diff --git a/app/blueprints/api/endpoints.py b/app/blueprints/api/endpoints.py index b7cfe761..c810d994 100644 --- a/app/blueprints/api/endpoints.py +++ b/app/blueprints/api/endpoints.py @@ -572,7 +572,7 @@ def all_package_stats(): @bp.route("/api/scores/") @cors_allowed -@cached(300) +@cached(900) def package_scores(): qb = QueryBuilder(request.args) query = qb.build_package_query() diff --git a/app/flatpages/help/api.md b/app/flatpages/help/api.md index 62fb5a27..8d816eeb 100644 --- a/app/flatpages/help/api.md +++ b/app/flatpages/help/api.md @@ -522,6 +522,10 @@ Supported query parameters: * `score`: total package score. * `score_reviews`: score from reviews. * `score_downloads`: score from downloads. + * `reviews`: a dictionary of + * `positive`: int, number of positive reviews. + * `neutral`: int, number of neutral reviews. + * `negative`: int, number of negative reviews. * GET `/api/homepage/` ([View](/api/homepage/)) - get contents of homepage. * `count`: number of packages * `downloads`: get number of downloads diff --git a/app/models/packages.py b/app/models/packages.py index add14665..8dbb8b0d 100644 --- a/app/models/packages.py +++ b/app/models/packages.py @@ -759,13 +759,19 @@ class Package(db.Model): return states def as_score_dict(self): + reviews = self.get_review_summary() return { "author": self.author.username, "name": self.name, "score": self.score, "score_downloads": self.score_downloads, "score_reviews": self.score - self.score_downloads, - "downloads": self.downloads + "downloads": self.downloads, + "reviews": { + "positive": reviews[0], + "neutral": reviews[1], + "negative": reviews[2], + }, } def recalculate_score(self):