Enable automatic browsing upvotes

This commit is contained in:
jjbrunton committed 2026-08-11 21:52:54 +01:00
1 parent 27012399ec
commit 7bf1aa9d24
26 files changed
+339 -57

No files matched your search

+20 -5
View File
@@ -15,6 +15,7 @@ export interface AccountBrowsingSettingsRecord {
minimumGapMs: number;
jitterMs: number;
allowNsfw: boolean;
autoVoteEnabled: boolean;
nextDueAt: number | null;
updatedAt: number;
}
@@ -29,6 +30,7 @@ export interface AccountBrowsingSettingsPatch {
minimumGapMs?: number;
jitterMs?: number;
allowNsfw?: boolean;
autoVoteEnabled?: boolean;
}
export interface BrowsingDecisionRecord {
@@ -44,6 +46,7 @@ export interface BrowsingDecisionRecord {
discoveredAt: number;
decidedAt: number;
scheduledSessionId: string;
voteSubmitted: boolean;
}
export interface BrowsingDecisionCounts {
@@ -74,6 +77,7 @@ export class AccountBrowsingSimulationRepository {
minimumGapMs: 45 * 60_000,
jitterMs: 15 * 60_000,
allowNsfw: false,
autoVoteEnabled: false,
nextDueAt: null,
updatedAt: now,
};
@@ -95,9 +99,9 @@ export class AccountBrowsingSimulationRepository {
this.db.prepare(`
INSERT INTO account_browsing_settings (
account_id, enabled, daily_target_min, daily_target_max, post_weight,
comment_weight, quiet_hours_json, minimum_gap_ms, jitter_ms, allow_nsfw,
comment_weight, quiet_hours_json, minimum_gap_ms, jitter_ms, allow_nsfw, auto_vote_enabled,
next_due_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(account_id) DO UPDATE SET
enabled = excluded.enabled,
daily_target_min = excluded.daily_target_min,
@@ -108,11 +112,12 @@ export class AccountBrowsingSimulationRepository {
minimum_gap_ms = excluded.minimum_gap_ms,
jitter_ms = excluded.jitter_ms,
allow_nsfw = excluded.allow_nsfw,
auto_vote_enabled = excluded.auto_vote_enabled,
updated_at = excluded.updated_at
`).run(
accountId, merged.enabled ? 1 : 0, merged.dailyTargetMin, merged.dailyTargetMax,
merged.postWeight, merged.commentWeight, JSON.stringify(merged.quietHours),
merged.minimumGapMs, merged.jitterMs, merged.allowNsfw ? 1 : 0,
merged.minimumGapMs, merged.jitterMs, merged.allowNsfw ? 1 : 0, merged.autoVoteEnabled ? 1 : 0,
merged.nextDueAt, now,
);
return this.getSettings(accountId, now);
@@ -131,12 +136,13 @@ export class AccountBrowsingSimulationRepository {
return this.db.prepare(`
INSERT OR IGNORE INTO account_browsing_decisions (
account_id, thing_fullname, thing_kind, post_id, subreddit, author,
permalink, decision, reason, discovered_at, decided_at, scheduled_session_id
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
permalink, decision, reason, discovered_at, decided_at, scheduled_session_id, vote_submitted
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`).run(
decision.accountId, decision.thingFullname, decision.thingKind, decision.postId,
decision.subreddit, decision.author, decision.permalink, decision.decision,
decision.reason, decision.discoveredAt, decision.decidedAt, decision.scheduledSessionId,
decision.voteSubmitted ? 1 : 0,
).changes === 1;
}
@@ -146,6 +152,13 @@ export class AccountBrowsingSimulationRepository {
}
}
markVoteSubmitted(accountId: string, thingFullname: string): boolean {
return this.db.prepare(`
UPDATE account_browsing_decisions SET vote_submitted = 1
WHERE account_id = ? AND thing_fullname = ? AND vote_submitted = 0
`).run(accountId, thingFullname).changes === 1;
}
hasAccountDecision(accountId: string, thingFullname: string): boolean {
return this.db.prepare(`
SELECT 1 FROM account_browsing_decisions WHERE account_id = ? AND thing_fullname = ?
@@ -271,6 +284,7 @@ function mapSettings(row: Record<string, unknown>): AccountBrowsingSettingsRecor
minimumGapMs: row.minimum_gap_ms as number,
jitterMs: row.jitter_ms as number,
allowNsfw: row.allow_nsfw === 1,
autoVoteEnabled: row.auto_vote_enabled === 1,
nextDueAt: (row.next_due_at as number | null) ?? null,
updatedAt: row.updated_at as number,
};
@@ -290,5 +304,6 @@ function mapDecision(row: Record<string, unknown>): BrowsingDecisionRecord {
discoveredAt: row.discovered_at as number,
decidedAt: row.decided_at as number,
scheduledSessionId: row.scheduled_session_id as string,
voteSubmitted: row.vote_submitted === 1,
};
}