Skip to content

Commit

Permalink
No longer attempting to cache for filter criteria that retrieve 0 rev…
Browse files Browse the repository at this point in the history
…isions
  • Loading branch information
levon003 committed Apr 21, 2022
1 parent 55b192d commit 5f6d6db
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion audit_web_client/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ rsync ${CHMOD} replica.my.cnf ${REMOTE}
rsync ${CHMOD} flask/app.py ${REMOTE}
rsync ${CHMOD} flask/requirements.txt ${REMOTE}
rsync ${CHMOD} flask/api/*.py ${REMOTE}/api
rsync -v -r ${CHMOD} build/ ${REMOTE}/api/www
rsync --delete -v -r ${CHMOD} build/ ${REMOTE}/api/www
echo "Finished syncing."

#scp flask/app.py ${REMOTE}
Expand Down
31 changes: 20 additions & 11 deletions audit_web_client/flask/api/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,20 @@ def get_sample_revisions():
for row in session.execute(s):
revision_list.append(row._asdict())
logger.info(f"Retrieved {len(revision_list)} revisions from revision table.")
rct = db.get_rev_cache_table()
rev_ids_to_cache = [rev['rev_id'] for rev in revision_list]
filter_hash = get_filter_hash(filters)
logger.info(f"Caching {len(rev_ids_to_cache)} revisions under filter hash '{filter_hash}'.")
rev_cache_list = []
for rev_id in rev_ids_to_cache:
rev_cache_list.append({
'rev_id': rev_id,
'filter_hash': filter_hash,
})
session.execute(rct.insert(), rev_cache_list)
if len(revision_list) > 0:
rct = db.get_rev_cache_table()
rev_ids_to_cache = [rev['rev_id'] for rev in revision_list]
filter_hash = get_filter_hash(filters)
logger.info(f"Caching {len(rev_ids_to_cache)} revisions under filter hash '{filter_hash}'.")
rev_cache_list = []
for rev_id in rev_ids_to_cache:
rev_cache_list.append({
'rev_id': rev_id,
'filter_hash': filter_hash,
})
session.execute(rct.insert(), rev_cache_list)
else:
rev_ids_to_cache = []
rev_ids = rev_ids_to_cache
else:
# remove any duplicates in cached_rev_ids
Expand All @@ -412,6 +415,12 @@ def get_sample_revisions():
rev_ids.append(rev_id)
else:
rev_ids = cached_rev_ids

if len(rev_ids) == 0:
counts = get_counts(filters, 0)
logger.info(f"Computed zero counts: {counts}")
return {'revisions': [], 'counts': counts}

logger.info(f"Retrieving full data for {len(rev_ids)} rev_ids.")

# query the revision table for the specific rev_ids we need
Expand Down

0 comments on commit 5f6d6db

Please sign in to comment.