feat: 同IP默认账号配额改为 primaryCount × 2
- 动态计算该类型默认账号数量 primaryCount - 前 primaryCount × 2 次在同IP的两个默认账号间轮询 - 超限后再去其他非默认账号 - 无默认账号时 threshold=0, 直接走轮询
This commit is contained in:
@@ -456,8 +456,15 @@ export async function getAndValidateCredential(cloudType: string, ipAddress?: st
|
||||
|
||||
const ipTodayCount = ipCountRow?.total || 0;
|
||||
|
||||
if (ipTodayCount < 3) {
|
||||
// First 2 saves — use a primary account (is_primary=1), fallback to any healthy
|
||||
// How many primary accounts does this cloud type have?
|
||||
const primaryCountRow = db.prepare(
|
||||
`SELECT COUNT(*) as c FROM cloud_configs WHERE cloud_type = ? AND is_primary = 1 AND is_active = 1`
|
||||
).get(cloudType) as { c: number };
|
||||
const primaryCount = primaryCountRow?.c || 0;
|
||||
const primaryThreshold = primaryCount * 2; // Each primary account gets 2 uses per IP
|
||||
|
||||
if (ipTodayCount < primaryThreshold) {
|
||||
// First N saves (primaryCount × 2) — use primary accounts (is_primary=1), fallback to any healthy
|
||||
config = db.prepare(
|
||||
`SELECT * FROM cloud_configs
|
||||
WHERE cloud_type = ? AND is_active = 1
|
||||
@@ -466,7 +473,7 @@ export async function getAndValidateCredential(cloudType: string, ipAddress?: st
|
||||
LIMIT 1`
|
||||
).get(cloudType) as CloudConfig | undefined;
|
||||
} else {
|
||||
// 3rd+ save — exclude accounts this IP has already used today,
|
||||
// After primary threshold — exclude accounts this IP has already used today,
|
||||
// fall back to other available accounts round-robin
|
||||
const usedConfigIds = db.prepare(
|
||||
`SELECT DISTINCT config_id FROM ip_daily_save_counts
|
||||
|
||||
Reference in New Issue
Block a user