Skip to content

Commit

Permalink
Org: Avoids expensive query when no filters have been defined
Browse files Browse the repository at this point in the history
TYPE: Bugfix
  • Loading branch information
Daverball committed Sep 11, 2024
1 parent 541b6ae commit 5cb2d88
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/onegov/org/views/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ def keyword_count(
)
fields = {f.id: f for f in self.directory.fields if f.id in keywords}
counts: dict[str, dict[str, int]] = {}

# NOTE: The counting can get incredibly expensive with many entries
# so we should skip it when we know we can skip it
if not fields:
return counts

# FIXME: This is incredibly slow. We need to think of a better way.
for model in request.exclude_invisible(self.without_keywords().query()):
for entry in model.keywords:
field_id, value = entry.split(':', 1)
Expand Down
7 changes: 7 additions & 0 deletions src/onegov/org/views/occurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ def keyword_count(
}

counts: dict[str, dict[str, int]] = {}

# NOTE: The counting can get incredibly expensive with many entries
# so we should skip it when we know we can skip it
if not fields:
return counts

# FIXME: This is incredibly slow. We need to think of a better way.
for model in self.without_keywords_and_tags().query():
if not request.is_visible(model):
continue
Expand Down

0 comments on commit 5cb2d88

Please sign in to comment.