0005-utils-cache-get_warehouses-result-based-on-schema-fi.patch
bijoe/utils.py | ||
---|---|---|
21 | 21 |
from django.conf import settings |
22 | 22 |
from django.db import connection |
23 | 23 |
from django.utils.translation import ugettext as _ |
24 |
try: |
|
25 |
from functools import lru_cache |
|
26 |
except ImportError: |
|
27 |
from django.utils.lru_cache import lru_cache |
|
28 | ||
24 | 29 | |
25 | 30 |
from .schemas import Warehouse |
26 | 31 | |
27 | 32 | |
28 |
def get_warehouses(): |
|
29 |
warehouses = [] |
|
33 |
def get_warehouses_paths(): |
|
30 | 34 |
for pattern in settings.BIJOE_SCHEMAS: |
31 | 35 |
for path in glob.glob(pattern): |
32 |
warehouses.append(Warehouse.from_json(json.load(open(path))))
|
|
36 |
yield path
|
|
33 | 37 |
if hasattr(connection, 'tenant'): |
34 | 38 |
pattern = os.path.join(connection.tenant.get_directory(), 'schemas', '*.model') |
35 | 39 |
for path in glob.glob(pattern): |
36 |
warehouses.append(Warehouse.from_json(json.load(open(path)))) |
|
40 |
yield path |
|
41 | ||
42 | ||
43 |
@lru_cache() |
|
44 |
def get_warehouses_by_paths(paths): |
|
45 |
warehouses = [] |
|
46 |
for path in paths: |
|
47 |
d = json.load(open(path)) |
|
48 |
warehouses.append(Warehouse.from_json(d)) |
|
37 | 49 |
return warehouses |
38 | 50 | |
39 | 51 | |
52 |
def get_warehouses(): |
|
53 |
paths = frozenset(get_warehouses_paths()) |
|
54 |
return get_warehouses_by_paths(paths) |
|
55 | ||
56 | ||
40 | 57 |
def human_join(l): |
41 | 58 |
if not l: |
42 | 59 |
return '' |
43 |
- |