Configure browsing session pacing and size
This commit is contained in:
1 parent
1fd154e1eb
commit
e890f74478
14 files changed
+201
-56
No files matched your search
@@ -15,6 +15,7 @@ export interface AccountBrowsingSettingsRecord {
|
||||
quietHours: GrowthQuietHours;
|
||||
minimumGapMs: number;
|
||||
jitterMs: number;
|
||||
selectionsPerSession: number;
|
||||
allowNsfw: boolean;
|
||||
autoVoteEnabled: boolean;
|
||||
nextDueAt: number | null;
|
||||
@@ -30,6 +31,7 @@ export interface AccountBrowsingSettingsPatch {
|
||||
quietHours?: GrowthQuietHours;
|
||||
minimumGapMs?: number;
|
||||
jitterMs?: number;
|
||||
selectionsPerSession?: number;
|
||||
allowNsfw?: boolean;
|
||||
autoVoteEnabled?: boolean;
|
||||
}
|
||||
@@ -78,6 +80,7 @@ export class AccountBrowsingSimulationRepository {
|
||||
quietHours: { ...DEFAULT_QUIET_HOURS },
|
||||
minimumGapMs: 45 * 60_000,
|
||||
jitterMs: 15 * 60_000,
|
||||
selectionsPerSession: 1,
|
||||
allowNsfw: false,
|
||||
autoVoteEnabled: false,
|
||||
nextDueAt: null,
|
||||
@@ -101,9 +104,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, auto_vote_enabled,
|
||||
comment_weight, quiet_hours_json, minimum_gap_ms, jitter_ms, selections_per_session, 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,
|
||||
@@ -113,13 +116,15 @@ export class AccountBrowsingSimulationRepository {
|
||||
quiet_hours_json = excluded.quiet_hours_json,
|
||||
minimum_gap_ms = excluded.minimum_gap_ms,
|
||||
jitter_ms = excluded.jitter_ms,
|
||||
selections_per_session = excluded.selections_per_session,
|
||||
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.autoVoteEnabled ? 1 : 0,
|
||||
merged.minimumGapMs, merged.jitterMs, merged.selectionsPerSession,
|
||||
merged.allowNsfw ? 1 : 0, merged.autoVoteEnabled ? 1 : 0,
|
||||
merged.nextDueAt, now,
|
||||
);
|
||||
return this.getSettings(accountId, now);
|
||||
@@ -274,6 +279,10 @@ function validateSettings(settings: AccountBrowsingSettingsRecord): void {
|
||||
if (!Number.isInteger(settings.jitterMs) || settings.jitterMs < 0) {
|
||||
throw new Error('Browsing jitter must be a non-negative whole number');
|
||||
}
|
||||
if (!Number.isInteger(settings.selectionsPerSession)
|
||||
|| settings.selectionsPerSession < 1 || settings.selectionsPerSession > 12) {
|
||||
throw new Error('Browsing selections per session must be a whole number between 1 and 12');
|
||||
}
|
||||
const { startHour, endHour } = settings.quietHours;
|
||||
if (!Number.isInteger(startHour) || startHour < 0 || startHour > 23
|
||||
|| !Number.isInteger(endHour) || endHour < 0 || endHour > 23) {
|
||||
@@ -292,6 +301,7 @@ function mapSettings(row: Record<string, unknown>): AccountBrowsingSettingsRecor
|
||||
quietHours: JSON.parse(row.quiet_hours_json as string) as GrowthQuietHours,
|
||||
minimumGapMs: row.minimum_gap_ms as number,
|
||||
jitterMs: row.jitter_ms as number,
|
||||
selectionsPerSession: row.selections_per_session as number,
|
||||
allowNsfw: row.allow_nsfw === 1,
|
||||
autoVoteEnabled: row.auto_vote_enabled === 1,
|
||||
nextDueAt: (row.next_due_at as number | null) ?? null,
|
||||
|
||||
@@ -616,6 +616,9 @@ export function runMigrations(db: Database.Database): void {
|
||||
addColumnIfNotExists(db, 'account_browsing_decisions', 'vote_status', "TEXT NOT NULL DEFAULT 'simulated' CHECK(vote_status IN ('simulated', 'pending', 'submitted', 'failed'))");
|
||||
db.exec("UPDATE account_browsing_decisions SET vote_status = 'submitted' WHERE vote_submitted = 1");
|
||||
},
|
||||
() => {
|
||||
addColumnIfNotExists(db, 'account_browsing_settings', 'selections_per_session', 'INTEGER NOT NULL DEFAULT 1 CHECK(selections_per_session BETWEEN 1 AND 12)');
|
||||
},
|
||||
];
|
||||
|
||||
let currentVersion = db.pragma('user_version', { simple: true }) as number;
|
||||
|
||||
Reference in new issue
Block a user