Skip to content

Commit

Permalink
add invalidate_query_cache command that invalidates all query caches
Browse files Browse the repository at this point in the history
  • Loading branch information
nattvara committed Mar 8, 2023
1 parent 94ca7f3 commit 4383d99
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions db/cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


from db.crud import get_all_lectures


def invalidate_all_query_caches():
print('invalidating all query caches')

lectures = get_all_lectures()
for lecture in lectures:
print(f'invalidating cache for lecture {lecture}: ', end='')
queries = lecture.queries()
print(f'found {len(queries)} queries', end='')
for query in queries:
query.cache_is_valid = False
query.save()
print(' done.')
5 changes: 5 additions & 0 deletions db/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ def create_query(lecture, query_string: str):
return query


def find_all_queries_for_lecture(lecture):
from db.models.query import Query
return Query.select().where(Query.lecture_id == lecture.id)


# Message
def save_message_for_analysis(analysis, title: str, body: Union[str, None] = None):
from db.models.message import Message
Expand Down
5 changes: 5 additions & 0 deletions db/models/lecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from db.crud import (
find_all_courses_relations_for_lecture_id,
find_all_courses_for_lecture_id,
find_all_queries_for_lecture,
)


Expand Down Expand Up @@ -150,6 +151,10 @@ def get_last_analysis(self):
.order_by(Analysis.modified_at.desc())
.first())

def queries(self):
queries = find_all_queries_for_lecture(self)
return queries

def courses(self):
out = []

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'create_migration = db.migrations:create_migration',
'migrate_up = db.migrations:run_migrations',
'migrate_down = db.migrations:rollback',
'invalidate_query_cache = db.cmd:invalidate_all_query_caches',
'analysis_queues_restart = jobs:analysis_queues_restart',
'dispatch_fetch_metadata_for_all_lectures = jobs.cmd:fetch_metadata_for_all_lectures',
'dispatch_capture_preview_for_all_lectures = jobs.cmd:capture_preview_for_all_lectures',
Expand Down

0 comments on commit 4383d99

Please sign in to comment.