Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat(web): count update check requests (#4362)

Elijah Potterab67c0700e04
diff --git a/packages/web/drizzle/0004_charming_redwing.sql b/packages/web/drizzle/0004_charming_redwing.sql
new file mode 100644
index 000000000..cebd1f05c
--- /dev/null
+++ b/packages/web/drizzle/0004_charming_redwing.sql
@@ -0,0 +1,5 @@
+CREATE TABLE `update_check_counts` (
+ `date` date NOT NULL,
+ `count` int NOT NULL,
+ CONSTRAINT `update_check_counts_date` PRIMARY KEY(`date`)
+);
diff --git a/packages/web/drizzle/meta/0004_snapshot.json b/packages/web/drizzle/meta/0004_snapshot.json
new file mode 100644
index 000000000..bb7f9928b
--- /dev/null
+++ b/packages/web/drizzle/meta/0004_snapshot.json
@@ -0,0 +1,193 @@
+{
+ "version": "5",
+ "dialect": "mysql",
+ "id": "7dd6b319-eb00-46a8-bf7b-f7569ccf2089",
+ "prevId": "9358d1e0-0c39-4be8-bf6d-767b7073ac02",
+ "tables": {
+ "domain_review": {
+ "name": "domain_review",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "works": {
+ "name": "works",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "feedback": {
+ "name": "feedback",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "domain": {
+ "name": "domain",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "timestamp": {
+ "name": "timestamp",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "domain_review_id": {
+ "name": "domain_review_id",
+ "columns": ["id"]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "problematic_lint": {
+ "name": "problematic_lint",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "is_false_positive": {
+ "name": "is_false_positive",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "example": {
+ "name": "example",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "feedback": {
+ "name": "feedback",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "rule_id": {
+ "name": "rule_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "timestamp": {
+ "name": "timestamp",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "problematic_lint_id": {
+ "name": "problematic_lint_id",
+ "columns": ["id"]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "uninstall_feedback": {
+ "name": "uninstall_feedback",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "feedback": {
+ "name": "feedback",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "timestamp": {
+ "name": "timestamp",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "uninstall_feedback_id": {
+ "name": "uninstall_feedback_id",
+ "columns": ["id"]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "update_check_counts": {
+ "name": "update_check_counts",
+ "columns": {
+ "date": {
+ "name": "date",
+ "type": "date",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "count": {
+ "name": "count",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "update_check_counts_date": {
+ "name": "update_check_counts_date",
+ "columns": ["date"]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ }
+ },
+ "views": {},
+ "_meta": {
+ "schemas": {},
+ "tables": {},
+ "columns": {}
+ },
+ "internal": {
+ "tables": {},
+ "indexes": {}
+ }
+}
diff --git a/packages/web/drizzle/meta/_journal.json b/packages/web/drizzle/meta/_journal.json
index 3f727d97c..99cbd7808 100644
--- a/packages/web/drizzle/meta/_journal.json
+++ b/packages/web/drizzle/meta/_journal.json
@@ -29,6 +29,13 @@
"when": 1784571049353,
"tag": "0003_fearless_thanos",
"breakpoints": true
+ },
+ {
+ "idx": 4,
+ "version": "5",
+ "when": 1789072725878,
+ "tag": "0004_charming_redwing",
+ "breakpoints": true
}
]
}
diff --git a/packages/web/src/lib/db/models/UpdateCheckCounts.ts b/packages/web/src/lib/db/models/UpdateCheckCounts.ts
new file mode 100644
index 000000000..12ea3df6d
--- /dev/null
+++ b/packages/web/src/lib/db/models/UpdateCheckCounts.ts
@@ -0,0 +1,42 @@
+import { eq, sql } from 'drizzle-orm';
+import { createSelectSchema } from 'drizzle-zod';
+import { db } from '..';
+import { updateCheckCountTable } from '../schema';
+
+export type UpdateCheckCountRow = typeof updateCheckCountTable.$inferSelect;
+const UpdateCheckCountRowParser = createSelectSchema(updateCheckCountTable);
+
+export default class DomainReviews {
+ public static async incrementForToday() {
+ DomainReviews.incrementForDate(new Date());
+ }
+
+ public static async incrementForDate(date: Date) {
+ await db
+ .insert(updateCheckCountTable)
+ .values({
+ date: date,
+ count: 1,
+ })
+ .onDuplicateKeyUpdate({
+ set: {
+ count: sql`${updateCheckCountTable.count} + 1`,
+ },
+ });
+ }
+
+ public static async getCountForDate(date: Date): Promise<number> {
+ const found = await db
+ .select()
+ .from(updateCheckCountTable)
+ .where(eq(updateCheckCountTable.date, date));
+
+ const first = found[0];
+
+ if (first == null) {
+ return 0;
+ } else {
+ return first.count;
+ }
+ }
+}
diff --git a/packages/web/src/lib/db/schema.ts b/packages/web/src/lib/db/schema.ts
index ba71e8804..56cd8c02a 100644
--- a/packages/web/src/lib/db/schema.ts
+++ b/packages/web/src/lib/db/schema.ts
@@ -1,4 +1,4 @@
-import { boolean, int, mysqlTable, text, timestamp } from 'drizzle-orm/mysql-core';
+import { boolean, date, int, mysqlTable, text, timestamp } from 'drizzle-orm/mysql-core';
export const uninstallFeedbackTable = mysqlTable('uninstall_feedback', {
id: int().autoincrement().primaryKey(),
@@ -23,3 +23,8 @@ export const domainReviewTable = mysqlTable('domain_review', {
domain: text().notNull(),
timestamp: timestamp().notNull().defaultNow(),
});
+
+export const updateCheckCountTable = mysqlTable('update_check_counts', {
+ date: date().primaryKey(),
+ count: int().notNull(),
+});
diff --git a/packages/web/src/routes/download-harper-desktop/[target]/[arch]/[current_version]/+server.ts b/packages/web/src/routes/download-harper-desktop/[target]/[arch]/[current_version]/+server.ts
index 24d13651c..0035fb560 100644
--- a/packages/web/src/routes/download-harper-desktop/[target]/[arch]/[current_version]/+server.ts
+++ b/packages/web/src/routes/download-harper-desktop/[target]/[arch]/[current_version]/+server.ts
@@ -1,4 +1,5 @@
import { json, type RequestEvent } from '@sveltejs/kit';
+import UpdateCheckCounts from '$lib/db/models/UpdateCheckCounts';
import { type GitHubRelease, type GitHubReleaseAsset, GithubClient } from '$lib/GitHubClient';
const REPO_OWNER = 'automattic';
@@ -114,6 +115,8 @@ export const GET = async ({ params }: RequestEvent) => {
return noUpdate();
}
+ UpdateCheckCounts.incrementForToday();
+
if (!supportsTarget(target, arch)) {
console.log(`No Harper Desktop update available for unsupported platform ${target}/${arch}.`);
return noUpdate();