Skip to content

Commit

Permalink
Merge pull request #799 from LibraryOfCongress/optimize-contributor-c…
Browse files Browse the repository at this point in the history
…ount-query

Optimize the query used to count unique contributors
  • Loading branch information
acdha committed Jan 31, 2019
2 parents ed3df1e + b570cc8 commit c2a10f9
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions concordia/views.py
Expand Up @@ -380,13 +380,9 @@ def calculate_asset_stats(asset_qs, ctx):
asset_count = asset_qs.count()

trans_qs = Transcription.objects.filter(asset__in=asset_qs)
ctx["contributor_count"] = (
User.objects.filter(
Q(transcription__in=trans_qs) | Q(transcription_reviewers__in=trans_qs)
)
.distinct()
.count()
)
ctx["contributor_count"] = User.objects.filter(
Q(pk__in=trans_qs.values("user_id")) | Q(pk__in=trans_qs.values("reviewed_by"))
).count()

asset_state_qs = asset_qs.values_list("transcription_status")
asset_state_qs = asset_state_qs.annotate(Count("transcription_status")).order_by()
Expand Down

0 comments on commit c2a10f9

Please sign in to comment.