Junior — Senior
Analysis and fixing bottlenecks in database queries
livecode
Task condition
It is necessary to identify and describe in detail the problems in the code that reduce the performance of database queries. Consider a function that retrieves all authors and their related articles.
def fetch_authors():
authors_qs = Author.objects.prefetch_related('articles').all()
for author in authors_qs:
print(f'{author.get_full_name()}:')
for article in author.articles.filter(deleted=False):
print(f' {article.name}')