Track pending browsing upvotes
This commit is contained in:
1 parent
540590f43e
commit
1fd154e1eb
13 files changed
+73
-27
No files matched your search
@@ -3,6 +3,7 @@ import type { GrowthQuietHours } from './growth-repository.js';
|
||||
|
||||
export type BrowsingThingKind = 'post' | 'comment';
|
||||
export type BrowsingDecisionKind = 'simulated-upvote' | 'skipped' | 'rejected';
|
||||
export type BrowsingVoteStatus = 'simulated' | 'pending' | 'submitted' | 'failed';
|
||||
|
||||
export interface AccountBrowsingSettingsRecord {
|
||||
accountId: string;
|
||||
@@ -47,6 +48,7 @@ export interface BrowsingDecisionRecord {
|
||||
decidedAt: number;
|
||||
scheduledSessionId: string;
|
||||
voteSubmitted: boolean;
|
||||
voteStatus: BrowsingVoteStatus;
|
||||
}
|
||||
|
||||
export interface BrowsingDecisionCounts {
|
||||
@@ -136,13 +138,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, vote_submitted
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
permalink, decision, reason, discovered_at, decided_at, scheduled_session_id, vote_submitted, vote_status
|
||||
) 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,
|
||||
decision.voteSubmitted ? 1 : 0, decision.voteStatus,
|
||||
).changes === 1;
|
||||
}
|
||||
|
||||
@@ -154,11 +156,18 @@ 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
|
||||
UPDATE account_browsing_decisions SET vote_submitted = 1, vote_status = 'submitted', reason = 'Reddit upvote submitted'
|
||||
WHERE account_id = ? AND thing_fullname = ? AND vote_status = 'pending'
|
||||
`).run(accountId, thingFullname).changes === 1;
|
||||
}
|
||||
|
||||
markVoteFailed(accountId: string, thingFullname: string, reason: string): boolean {
|
||||
return this.db.prepare(`
|
||||
UPDATE account_browsing_decisions SET vote_status = 'failed', reason = ?
|
||||
WHERE account_id = ? AND thing_fullname = ? AND vote_status = 'pending'
|
||||
`).run(reason, 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 = ?
|
||||
@@ -305,5 +314,6 @@ function mapDecision(row: Record<string, unknown>): BrowsingDecisionRecord {
|
||||
decidedAt: row.decided_at as number,
|
||||
scheduledSessionId: row.scheduled_session_id as string,
|
||||
voteSubmitted: row.vote_submitted === 1,
|
||||
voteStatus: row.vote_status as BrowsingVoteStatus,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user