0002-utils-cache-warehouses-27412.patch
bijoe/utils.py | ||
---|---|---|
19 | 19 |
import json |
20 | 20 | |
21 | 21 |
from django.conf import settings |
22 |
from django.core.cache import cache |
|
22 | 23 |
from django.db import connection |
23 | 24 |
from django.utils.translation import ugettext as _ |
24 | 25 | |
... | ... | |
26 | 27 | |
27 | 28 | |
28 | 29 |
def get_warehouses(): |
30 |
if cache.get('warehouses_cache'): |
|
31 |
return cache.get('warehouses_cache') |
|
29 | 32 |
warehouses = [] |
30 | 33 |
for pattern in settings.BIJOE_SCHEMAS: |
31 | 34 |
for path in glob.glob(pattern): |
... | ... | |
34 | 37 |
pattern = os.path.join(connection.tenant.get_directory(), 'schemas', '*.model') |
35 | 38 |
for path in glob.glob(pattern): |
36 | 39 |
warehouses.append(Warehouse.from_json(json.load(open(path)))) |
40 |
cache.set('warehouses_cache', warehouses, 30) |
|
37 | 41 |
return warehouses |
38 | 42 | |
39 | 43 |
tests/conftest.py | ||
---|---|---|
15 | 15 | |
16 | 16 |
from django.db import connection |
17 | 17 |
from django.contrib.auth.models import User |
18 |
from django.core.cache import cache |
|
18 | 19 |
from django.core.management import call_command |
19 | 20 | |
20 | 21 | |
... | ... | |
52 | 53 |
def load_schema_db(schema): |
53 | 54 |
import random |
54 | 55 | |
56 |
cache.delete('warehouses_cache') |
|
55 | 57 |
database_name = 'db%s' % random.getrandbits(20) |
56 | 58 |
tmpdir = tempfile.mkdtemp() |
57 | 59 |
bijoe_schema_dir = os.path.join(tmpdir, 'schemas') |
58 |
- |