[aur-dev] [PATCH 2/4] Add a field for package base popularity

Lukas Fleischer lfleischer at archlinux.org
Thu Jun 11 17:06:52 UTC 2015


Create a new field Popularity in the PackageBases table. The field is
updated by the popupdate script and reflects the popularity of a
package. Popularity is the sum of all votes with each vote being
weighted with a factor of 0.98 per day since its creation.

Signed-off-by: Lukas Fleischer <lfleischer at archlinux.org>
---
 schema/aur-schema.sql | 1 +
 scripts/popupdate.py  | 5 +++++
 upgrading/4.0.0.txt   | 9 ++++++++-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/schema/aur-schema.sql b/schema/aur-schema.sql
index 5641d0d..1935cf0 100644
--- a/schema/aur-schema.sql
+++ b/schema/aur-schema.sql
@@ -102,6 +102,7 @@ CREATE TABLE PackageBases (
 	Name VARCHAR(255) NOT NULL,
 	CategoryID TINYINT UNSIGNED NOT NULL DEFAULT 1,
 	NumVotes INTEGER UNSIGNED NOT NULL DEFAULT 0,
+	Popularity DECIMAL(6,2) UNSIGNED NOT NULL DEFAULT 0,
 	OutOfDateTS BIGINT UNSIGNED NULL DEFAULT NULL,
 	SubmittedTS BIGINT UNSIGNED NOT NULL,
 	ModifiedTS BIGINT UNSIGNED NOT NULL,
diff --git a/scripts/popupdate.py b/scripts/popupdate.py
index 489cd41..f4c99ca 100755
--- a/scripts/popupdate.py
+++ b/scripts/popupdate.py
@@ -23,5 +23,10 @@ cur = db.cursor()
 cur.execute("UPDATE PackageBases SET NumVotes = (SELECT COUNT(*) FROM " +
             "PackageVotes WHERE PackageVotes.PackageBaseID = PackageBases.ID)")
 
+cur.execute("UPDATE PackageBases SET Popularity = (" +
+            "SELECT SUM(POWER(0.98, (UNIX_TIMESTAMP() - VoteTS) / 86400)) " +
+            "FROM PackageVotes WHERE PackageVotes.PackageBaseID = " +
+            "PackageBases.ID AND NOT VoteTS IS NULL)")
+
 db.commit()
 db.close()
diff --git a/upgrading/4.0.0.txt b/upgrading/4.0.0.txt
index ed39c9f..aa1e535 100644
--- a/upgrading/4.0.0.txt
+++ b/upgrading/4.0.0.txt
@@ -31,4 +31,11 @@ CREATE TABLE PackageComaintainers (
 ) ENGINE = InnoDB;
 ----
 
-5. (optional) Setup cgit to browse the Git repositories via HTTP.
+5. Add a field for the package base popularity to the PackageBases table:
+
+----
+ALTER TABLE PackageBases
+	ADD COLUMN Popularity DECIMAL(6,2) UNSIGNED NOT NULL DEFAULT 0;
+----
+
+6. (optional) Setup cgit to browse the Git repositories via HTTP.
-- 
2.4.2


More information about the aur-dev mailing list