fix(db): dedupe bulk-imported proxies by full credential tuple (#7594) (#7644)

This commit is contained in:
Ronaldo Davi
2026-07-18 15:14:53 -03:00
committed by GitHub
parent 16e481ba3e
commit 589dbde2e6
2 changed files with 119 additions and 5 deletions

View File

@@ -296,9 +296,14 @@ export async function createProxy(payload: ProxyPayload) {
}
/**
* Upsert a proxy by host+port.
* If a proxy with the same host and port already exists, update it.
* Otherwise, create a new one. Used by the bulk import feature.
* Upsert a proxy by its credential tuple (host+port+username+password).
* If a proxy with the same host, port, username AND password already exists,
* update it. Otherwise, create a new one. Used by the bulk import feature.
*
* #7594: host+port alone is NOT a stable identity. Rotating residential/gateway
* proxies route every credential through one shared host:port, so keying only on
* host+port collapsed distinct-credential imports onto the first existing row
* (the same entry got "updated" N times instead of N entries being created).
*/
export async function upsertProxy(payload: ProxyPayload): Promise<{
proxy: ProxyRegistryRecord | null;
@@ -307,10 +312,14 @@ export async function upsertProxy(payload: ProxyPayload): Promise<{
const db = getDbInstance();
const host = (payload.host || "").trim();
const port = Number(payload.port);
const username = (payload.username || "").trim();
const password = (payload.password || "").trim();
const existing = db
.prepare("SELECT id FROM proxy_registry WHERE host = ? AND port = ? LIMIT 1")
.get(host, port) as { id?: string } | undefined;
.prepare(
"SELECT id FROM proxy_registry WHERE host = ? AND port = ? AND username = ? AND password = ? LIMIT 1"
)
.get(host, port, username, password) as { id?: string } | undefined;
if (existing?.id) {
const updated = await updateProxy(existing.id, payload);