From 2617c53abfc3b1a1af10a88794e17bb88affd61d Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 9 Jul 2020 01:11:50 +0100 Subject: Add downloads column to Package Fixes #200 --- app/models.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'app/models.py') diff --git a/app/models.py b/app/models.py index 56adc8e..79b70cf 100644 --- a/app/models.py +++ b/app/models.py @@ -431,7 +431,8 @@ class Package(db.Model): approved = db.Column(db.Boolean, nullable=False, default=False) soft_deleted = db.Column(db.Boolean, nullable=False, default=False) - score = db.Column(db.Float, nullable=False, default=0) + score = db.Column(db.Float, nullable=False, default=0) + downloads = db.Column(db.Integer, nullable=False, default=0) review_thread_id = db.Column(db.Integer, db.ForeignKey("thread.id"), nullable=True, default=None) review_thread = db.relationship("Thread", foreign_keys=[review_thread_id]) @@ -658,12 +659,6 @@ class Package(db.Model): return None - def getDownloadCount(self): - counter = 0 - for release in self.releases: - counter += release.downloads - return counter - def checkPerm(self, user, perm): if not user.is_authenticated: return False @@ -709,8 +704,7 @@ class Package(db.Model): raise Exception("Permission {} is not related to packages".format(perm.name)) def setStartScore(self): - downloads = db.session.query(func.sum(PackageRelease.downloads)). \ - filter(PackageRelease.package_id == self.id).scalar() or 0 + downloads = self.downloads forum_score = 0 forum_bonus = 0 -- cgit v1.2.3