Skip to content

Commit

Permalink
Fix frontend linking and performance (#776)
Browse files Browse the repository at this point in the history
Fix #775
  • Loading branch information
another-rex committed Oct 13, 2022
1 parent efc3876 commit c8b56e1
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions gcp/appengine/frontend_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
_PAGE_SIZE = 16
_PAGE_LOOKAHEAD = 4
_REQUESTS_PER_MIN = 30
_MAX_LINKING_ALIASES = 8

if utils.is_prod():
redis_host = os.environ.get('REDISHOST', 'localhost')
Expand Down Expand Up @@ -196,25 +195,25 @@ def add_related_aliases(bug: osv.Bug, response):
"""Add links to other osv entries that's related through aliases"""
# Add links to other entries if they exist
aliases = {}
for alias in bug.aliases:
# only if there aren't too many, otherwise skip this
if len(bug.aliases) <= _MAX_LINKING_ALIASES:
result = bug.get_by_id(alias)
else:
result = False
aliases[alias] = {'exists': result, 'same_alias_entries': []}
if bug.aliases:
directly_refed = osv.Bug.query(osv.Bug.db_id.IN(bug.aliases))
is_directly_refed = {dr.db_id for dr in directly_refed}
for alias in bug.aliases:
aliases[alias] = {
'exists': alias in is_directly_refed,
'same_alias_entries': []
}

# Add links to other entries that have the same alias or references this
if bug.aliases:
query = osv.Bug.query(osv.Bug.aliases.IN(bug.aliases + [bug.id()]))
for other in query:
if other.id() == bug.id():
continue
for other_alias in other.aliases:
if other_alias in aliases:
aliases[other_alias]['same_alias_entries'].append(other.id())
if bug.id() in other.aliases:
aliases[other.id()] = {'exists': True, 'same_alias_entries': []}
query = osv.Bug.query(osv.Bug.aliases.IN(bug.aliases + [bug.id()]))
for other in query:
if other.id() == bug.id():
continue
for other_alias in other.aliases:
if other_alias in aliases:
aliases[other_alias]['same_alias_entries'].append(other.id())
if bug.id() in other.aliases:
aliases[other.id()] = {'exists': True, 'same_alias_entries': []}

# Remove self if it was added
aliases.pop(bug.id(), None)
Expand Down

0 comments on commit c8b56e1

Please sign in to comment.