Skip to content

Commit

Permalink
Types performance
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Oct 24, 2023
1 parent 085e796 commit 7dc471d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
9 changes: 0 additions & 9 deletions openatlas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,7 @@ def before_request() -> None:
g.cidoc_classes = CidocClass.get_all(session['language'])
g.properties = CidocProperty.get_all(session['language'])
g.classes = OpenatlasClass.get_all()

from time import perf_counter
start_time = perf_counter()

g.types = Type.get_all()

end_time = perf_counter()
elapsed_time = end_time - start_time
print(f"Elapsed time: {elapsed_time} seconds")

g.reference_systems = ReferenceSystem.get_all()
g.view_class_mapping = view_class_mapping
g.class_view_mapping = OpenatlasClass.get_class_view_mapping()
Expand Down
10 changes: 5 additions & 5 deletions openatlas/database/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Type:

@staticmethod
def get_types(class_: str, property_: str) -> list[dict[str, Any]]:
def get_types() -> list[dict[str, Any]]:
g.cursor.execute(
"""
SELECT
Expand Down Expand Up @@ -34,19 +34,19 @@ def get_types(class_: str, property_: str) -> list[dict[str, Any]]:
-- Get super
LEFT JOIN model.link l ON e.id = l.domain_id
AND l.property_code = %(property_code)s
AND l.property_code IN ('P127', 'P89')
LEFT JOIN model.entity es ON l.range_id = es.id
-- Get count
LEFT JOIN model.link l2 ON e.id = l2.range_id
AND l2.property_code IN ('P2', 'P89')
LEFT JOIN model.link l3 ON e.id = l3.type_id
WHERE e.openatlas_class_name = %(class)s
WHERE e.openatlas_class_name
IN ('administrative_unit', 'type', 'type_tools')
GROUP BY e.id, es.id
ORDER BY e.name;
""",
{'class': class_, 'property_code': property_})
""")
return [dict(row) for row in g.cursor.fetchall()]

@staticmethod
Expand Down
7 changes: 2 additions & 5 deletions openatlas/models/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,9 @@ def move_entities(self, new_type_id: int, checkbox_values: str) -> None:
Db.remove_entity_type(self.id, delete_ids)

@staticmethod
def get_all(with_count: bool = False) -> dict[int, Type]:
def get_all() -> dict[int, Type]:
types = {}
for row in \
Db.get_types('type', 'P127') + \
Db.get_types('type_tools', 'P127') + \
Db.get_types('administrative_unit', 'P89'):
for row in Db.get_types():
type_ = Type(row)
types[type_.id] = type_
type_.count = row['count'] or row['count_property']
Expand Down

0 comments on commit 7dc471d

Please sign in to comment.