Skip to content

Commit

Permalink
Merge pull request #822 from ImageMarkup/improve-counts-query
Browse files Browse the repository at this point in the history
Improve performance of review page counts query
  • Loading branch information
danlamanna authored Dec 15, 2023
2 parents 70e3218 + b4ad6ef commit c826886
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions isic/ingest/views/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@

from isic.core.permissions import needs_object_permission
from isic.ingest.models import Cohort
from isic.ingest.models.accession import AccessionStatus

from . import make_breadcrumbs

REVIEW_PER_PAGE = 500


def _cohort_review_progress(cohort: Cohort) -> dict:
num_reviewed = cohort.accessions.reviewed().count()
num_reviewable = cohort.accessions.reviewable().count()
ingested_and_publishable = Q(image__isnull=True, status=AccessionStatus.SUCCEEDED)
counts = cohort.accessions.aggregate(
reviewed=Count("id", filter=ingested_and_publishable & ~Q(review=None)),
reviewable=Count("id", filter=ingested_and_publishable),
)

return {
"num_reviewed": num_reviewed,
"num_reviewable": num_reviewable,
"percentage": 0 if num_reviewable == 0 else math.floor(num_reviewed / num_reviewable * 100),
"num_reviewed": counts["reviewed"],
"num_reviewable": counts["reviewable"],
"percentage": 0
if counts["reviewable"] == 0
else math.floor(counts["reviewed"] / counts["reviewable"] * 100),
}


Expand Down

0 comments on commit c826886

Please sign in to comment.