diff --git a/.commentlint/go-baseline.json b/.commentlint/go-baseline.json index c983604..c3a143c 100644 --- a/.commentlint/go-baseline.json +++ b/.commentlint/go-baseline.json @@ -23825,18846 +23825,6 @@ "kind": "local-variable", "name": "err" }, - { - "file": "internal/db/account_login_logs.go", - "line": 24, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_login_logs.go", - "line": 41, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_login_logs.go", - "line": 41, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/account_login_logs.go", - "line": 55, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/account_login_logs.go", - "line": 57, - "kind": "var", - "name": "log" - }, - { - "file": "internal/db/account_login_logs.go", - "line": 58, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tasks.go", - "line": 11, - "kind": "type", - "name": "AccountTaskSettings" - }, - { - "file": "internal/db/account_tasks.go", - "line": 22, - "kind": "type", - "name": "AccountTaskRun" - }, - { - "file": "internal/db/account_tasks.go", - "line": 38, - "kind": "type", - "name": "AccountTaskStore" - }, - { - "file": "internal/db/account_tasks.go", - "line": 43, - "kind": "function", - "name": "defaultAccountTaskSettings" - }, - { - "file": "internal/db/account_tasks.go", - "line": 47, - "kind": "function", - "name": "Get" - }, - { - "file": "internal/db/account_tasks.go", - "line": 48, - "kind": "local-variable", - "name": "result" - }, - { - "file": "internal/db/account_tasks.go", - "line": 49, - "kind": "var", - "name": "polishEnabled" - }, - { - "file": "internal/db/account_tasks.go", - "line": 49, - "kind": "var", - "name": "rateEnabled" - }, - { - "file": "internal/db/account_tasks.go", - "line": 50, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tasks.go", - "line": 62, - "kind": "function", - "name": "Upsert" - }, - { - "file": "internal/db/account_tasks.go", - "line": 70, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/db/account_tasks.go", - "line": 71, - "kind": "local-variable", - "name": "query" - }, - { - "file": "internal/db/account_tasks.go", - "line": 78, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tasks.go", - "line": 84, - "kind": "function", - "name": "Enabled" - }, - { - "file": "internal/db/account_tasks.go", - "line": 85, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tasks.go", - "line": 85, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/account_tasks.go", - "line": 93, - "kind": "var", - "name": "result" - }, - { - "file": "internal/db/account_tasks.go", - "line": 95, - "kind": "var", - "name": "row" - }, - { - "file": "internal/db/account_tasks.go", - "line": 96, - "kind": "var", - "name": "polish" - }, - { - "file": "internal/db/account_tasks.go", - "line": 96, - "kind": "var", - "name": "rate" - }, - { - "file": "internal/db/account_tasks.go", - "line": 97, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tasks.go", - "line": 108, - "kind": "function", - "name": "ClaimRun" - }, - { - "file": "internal/db/account_tasks.go", - "line": 115, - "kind": "function", - "name": "ClaimRunImmediately" - }, - { - "file": "internal/db/account_tasks.go", - "line": 119, - "kind": "function", - "name": "claimRun" - }, - { - "file": "internal/db/account_tasks.go", - "line": 120, - "kind": "local-variable", - "name": "retryCondition" - }, - { - "file": "internal/db/account_tasks.go", - "line": 121, - "kind": "local-variable", - "name": "args" - }, - { - "file": "internal/db/account_tasks.go", - "line": 126, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tasks.go", - "line": 126, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/account_tasks.go", - "line": 131, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/account_tasks.go", - "line": 134, - "kind": "local-variable", - "name": "query" - }, - { - "file": "internal/db/account_tasks.go", - "line": 141, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/account_tasks.go", - "line": 145, - "kind": "function", - "name": "FinishRun" - }, - { - "file": "internal/db/account_tasks.go", - "line": 146, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tasks.go", - "line": 151, - "kind": "function", - "name": "MarkRateScan" - }, - { - "file": "internal/db/account_tasks.go", - "line": 152, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tasks.go", - "line": 156, - "kind": "function", - "name": "MarkPolished" - }, - { - "file": "internal/db/account_tasks.go", - "line": 157, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tasks.go", - "line": 161, - "kind": "function", - "name": "RecentRuns" - }, - { - "file": "internal/db/account_tasks.go", - "line": 165, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tasks.go", - "line": 165, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/account_tasks.go", - "line": 171, - "kind": "var", - "name": "result" - }, - { - "file": "internal/db/account_tasks.go", - "line": 173, - "kind": "var", - "name": "row" - }, - { - "file": "internal/db/account_tasks.go", - "line": 174, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tasks.go", - "line": 184, - "kind": "function", - "name": "boolInt" - }, - { - "file": "internal/db/account_tokens.go", - "line": 30, - "kind": "var", - "name": "tk" - }, - { - "file": "internal/db/account_tokens.go", - "line": 32, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens.go", - "line": 59, - "kind": "function", - "name": "SaveBound" - }, - { - "file": "internal/db/account_tokens.go", - "line": 60, - "kind": "local-variable", - "name": "encryptedDeviceID" - }, - { - "file": "internal/db/account_tokens.go", - "line": 60, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens.go", - "line": 64, - "kind": "local-variable", - "name": "encryptedToken" - }, - { - "file": "internal/db/account_tokens.go", - "line": 64, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens.go", - "line": 87, - "kind": "function", - "name": "GetOrCreateDeviceID" - }, - { - "file": "internal/db/account_tokens.go", - "line": 91, - "kind": "local-variable", - "name": "encryptedCandidate" - }, - { - "file": "internal/db/account_tokens.go", - "line": 91, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens.go", - "line": 97, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens.go", - "line": 105, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens.go", - "line": 110, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens.go", - "line": 110, - "kind": "local-variable", - "name": "tk" - }, - { - "file": "internal/db/account_tokens.go", - "line": 119, - "kind": "function", - "name": "Clear" - }, - { - "file": "internal/db/account_tokens.go", - "line": 120, - "kind": "local-variable", - "name": "encryptedToken" - }, - { - "file": "internal/db/account_tokens.go", - "line": 120, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 13, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 13, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 15, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 19, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 20, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 31, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 34, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 34, - "kind": "local-variable", - "name": "tk" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 66, - "kind": "function", - "name": "TestAccountTokens_SaveTracksLatestRuntimeDeviceID" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 67, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 67, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 69, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 71, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 72, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 75, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 75, - "kind": "local-variable", - "name": "first" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 79, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 82, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 85, - "kind": "local-variable", - "name": "afterRestart" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 85, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 91, - "kind": "function", - "name": "TestAccountTokens_ConcurrentDeviceIDCreationConverges" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 92, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 92, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 94, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 96, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 97, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 101, - "kind": "const", - "name": "workers" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 102, - "kind": "local-variable", - "name": "results" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 103, - "kind": "local-variable", - "name": "errs" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 104, - "kind": "var", - "name": "wg" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 105, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 109, - "kind": "local-variable", - "name": "deviceID" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 109, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 120, - "kind": "range-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 123, - "kind": "var", - "name": "permanent" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 124, - "kind": "range-variable", - "name": "deviceID" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 132, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/account_tokens_test.go", - "line": 132, - "kind": "local-variable", - "name": "stored" - }, - { - "file": "internal/db/ai_reply.go", - "line": 39, - "kind": "var", - "name": "s" - }, - { - "file": "internal/db/ai_reply.go", - "line": 40, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/ai_reply.go", - "line": 41, - "kind": "var", - "name": "apiKey" - }, - { - "file": "internal/db/ai_reply.go", - "line": 41, - "kind": "var", - "name": "customPrompts" - }, - { - "file": "internal/db/ai_reply.go", - "line": 42, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/ai_reply.go", - "line": 71, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/ai_reply.go", - "line": 71, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/ai_reply.go", - "line": 79, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/ai_reply.go", - "line": 81, - "kind": "var", - "name": "item" - }, - { - "file": "internal/db/ai_reply.go", - "line": 82, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/ai_reply.go", - "line": 83, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/ai_reply.go", - "line": 94, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/ai_reply.go", - "line": 123, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/ai_reply.go", - "line": 123, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/ai_reply.go", - "line": 132, - "kind": "var", - "name": "reversed" - }, - { - "file": "internal/db/ai_reply.go", - "line": 134, - "kind": "var", - "name": "message" - }, - { - "file": "internal/db/ai_reply.go", - "line": 135, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/ai_reply.go", - "line": 140, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/ai_reply.go", - "line": 143, - "kind": "local-variable", - "name": "result" - }, - { - "file": "internal/db/ai_reply.go", - "line": 144, - "kind": "range-variable", - "name": "i" - }, - { - "file": "internal/db/ai_reply.go", - "line": 152, - "kind": "var", - "name": "count" - }, - { - "file": "internal/db/ai_reply.go", - "line": 153, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/ai_reply.go", - "line": 161, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/ai_reply.go", - "line": 170, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/ai_reply.go", - "line": 170, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/ai_reply.go", - "line": 175, - "kind": "local-variable", - "name": "query" - }, - { - "file": "internal/db/ai_reply.go", - "line": 178, - "kind": "range-variable", - "name": "message" - }, - { - "file": "internal/db/ai_reply.go", - "line": 179, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 13, - "kind": "var", - "name": "ErrAutomationRunActive" - }, - { - "file": "internal/db/automation.go", - "line": 29, - "kind": "var", - "name": "exists" - }, - { - "file": "internal/db/automation.go", - "line": 30, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 97, - "kind": "type", - "name": "DeferredAutomationTask" - }, - { - "file": "internal/db/automation.go", - "line": 108, - "kind": "var", - "name": "ErrDeferredTaskLeaseLost" - }, - { - "file": "internal/db/automation.go", - "line": 110, - "kind": "type", - "name": "AutomationRunIssue" - }, - { - "file": "internal/db/automation.go", - "line": 123, - "kind": "type", - "name": "DeferredAutomationIssue" - }, - { - "file": "internal/db/automation.go", - "line": 156, - "kind": "function", - "name": "automationRuleWhere" - }, - { - "file": "internal/db/automation.go", - "line": 157, - "kind": "local-variable", - "name": "where" - }, - { - "file": "internal/db/automation.go", - "line": 158, - "kind": "local-variable", - "name": "args" - }, - { - "file": "internal/db/automation.go", - "line": 171, - "kind": "local-variable", - "name": "search" - }, - { - "file": "internal/db/automation.go", - "line": 172, - "kind": "local-variable", - "name": "pattern" - }, - { - "file": "internal/db/automation.go", - "line": 195, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 195, - "kind": "local-variable", - "name": "rules" - }, - { - "file": "internal/db/automation.go", - "line": 201, - "kind": "local-variable", - "name": "args" - }, - { - "file": "internal/db/automation.go", - "line": 201, - "kind": "local-variable", - "name": "whereSQL" - }, - { - "file": "internal/db/automation.go", - "line": 203, - "kind": "var", - "name": "total" - }, - { - "file": "internal/db/automation.go", - "line": 204, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 212, - "kind": "local-variable", - "name": "queryArgs" - }, - { - "file": "internal/db/automation.go", - "line": 213, - "kind": "local-variable", - "name": "limitSQL" - }, - { - "file": "internal/db/automation.go", - "line": 218, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 218, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/automation.go", - "line": 229, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/db/automation.go", - "line": 231, - "kind": "var", - "name": "r" - }, - { - "file": "internal/db/automation.go", - "line": 232, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/automation.go", - "line": 233, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 238, - "kind": "local-variable", - "name": "acts" - }, - { - "file": "internal/db/automation.go", - "line": 238, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 251, - "kind": "local-variable", - "name": "args" - }, - { - "file": "internal/db/automation.go", - "line": 251, - "kind": "local-variable", - "name": "whereSQL" - }, - { - "file": "internal/db/automation.go", - "line": 252, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 252, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/automation.go", - "line": 262, - "kind": "local-variable", - "name": "counts" - }, - { - "file": "internal/db/automation.go", - "line": 264, - "kind": "var", - "name": "triggerType" - }, - { - "file": "internal/db/automation.go", - "line": 265, - "kind": "var", - "name": "count" - }, - { - "file": "internal/db/automation.go", - "line": 266, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 277, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 277, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/db/automation.go", - "line": 285, - "kind": "function", - "name": "highestPriorityRule" - }, - { - "file": "internal/db/automation.go", - "line": 294, - "kind": "var", - "name": "rule" - }, - { - "file": "internal/db/automation.go", - "line": 295, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/automation.go", - "line": 296, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 314, - "kind": "function", - "name": "matchScope" - }, - { - "file": "internal/db/automation.go", - "line": 315, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 315, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/automation.go", - "line": 330, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/db/automation.go", - "line": 332, - "kind": "var", - "name": "r" - }, - { - "file": "internal/db/automation.go", - "line": 333, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/automation.go", - "line": 334, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 339, - "kind": "local-variable", - "name": "acts" - }, - { - "file": "internal/db/automation.go", - "line": 339, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 351, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 351, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/automation.go", - "line": 356, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 356, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/db/automation.go", - "line": 360, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 368, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 368, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/automation.go", - "line": 373, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 373, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 381, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/automation.go", - "line": 384, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 387, - "kind": "range-variable", - "name": "act" - }, - { - "file": "internal/db/automation.go", - "line": 388, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 397, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 397, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 405, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/automation.go", - "line": 406, - "kind": "var", - "name": "exists" - }, - { - "file": "internal/db/automation.go", - "line": 407, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 420, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 420, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/automation.go", - "line": 431, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/db/automation.go", - "line": 433, - "kind": "var", - "name": "act" - }, - { - "file": "internal/db/automation.go", - "line": 434, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/automation.go", - "line": 435, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 449, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/db/automation.go", - "line": 450, - "kind": "local-variable", - "name": "leaseExpiresAt" - }, - { - "file": "internal/db/automation.go", - "line": 454, - "kind": "local-variable", - "name": "query" - }, - { - "file": "internal/db/automation.go", - "line": 457, - "kind": "local-variable", - "name": "args" - }, - { - "file": "internal/db/automation.go", - "line": 463, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 473, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 473, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 477, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/automation.go", - "line": 480, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/db/automation.go", - "line": 484, - "kind": "function", - "name": "reclaimRun" - }, - { - "file": "internal/db/automation.go", - "line": 485, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 485, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 496, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/automation.go", - "line": 496, - "kind": "local-variable", - "name": "rowsErr" - }, - { - "file": "internal/db/automation.go", - "line": 499, - "kind": "var", - "name": "id" - }, - { - "file": "internal/db/automation.go", - "line": 500, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 509, - "kind": "var", - "name": "run" - }, - { - "file": "internal/db/automation.go", - "line": 510, - "kind": "var", - "name": "actionStarted" - }, - { - "file": "internal/db/automation.go", - "line": 511, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 526, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 526, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 531, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 531, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/automation.go", - "line": 537, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 537, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 546, - "kind": "function", - "name": "AbortRunAction" - }, - { - "file": "internal/db/automation.go", - "line": 547, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 547, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 555, - "kind": "function", - "name": "RenewRunLease" - }, - { - "file": "internal/db/automation.go", - "line": 556, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 556, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 564, - "kind": "function", - "name": "QuarantineRun" - }, - { - "file": "internal/db/automation.go", - "line": 565, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 565, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 574, - "kind": "function", - "name": "QuarantineRunResult" - }, - { - "file": "internal/db/automation.go", - "line": 575, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 575, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 586, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 586, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 597, - "kind": "function", - "name": "ClaimRecoveryRun" - }, - { - "file": "internal/db/automation.go", - "line": 598, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/db/automation.go", - "line": 599, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 599, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 607, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 607, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/automation.go", - "line": 613, - "kind": "local-variable", - "name": "nextRetryAt" - }, - { - "file": "internal/db/automation.go", - "line": 617, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 617, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 627, - "kind": "function", - "name": "requireAutomationRunOwner" - }, - { - "file": "internal/db/automation.go", - "line": 628, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 628, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/automation.go", - "line": 644, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/db/automation.go", - "line": 645, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 645, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/automation.go", - "line": 657, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/automation.go", - "line": 659, - "kind": "var", - "name": "run" - }, - { - "file": "internal/db/automation.go", - "line": 660, - "kind": "var", - "name": "actionStarted" - }, - { - "file": "internal/db/automation.go", - "line": 661, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 677, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 677, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 691, - "kind": "function", - "name": "DeferTask" - }, - { - "file": "internal/db/automation.go", - "line": 692, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 707, - "kind": "function", - "name": "ListIssues" - }, - { - "file": "internal/db/automation.go", - "line": 708, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 708, - "kind": "local-variable", - "name": "runRows" - }, - { - "file": "internal/db/automation.go", - "line": 716, - "kind": "local-variable", - "name": "runs" - }, - { - "file": "internal/db/automation.go", - "line": 718, - "kind": "var", - "name": "issue" - }, - { - "file": "internal/db/automation.go", - "line": 719, - "kind": "var", - "name": "rawEventJSON" - }, - { - "file": "internal/db/automation.go", - "line": 720, - "kind": "var", - "name": "actionStarted" - }, - { - "file": "internal/db/automation.go", - "line": 720, - "kind": "var", - "name": "ruleEnabled" - }, - { - "file": "internal/db/automation.go", - "line": 721, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 731, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 734, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 734, - "kind": "local-variable", - "name": "taskRows" - }, - { - "file": "internal/db/automation.go", - "line": 742, - "kind": "local-variable", - "name": "tasks" - }, - { - "file": "internal/db/automation.go", - "line": 744, - "kind": "var", - "name": "issue" - }, - { - "file": "internal/db/automation.go", - "line": 745, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 754, - "kind": "function", - "name": "ResolveRunIssue" - }, - { - "file": "internal/db/automation.go", - "line": 755, - "kind": "var", - "name": "errorMessage" - }, - { - "file": "internal/db/automation.go", - "line": 755, - "kind": "var", - "name": "rawEventJSON" - }, - { - "file": "internal/db/automation.go", - "line": 756, - "kind": "var", - "name": "actionStarted" - }, - { - "file": "internal/db/automation.go", - "line": 756, - "kind": "var", - "name": "ruleEnabled" - }, - { - "file": "internal/db/automation.go", - "line": 756, - "kind": "var", - "name": "sentCount" - }, - { - "file": "internal/db/automation.go", - "line": 757, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 768, - "kind": "local-variable", - "name": "allowed" - }, - { - "file": "internal/db/automation.go", - "line": 772, - "kind": "var", - "name": "set" - }, - { - "file": "internal/db/automation.go", - "line": 783, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 783, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 788, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/automation.go", - "line": 794, - "kind": "function", - "name": "automationIssuePolicy" - }, - { - "file": "internal/db/automation.go", - "line": 800, - "kind": "var", - "name": "raw" - }, - { - "file": "internal/db/automation.go", - "line": 804, - "kind": "local-variable", - "name": "accountID" - }, - { - "file": "internal/db/automation.go", - "line": 823, - "kind": "function", - "name": "containsString" - }, - { - "file": "internal/db/automation.go", - "line": 824, - "kind": "range-variable", - "name": "value" - }, - { - "file": "internal/db/automation.go", - "line": 832, - "kind": "function", - "name": "ResolveDeferredIssue" - }, - { - "file": "internal/db/automation.go", - "line": 834, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 834, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 840, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/automation.go", - "line": 845, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 845, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 850, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/automation.go", - "line": 856, - "kind": "function", - "name": "ClaimDueDeferredTasks" - }, - { - "file": "internal/db/automation.go", - "line": 860, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/db/automation.go", - "line": 861, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 861, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/automation.go", - "line": 868, - "kind": "local-variable", - "name": "candidates" - }, - { - "file": "internal/db/automation.go", - "line": 870, - "kind": "var", - "name": "task" - }, - { - "file": "internal/db/automation.go", - "line": 871, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 877, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 880, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/automation.go", - "line": 881, - "kind": "range-variable", - "name": "task" - }, - { - "file": "internal/db/automation.go", - "line": 882, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 882, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 888, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/automation.go", - "line": 896, - "kind": "function", - "name": "FinishDeferredTask" - }, - { - "file": "internal/db/automation.go", - "line": 898, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 898, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 902, - "kind": "local-variable", - "name": "retryDelay" - }, - { - "file": "internal/db/automation.go", - "line": 903, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 903, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 910, - "kind": "function", - "name": "deferredRetryDelay" - }, - { - "file": "internal/db/automation.go", - "line": 914, - "kind": "local-variable", - "name": "delay" - }, - { - "file": "internal/db/automation.go", - "line": 926, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 935, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 946, - "kind": "function", - "name": "RenewDeferredTaskLease" - }, - { - "file": "internal/db/automation.go", - "line": 947, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 947, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/automation.go", - "line": 953, - "kind": "function", - "name": "requireDeferredTaskOwner" - }, - { - "file": "internal/db/automation.go", - "line": 957, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 957, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/automation.go", - "line": 978, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 984, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/db/automation.go", - "line": 985, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 1005, - "kind": "local-variable", - "name": "cursorSQL" - }, - { - "file": "internal/db/automation.go", - "line": 1006, - "kind": "local-variable", - "name": "args" - }, - { - "file": "internal/db/automation.go", - "line": 1012, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 1012, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/automation.go", - "line": 1033, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/db/automation.go", - "line": 1035, - "kind": "var", - "name": "ord" - }, - { - "file": "internal/db/automation.go", - "line": 1036, - "kind": "var", - "name": "isBargain" - }, - { - "file": "internal/db/automation.go", - "line": 1036, - "kind": "var", - "name": "sysShipped" - }, - { - "file": "internal/db/automation.go", - "line": 1036, - "kind": "var", - "name": "version" - }, - { - "file": "internal/db/automation.go", - "line": 1041, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 1069, - "kind": "function", - "name": "createAutomationRuleTx" - }, - { - "file": "internal/db/automation.go", - "line": 1073, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 1073, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/db/automation.go", - "line": 1080, - "kind": "range-variable", - "name": "act" - }, - { - "file": "internal/db/automation.go", - "line": 1081, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 1088, - "kind": "function", - "name": "insertAutomationActionTx" - }, - { - "file": "internal/db/automation.go", - "line": 1092, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation.go", - "line": 1101, - "kind": "function", - "name": "nullInt64" - }, - { - "file": "internal/db/automation.go", - "line": 1108, - "kind": "function", - "name": "validJSON" - }, - { - "file": "internal/db/automation.go", - "line": 1112, - "kind": "var", - "name": "v" - }, - { - "file": "internal/db/automation.go", - "line": 1113, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 25, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 25, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 27, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 28, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 28, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/automation_test.go", - "line": 33, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 33, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/automation_test.go", - "line": 45, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 45, - "kind": "local-variable", - "name": "rules" - }, - { - "file": "internal/db/automation_test.go", - "line": 52, - "kind": "local-variable", - "name": "r" - }, - { - "file": "internal/db/automation_test.go", - "line": 85, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 85, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 87, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 88, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 88, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/automation_test.go", - "line": 118, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 118, - "kind": "local-variable", - "name": "matched" - }, - { - "file": "internal/db/automation_test.go", - "line": 129, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 129, - "kind": "local-variable", - "name": "fallback" - }, - { - "file": "internal/db/automation_test.go", - "line": 141, - "kind": "function", - "name": "TestAutomationMatchReturnsOnlyHighestPriorityRule" - }, - { - "file": "internal/db/automation_test.go", - "line": 142, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 142, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 144, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 145, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 145, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/automation_test.go", - "line": 146, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 146, - "kind": "local-variable", - "name": "first" - }, - { - "file": "internal/db/automation_test.go", - "line": 150, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 153, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 153, - "kind": "local-variable", - "name": "matched" - }, - { - "file": "internal/db/automation_test.go", - "line": 161, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 161, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 163, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 164, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 164, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/automation_test.go", - "line": 166, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 166, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/automation_test.go", - "line": 184, - "kind": "local-variable", - "name": "rules" - }, - { - "file": "internal/db/automation_test.go", - "line": 188, - "kind": "local-variable", - "name": "r" - }, - { - "file": "internal/db/automation_test.go", - "line": 200, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 207, - "kind": "var", - "name": "deletedAt" - }, - { - "file": "internal/db/automation_test.go", - "line": 208, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/automation_test.go", - "line": 209, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 221, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 228, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 228, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 230, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 231, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 236, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 240, - "kind": "const", - "name": "originalPaidAt" - }, - { - "file": "internal/db/automation_test.go", - "line": 241, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 244, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 247, - "kind": "var", - "name": "paidAt" - }, - { - "file": "internal/db/automation_test.go", - "line": 248, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 263, - "kind": "function", - "name": "TestAutomation_ReviewRequest" - }, - { - "file": "internal/db/automation_test.go", - "line": 264, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 264, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 266, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 267, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 267, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/automation_test.go", - "line": 268, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 283, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 286, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/automation_test.go", - "line": 325, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 325, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 327, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 328, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 328, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/automation_test.go", - "line": 338, - "kind": "local-variable", - "name": "rules" - }, - { - "file": "internal/db/automation_test.go", - "line": 347, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 347, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 349, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 350, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 350, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/automation_test.go", - "line": 352, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/automation_test.go", - "line": 355, - "kind": "local-variable", - "name": "run" - }, - { - "file": "internal/db/automation_test.go", - "line": 360, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 360, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/db/automation_test.go", - "line": 360, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/db/automation_test.go", - "line": 365, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 370, - "kind": "function", - "name": "TestAutomationRecoverDefinitelyUnsentReviewRun" - }, - { - "file": "internal/db/automation_test.go", - "line": 371, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 371, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 373, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 374, - "kind": "local-variable", - "name": "cookieID" - }, - { - "file": "internal/db/automation_test.go", - "line": 374, - "kind": "local-variable", - "name": "userID" - }, - { - "file": "internal/db/automation_test.go", - "line": 375, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 375, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/automation_test.go", - "line": 382, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 382, - "kind": "local-variable", - "name": "runID" - }, - { - "file": "internal/db/automation_test.go", - "line": 382, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/db/automation_test.go", - "line": 389, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 395, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 395, - "kind": "local-variable", - "name": "recovered" - }, - { - "file": "internal/db/automation_test.go", - "line": 399, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 399, - "kind": "local-variable", - "name": "run" - }, - { - "file": "internal/db/automation_test.go", - "line": 408, - "kind": "function", - "name": "TestAutomation_TryStartRunRecoversStaleAndUnsentFailedRuns" - }, - { - "file": "internal/db/automation_test.go", - "line": 409, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 409, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 411, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 412, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 412, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/automation_test.go", - "line": 413, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/automation_test.go", - "line": 414, - "kind": "local-variable", - "name": "run" - }, - { - "file": "internal/db/automation_test.go", - "line": 418, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 418, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/db/automation_test.go", - "line": 418, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/db/automation_test.go", - "line": 425, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 428, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 428, - "kind": "local-variable", - "name": "recoveredID" - }, - { - "file": "internal/db/automation_test.go", - "line": 428, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/db/automation_test.go", - "line": 432, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 432, - "kind": "local-variable", - "name": "recoveredRun" - }, - { - "file": "internal/db/automation_test.go", - "line": 436, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 442, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 448, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 448, - "kind": "local-variable", - "name": "retriedRun" - }, - { - "file": "internal/db/automation_test.go", - "line": 452, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 460, - "kind": "function", - "name": "TestAutomationRunAttemptFencesStaleWorker" - }, - { - "file": "internal/db/automation_test.go", - "line": 461, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 461, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 463, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 464, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 464, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/automation_test.go", - "line": 465, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 465, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/automation_test.go", - "line": 470, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 470, - "kind": "local-variable", - "name": "runID" - }, - { - "file": "internal/db/automation_test.go", - "line": 470, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/db/automation_test.go", - "line": 476, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 476, - "kind": "local-variable", - "name": "stale" - }, - { - "file": "internal/db/automation_test.go", - "line": 480, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 483, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/automation_test.go", - "line": 483, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 487, - "kind": "local-variable", - "name": "current" - }, - { - "file": "internal/db/automation_test.go", - "line": 487, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 491, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 491, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/automation_test.go", - "line": 494, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 494, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/automation_test.go", - "line": 497, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 500, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 503, - "kind": "local-variable", - "name": "afterStale" - }, - { - "file": "internal/db/automation_test.go", - "line": 503, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 507, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 510, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 515, - "kind": "function", - "name": "TestPostponeRecoveryRunCannotOverwriteNewOwnerLease" - }, - { - "file": "internal/db/automation_test.go", - "line": 516, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 516, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 518, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 519, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 519, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/automation_test.go", - "line": 520, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/automation_test.go", - "line": 521, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 521, - "kind": "local-variable", - "name": "runID" - }, - { - "file": "internal/db/automation_test.go", - "line": 521, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/db/automation_test.go", - "line": 525, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 525, - "kind": "local-variable", - "name": "stale" - }, - { - "file": "internal/db/automation_test.go", - "line": 529, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 532, - "kind": "local-variable", - "name": "newLease" - }, - { - "file": "internal/db/automation_test.go", - "line": 533, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/automation_test.go", - "line": 533, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 537, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 540, - "kind": "local-variable", - "name": "current" - }, - { - "file": "internal/db/automation_test.go", - "line": 540, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 548, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/automation_test.go", - "line": 551, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/automation_test.go", - "line": 554, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/automation_test.go", - "line": 559, - "kind": "function", - "name": "TestAutomationIssuesCanBeListedAndResolved" - }, - { - "file": "internal/db/automation_test.go", - "line": 560, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 560, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 562, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 563, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 563, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/automation_test.go", - "line": 564, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 564, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/automation_test.go", - "line": 569, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 569, - "kind": "local-variable", - "name": "runID" - }, - { - "file": "internal/db/automation_test.go", - "line": 569, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/db/automation_test.go", - "line": 574, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 574, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/automation_test.go", - "line": 577, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 580, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 584, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 584, - "kind": "local-variable", - "name": "runs" - }, - { - "file": "internal/db/automation_test.go", - "line": 584, - "kind": "local-variable", - "name": "tasks" - }, - { - "file": "internal/db/automation_test.go", - "line": 594, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 597, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 600, - "kind": "local-variable", - "name": "run" - }, - { - "file": "internal/db/automation_test.go", - "line": 604, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 607, - "kind": "local-variable", - "name": "due" - }, - { - "file": "internal/db/automation_test.go", - "line": 607, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 611, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 614, - "kind": "var", - "name": "status" - }, - { - "file": "internal/db/automation_test.go", - "line": 615, - "kind": "var", - "name": "attempts" - }, - { - "file": "internal/db/automation_test.go", - "line": 616, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 624, - "kind": "function", - "name": "TestInvalidAutomationSnapshotCanOnlyBeCanceled" - }, - { - "file": "internal/db/automation_test.go", - "line": 625, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 625, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 627, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 628, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 628, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/automation_test.go", - "line": 629, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 629, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/automation_test.go", - "line": 634, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 634, - "kind": "local-variable", - "name": "runID" - }, - { - "file": "internal/db/automation_test.go", - "line": 634, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/db/automation_test.go", - "line": 639, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 642, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 642, - "kind": "local-variable", - "name": "runs" - }, - { - "file": "internal/db/automation_test.go", - "line": 649, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 652, - "kind": "local-variable", - "name": "run" - }, - { - "file": "internal/db/automation_test.go", - "line": 656, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 661, - "kind": "function", - "name": "TestAutomationIssuePolicyForDisabledRuleRequiresReenableBeforeRetry" - }, - { - "file": "internal/db/automation_test.go", - "line": 662, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 662, - "kind": "local-variable", - "name": "rawBytes" - }, - { - "file": "internal/db/automation_test.go", - "line": 666, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/db/automation_test.go", - "line": 667, - "kind": "local-variable", - "name": "allowed" - }, - { - "file": "internal/db/automation_test.go", - "line": 667, - "kind": "local-variable", - "name": "kind" - }, - { - "file": "internal/db/automation_test.go", - "line": 677, - "kind": "function", - "name": "TestDeferTaskRevivesDeadLetterWithFreshAttemptBudget" - }, - { - "file": "internal/db/automation_test.go", - "line": 678, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 678, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 680, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 681, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 682, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/db/automation_test.go", - "line": 683, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 688, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 691, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/automation_test.go", - "line": 691, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 697, - "kind": "function", - "name": "TestDeferredRetryBackoffAndCredentialWake" - }, - { - "file": "internal/db/automation_test.go", - "line": 698, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 698, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 700, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 701, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 702, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 705, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/automation_test.go", - "line": 705, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 709, - "kind": "local-variable", - "name": "before" - }, - { - "file": "internal/db/automation_test.go", - "line": 710, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 713, - "kind": "var", - "name": "dueAt" - }, - { - "file": "internal/db/automation_test.go", - "line": 714, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 720, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 723, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 726, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 729, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 732, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 735, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 738, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 741, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 746, - "kind": "function", - "name": "TestDeferredTaskFencingRejectsStaleWorker" - }, - { - "file": "internal/db/automation_test.go", - "line": 747, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 747, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 749, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 750, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 751, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 756, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 756, - "kind": "local-variable", - "name": "first" - }, - { - "file": "internal/db/automation_test.go", - "line": 760, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 763, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 763, - "kind": "local-variable", - "name": "second" - }, - { - "file": "internal/db/automation_test.go", - "line": 770, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 773, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 776, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/automation_test.go", - "line": 781, - "kind": "function", - "name": "TestAutomationRuleDeleteRejectsActiveRun" - }, - { - "file": "internal/db/automation_test.go", - "line": 782, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/automation_test.go", - "line": 782, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/automation_test.go", - "line": 784, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/automation_test.go", - "line": 785, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/automation_test.go", - "line": 785, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/automation_test.go", - "line": 786, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/automation_test.go", - "line": 790, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 12, - "kind": "type", - "name": "ChatSession" - }, - { - "file": "internal/db/chat.go", - "line": 25, - "kind": "type", - "name": "ChatMessage" - }, - { - "file": "internal/db/chat.go", - "line": 39, - "kind": "type", - "name": "ChatStore" - }, - { - "file": "internal/db/chat.go", - "line": 44, - "kind": "function", - "name": "UpsertSession" - }, - { - "file": "internal/db/chat.go", - "line": 45, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/db/chat.go", - "line": 46, - "kind": "local-variable", - "name": "prefix" - }, - { - "file": "internal/db/chat.go", - "line": 47, - "kind": "local-variable", - "name": "query" - }, - { - "file": "internal/db/chat.go", - "line": 50, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 55, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 71, - "kind": "function", - "name": "DeleteSession" - }, - { - "file": "internal/db/chat.go", - "line": 72, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 80, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 89, - "kind": "function", - "name": "SyncSessionSummary" - }, - { - "file": "internal/db/chat.go", - "line": 90, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 96, - "kind": "function", - "name": "UpdateSessionIdentity" - }, - { - "file": "internal/db/chat.go", - "line": 97, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 109, - "kind": "function", - "name": "LatestUnmaskedPeerName" - }, - { - "file": "internal/db/chat.go", - "line": 110, - "kind": "var", - "name": "name" - }, - { - "file": "internal/db/chat.go", - "line": 111, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 125, - "kind": "function", - "name": "SaveMessage" - }, - { - "file": "internal/db/chat.go", - "line": 139, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/db/chat.go", - "line": 140, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 140, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/chat.go", - "line": 147, - "kind": "local-variable", - "name": "sessionPrefix" - }, - { - "file": "internal/db/chat.go", - "line": 148, - "kind": "local-variable", - "name": "sessionInsert" - }, - { - "file": "internal/db/chat.go", - "line": 151, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 156, - "kind": "local-variable", - "name": "prefix" - }, - { - "file": "internal/db/chat.go", - "line": 157, - "kind": "local-variable", - "name": "query" - }, - { - "file": "internal/db/chat.go", - "line": 160, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 160, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/chat.go", - "line": 166, - "kind": "local-variable", - "name": "inserted" - }, - { - "file": "internal/db/chat.go", - "line": 168, - "kind": "local-variable", - "name": "unreadDelta" - }, - { - "file": "internal/db/chat.go", - "line": 172, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 182, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 185, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 185, - "kind": "local-variable", - "name": "stored" - }, - { - "file": "internal/db/chat.go", - "line": 189, - "kind": "function", - "name": "GetMessageByKey" - }, - { - "file": "internal/db/chat.go", - "line": 190, - "kind": "var", - "name": "m" - }, - { - "file": "internal/db/chat.go", - "line": 191, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 203, - "kind": "function", - "name": "UpdateMessageType" - }, - { - "file": "internal/db/chat.go", - "line": 204, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 209, - "kind": "function", - "name": "ListSessions" - }, - { - "file": "internal/db/chat.go", - "line": 213, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 213, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/chat.go", - "line": 221, - "kind": "var", - "name": "result" - }, - { - "file": "internal/db/chat.go", - "line": 223, - "kind": "var", - "name": "row" - }, - { - "file": "internal/db/chat.go", - "line": 224, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 233, - "kind": "function", - "name": "ListMessages" - }, - { - "file": "internal/db/chat.go", - "line": 237, - "kind": "local-variable", - "name": "query" - }, - { - "file": "internal/db/chat.go", - "line": 240, - "kind": "local-variable", - "name": "args" - }, - { - "file": "internal/db/chat.go", - "line": 248, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 248, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/chat.go", - "line": 253, - "kind": "var", - "name": "result" - }, - { - "file": "internal/db/chat.go", - "line": 255, - "kind": "var", - "name": "m" - }, - { - "file": "internal/db/chat.go", - "line": 256, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 263, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/db/chat.go", - "line": 263, - "kind": "local-variable", - "name": "j" - }, - { - "file": "internal/db/chat.go", - "line": 269, - "kind": "function", - "name": "MarkRead" - }, - { - "file": "internal/db/chat.go", - "line": 270, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/chat.go", - "line": 276, - "kind": "function", - "name": "UpdateMessageStatus" - }, - { - "file": "internal/db/chat.go", - "line": 277, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 13, - "kind": "const", - "name": "DisableReasonManual" - }, - { - "file": "internal/db/cookies.go", - "line": 41, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 41, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/cookies.go", - "line": 46, - "kind": "var", - "name": "ownerID" - }, - { - "file": "internal/db/cookies.go", - "line": 47, - "kind": "var", - "name": "metadataJSON" - }, - { - "file": "internal/db/cookies.go", - "line": 48, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 58, - "kind": "local-variable", - "name": "assignments" - }, - { - "file": "internal/db/cookies.go", - "line": 59, - "kind": "local-variable", - "name": "args" - }, - { - "file": "internal/db/cookies.go", - "line": 61, - "kind": "local-variable", - "name": "encrypted" - }, - { - "file": "internal/db/cookies.go", - "line": 61, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 67, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 67, - "kind": "local-variable", - "name": "plainMetadata" - }, - { - "file": "internal/db/cookies.go", - "line": 71, - "kind": "local-variable", - "name": "cleanMetadata" - }, - { - "file": "internal/db/cookies.go", - "line": 71, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 86, - "kind": "local-variable", - "name": "pausedUntil" - }, - { - "file": "internal/db/cookies.go", - "line": 102, - "kind": "local-variable", - "name": "encrypted" - }, - { - "file": "internal/db/cookies.go", - "line": 102, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 115, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 120, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 128, - "kind": "local-variable", - "name": "seen" - }, - { - "file": "internal/db/cookies.go", - "line": 129, - "kind": "range-variable", - "name": "channelID" - }, - { - "file": "internal/db/cookies.go", - "line": 130, - "kind": "local-variable", - "name": "duplicate" - }, - { - "file": "internal/db/cookies.go", - "line": 134, - "kind": "var", - "name": "exists" - }, - { - "file": "internal/db/cookies.go", - "line": 135, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 142, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 145, - "kind": "range-variable", - "name": "channelID" - }, - { - "file": "internal/db/cookies.go", - "line": 146, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 151, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 162, - "kind": "local-variable", - "name": "encrypted" - }, - { - "file": "internal/db/cookies.go", - "line": 162, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 166, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 166, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/cookies.go", - "line": 173, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/cookies.go", - "line": 173, - "kind": "local-variable", - "name": "rowsErr" - }, - { - "file": "internal/db/cookies.go", - "line": 179, - "kind": "var", - "name": "existingOwner" - }, - { - "file": "internal/db/cookies.go", - "line": 180, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 197, - "kind": "local-variable", - "name": "encrypted" - }, - { - "file": "internal/db/cookies.go", - "line": 197, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 201, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 201, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/cookies.go", - "line": 206, - "kind": "var", - "name": "existingOwner" - }, - { - "file": "internal/db/cookies.go", - "line": 207, - "kind": "var", - "name": "rawMetadata" - }, - { - "file": "internal/db/cookies.go", - "line": 208, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 217, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 217, - "kind": "local-variable", - "name": "metadata" - }, - { - "file": "internal/db/cookies.go", - "line": 221, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 221, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/cookies.go", - "line": 227, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/cookies.go", - "line": 227, - "kind": "local-variable", - "name": "rowsErr" - }, - { - "file": "internal/db/cookies.go", - "line": 241, - "kind": "local-variable", - "name": "encrypted" - }, - { - "file": "internal/db/cookies.go", - "line": 241, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 245, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 245, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/cookies.go", - "line": 250, - "kind": "var", - "name": "rawMetadata" - }, - { - "file": "internal/db/cookies.go", - "line": 251, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 257, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 257, - "kind": "local-variable", - "name": "metadata" - }, - { - "file": "internal/db/cookies.go", - "line": 261, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 261, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/cookies.go", - "line": 266, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 266, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/cookies.go", - "line": 276, - "kind": "function", - "name": "cookieSelectForUpdate" - }, - { - "file": "internal/db/cookies.go", - "line": 277, - "kind": "local-variable", - "name": "query" - }, - { - "file": "internal/db/cookies.go", - "line": 284, - "kind": "function", - "name": "metadataWithoutCookieSnapshotValue" - }, - { - "file": "internal/db/cookies.go", - "line": 285, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 285, - "kind": "local-variable", - "name": "plain" - }, - { - "file": "internal/db/cookies.go", - "line": 292, - "kind": "function", - "name": "stripCookieSnapshotMetadata" - }, - { - "file": "internal/db/cookies.go", - "line": 296, - "kind": "var", - "name": "values" - }, - { - "file": "internal/db/cookies.go", - "line": 297, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 303, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 303, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/db/cookies.go", - "line": 316, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 321, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 331, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 331, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/cookies.go", - "line": 336, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 345, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 348, - "kind": "range-variable", - "name": "table" - }, - { - "file": "internal/db/cookies.go", - "line": 355, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 359, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 367, - "kind": "var", - "name": "v" - }, - { - "file": "internal/db/cookies.go", - "line": 368, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 380, - "kind": "var", - "name": "rows" - }, - { - "file": "internal/db/cookies.go", - "line": 381, - "kind": "var", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 391, - "kind": "local-variable", - "name": "m" - }, - { - "file": "internal/db/cookies.go", - "line": 393, - "kind": "var", - "name": "id" - }, - { - "file": "internal/db/cookies.go", - "line": 393, - "kind": "var", - "name": "v" - }, - { - "file": "internal/db/cookies.go", - "line": 394, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 397, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 397, - "kind": "local-variable", - "name": "plain" - }, - { - "file": "internal/db/cookies.go", - "line": 408, - "kind": "var", - "name": "d" - }, - { - "file": "internal/db/cookies.go", - "line": 409, - "kind": "var", - "name": "autoConfirm" - }, - { - "file": "internal/db/cookies.go", - "line": 409, - "kind": "var", - "name": "showBrowser" - }, - { - "file": "internal/db/cookies.go", - "line": 410, - "kind": "var", - "name": "pauseDuration" - }, - { - "file": "internal/db/cookies.go", - "line": 411, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 451, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/db/cookies.go", - "line": 455, - "kind": "local-variable", - "name": "encrypted" - }, - { - "file": "internal/db/cookies.go", - "line": 455, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 469, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 479, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 489, - "kind": "var", - "name": "pd" - }, - { - "file": "internal/db/cookies.go", - "line": 490, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 502, - "kind": "local-variable", - "name": "pausedUntil" - }, - { - "file": "internal/db/cookies.go", - "line": 506, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 518, - "kind": "var", - "name": "pausedUntil" - }, - { - "file": "internal/db/cookies.go", - "line": 519, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 531, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/cookies.go", - "line": 532, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 549, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/db/cookies.go", - "line": 553, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 566, - "kind": "local-variable", - "name": "enabled" - }, - { - "file": "internal/db/cookies.go", - "line": 566, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 575, - "kind": "local-variable", - "name": "enabled" - }, - { - "file": "internal/db/cookies.go", - "line": 575, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 582, - "kind": "var", - "name": "exists" - }, - { - "file": "internal/db/cookies.go", - "line": 583, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies.go", - "line": 589, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/cookies.go", - "line": 590, - "kind": "var", - "name": "reason" - }, - { - "file": "internal/db/cookies.go", - "line": 591, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 10, - "kind": "function", - "name": "TestCreateOwnedConcurrentUsersNeverTransfersOwner" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 11, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 11, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 13, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 14, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 17, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 20, - "kind": "local-variable", - "name": "a" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 21, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 23, - "kind": "local-variable", - "name": "start" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 24, - "kind": "local-variable", - "name": "results" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 25, - "kind": "var", - "name": "wg" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 26, - "kind": "range-variable", - "name": "input" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 30, - "kind": "local-variable", - "name": "input" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 42, - "kind": "local-variable", - "name": "successes" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 43, - "kind": "range-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 55, - "kind": "var", - "name": "owner" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 56, - "kind": "var", - "name": "value" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 57, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 68, - "kind": "function", - "name": "TestUpdateValueExistingCannotResurrectDeletedAccount" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 69, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 69, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 71, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 72, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 75, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 76, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 79, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 82, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 85, - "kind": "var", - "name": "count" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 86, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 91, - "kind": "function", - "name": "TestDeleteUserCleansNonForeignKeyAccountData" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 92, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 92, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 94, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 95, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 98, - "kind": "local-variable", - "name": "owner" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 99, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 102, - "kind": "range-variable", - "name": "query" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 109, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 113, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 116, - "kind": "range-variable", - "name": "table" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 120, - "kind": "var", - "name": "count" - }, - { - "file": "internal/db/cookies_concurrency_test.go", - "line": 121, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 9, - "kind": "function", - "name": "TestUpdateAccountSettingsIsAtomic" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 10, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 10, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 12, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 13, - "kind": "range-variable", - "name": "user" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 14, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 14, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 18, - "kind": "local-variable", - "name": "owner" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 19, - "kind": "local-variable", - "name": "other" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 20, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 23, - "kind": "local-variable", - "name": "channelResult" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 23, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 27, - "kind": "local-variable", - "name": "otherChannelID" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 28, - "kind": "local-variable", - "name": "newCookie" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 28, - "kind": "local-variable", - "name": "remark" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 29, - "kind": "local-variable", - "name": "autoConfirm" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 30, - "kind": "local-variable", - "name": "badChannels" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 37, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 46, - "kind": "local-variable", - "name": "ownedChannelID" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 47, - "kind": "local-variable", - "name": "channels" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 48, - "kind": "local-variable", - "name": "pause" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 49, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/cookies_settings_test.go", - "line": 55, - "kind": "local-variable", - "name": "bindings" - }, - { - "file": "internal/db/db.go", - "line": 28, - "kind": "var", - "name": "migrationsFS" - }, - { - "file": "internal/db/db.go", - "line": 34, - "kind": "const", - "name": "DialectSQLite" - }, - { - "file": "internal/db/db.go", - "line": 35, - "kind": "const", - "name": "DialectMySQL" - }, - { - "file": "internal/db/db.go", - "line": 36, - "kind": "const", - "name": "DialectPostgres" - }, - { - "file": "internal/db/db.go", - "line": 43, - "kind": "const", - "name": "driverSQLite" - }, - { - "file": "internal/db/db.go", - "line": 44, - "kind": "const", - "name": "driverMySQL" - }, - { - "file": "internal/db/db.go", - "line": 57, - "kind": "local-variable", - "name": "dialect" - }, - { - "file": "internal/db/db.go", - "line": 57, - "kind": "local-variable", - "name": "driver" - }, - { - "file": "internal/db/db.go", - "line": 57, - "kind": "local-variable", - "name": "dsn" - }, - { - "file": "internal/db/db.go", - "line": 57, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/db.go", - "line": 61, - "kind": "local-variable", - "name": "db" - }, - { - "file": "internal/db/db.go", - "line": 61, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/db.go", - "line": 77, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/db.go", - "line": 82, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/db.go", - "line": 97, - "kind": "local-variable", - "name": "dsn" - }, - { - "file": "internal/db/db.go", - "line": 100, - "kind": "local-variable", - "name": "idx" - }, - { - "file": "internal/db/db.go", - "line": 101, - "kind": "local-variable", - "name": "scheme" - }, - { - "file": "internal/db/db.go", - "line": 102, - "kind": "local-variable", - "name": "rest" - }, - { - "file": "internal/db/db.go", - "line": 137, - "kind": "function", - "name": "forceMySQLBoolParam" - }, - { - "file": "internal/db/db.go", - "line": 138, - "kind": "local-variable", - "name": "base" - }, - { - "file": "internal/db/db.go", - "line": 138, - "kind": "local-variable", - "name": "hasQuery" - }, - { - "file": "internal/db/db.go", - "line": 138, - "kind": "local-variable", - "name": "rawQuery" - }, - { - "file": "internal/db/db.go", - "line": 139, - "kind": "local-variable", - "name": "parts" - }, - { - "file": "internal/db/db.go", - "line": 140, - "kind": "local-variable", - "name": "found" - }, - { - "file": "internal/db/db.go", - "line": 142, - "kind": "range-variable", - "name": "part" - }, - { - "file": "internal/db/db.go", - "line": 146, - "kind": "local-variable", - "name": "name" - }, - { - "file": "internal/db/db.go", - "line": 165, - "kind": "var", - "name": "gooseDialect" - }, - { - "file": "internal/db/db.go", - "line": 166, - "kind": "var", - "name": "subdir" - }, - { - "file": "internal/db/db.go", - "line": 177, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/db.go", - "line": 181, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/db_url_test.go", - "line": 12, - "kind": "local-variable", - "name": "cases" - }, - { - "file": "internal/db/db_url_test.go", - "line": 34, - "kind": "range-variable", - "name": "c" - }, - { - "file": "internal/db/db_url_test.go", - "line": 36, - "kind": "local-variable", - "name": "dialect" - }, - { - "file": "internal/db/db_url_test.go", - "line": 36, - "kind": "local-variable", - "name": "driver" - }, - { - "file": "internal/db/db_url_test.go", - "line": 36, - "kind": "local-variable", - "name": "dsn" - }, - { - "file": "internal/db/db_url_test.go", - "line": 36, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/db_url_test.go", - "line": 86, - "kind": "local-variable", - "name": "cases" - }, - { - "file": "internal/db/db_url_test.go", - "line": 99, - "kind": "range-variable", - "name": "c" - }, - { - "file": "internal/db/db_url_test.go", - "line": 101, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/delivery.go", - "line": 50, - "kind": "var", - "name": "it" - }, - { - "file": "internal/db/delivery.go", - "line": 51, - "kind": "var", - "name": "isMulti" - }, - { - "file": "internal/db/delivery.go", - "line": 51, - "kind": "var", - "name": "multiQty" - }, - { - "file": "internal/db/delivery.go", - "line": 52, - "kind": "var", - "name": "cat" - }, - { - "file": "internal/db/delivery.go", - "line": 52, - "kind": "var", - "name": "desc" - }, - { - "file": "internal/db/delivery.go", - "line": 52, - "kind": "var", - "name": "detail" - }, - { - "file": "internal/db/delivery.go", - "line": 52, - "kind": "var", - "name": "price" - }, - { - "file": "internal/db/delivery.go", - "line": 52, - "kind": "var", - "name": "title" - }, - { - "file": "internal/db/delivery.go", - "line": 53, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/delivery.go", - "line": 77, - "kind": "var", - "name": "v" - }, - { - "file": "internal/db/delivery.go", - "line": 78, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/delivery.go", - "line": 87, - "kind": "var", - "name": "v" - }, - { - "file": "internal/db/delivery.go", - "line": 88, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/delivery.go", - "line": 104, - "kind": "local-variable", - "name": "attempts" - }, - { - "file": "internal/db/delivery.go", - "line": 105, - "kind": "var", - "name": "dataContent" - }, - { - "file": "internal/db/delivery.go", - "line": 106, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/delivery.go", - "line": 116, - "kind": "local-variable", - "name": "lines" - }, - { - "file": "internal/db/delivery.go", - "line": 120, - "kind": "local-variable", - "name": "remaining" - }, - { - "file": "internal/db/delivery.go", - "line": 124, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/delivery.go", - "line": 124, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/delivery.go", - "line": 130, - "kind": "local-variable", - "name": "affected" - }, - { - "file": "internal/db/delivery.go", - "line": 130, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/delivery.go", - "line": 144, - "kind": "local-variable", - "name": "attempts" - }, - { - "file": "internal/db/delivery.go", - "line": 145, - "kind": "var", - "name": "current" - }, - { - "file": "internal/db/delivery.go", - "line": 146, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/delivery.go", - "line": 152, - "kind": "local-variable", - "name": "merged" - }, - { - "file": "internal/db/delivery.go", - "line": 156, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/delivery.go", - "line": 156, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/delivery.go", - "line": 162, - "kind": "local-variable", - "name": "affected" - }, - { - "file": "internal/db/delivery.go", - "line": 162, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/delivery.go", - "line": 172, - "kind": "var", - "name": "dataContent" - }, - { - "file": "internal/db/delivery.go", - "line": 183, - "kind": "local-variable", - "name": "lines" - }, - { - "file": "internal/db/delivery.go", - "line": 193, - "kind": "local-variable", - "name": "lines" - }, - { - "file": "internal/db/delivery.go", - "line": 197, - "kind": "local-variable", - "name": "remaining" - }, - { - "file": "internal/db/delivery.go", - "line": 201, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/delivery.go", - "line": 201, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/delivery.go", - "line": 205, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/delivery.go", - "line": 205, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/delivery.go", - "line": 215, - "kind": "local-variable", - "name": "lines" - }, - { - "file": "internal/db/delivery.go", - "line": 216, - "kind": "local-variable", - "name": "valid" - }, - { - "file": "internal/db/delivery.go", - "line": 217, - "kind": "range-variable", - "name": "l" - }, - { - "file": "internal/db/delivery.go", - "line": 225, - "kind": "local-variable", - "name": "attempts" - }, - { - "file": "internal/db/delivery.go", - "line": 226, - "kind": "var", - "name": "existing" - }, - { - "file": "internal/db/delivery.go", - "line": 227, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/delivery.go", - "line": 234, - "kind": "local-variable", - "name": "merged" - }, - { - "file": "internal/db/delivery.go", - "line": 238, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/delivery.go", - "line": 238, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/delivery.go", - "line": 244, - "kind": "local-variable", - "name": "affected" - }, - { - "file": "internal/db/delivery.go", - "line": 244, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/delivery.go", - "line": 253, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/delivery.go", - "line": 254, - "kind": "local-variable", - "name": "cur" - }, - { - "file": "internal/db/delivery.go", - "line": 255, - "kind": "range-variable", - "name": "r" - }, - { - "file": "internal/db/delivery.go", - "line": 273, - "kind": "range-variable", - "name": "l" - }, - { - "file": "internal/db/delivery.go", - "line": 281, - "kind": "function", - "name": "joinLines" - }, - { - "file": "internal/db/delivery.go", - "line": 285, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/db/delivery.go", - "line": 286, - "kind": "range-variable", - "name": "l" - }, - { - "file": "internal/db/dialect.go", - "line": 22, - "kind": "local-variable", - "name": "keys" - }, - { - "file": "internal/db/dialect.go", - "line": 23, - "kind": "range-variable", - "name": "k" - }, - { - "file": "internal/db/dialect.go", - "line": 27, - "kind": "local-variable", - "name": "sets" - }, - { - "file": "internal/db/dialect.go", - "line": 28, - "kind": "range-variable", - "name": "col" - }, - { - "file": "internal/db/dialect.go", - "line": 29, - "kind": "local-variable", - "name": "expr" - }, - { - "file": "internal/db/dialect.go", - "line": 67, - "kind": "function", - "name": "dialectInsertIgnore" - }, - { - "file": "internal/db/dialect.go", - "line": 77, - "kind": "function", - "name": "dialectInsertIgnorePrefix" - }, - { - "file": "internal/db/dialect.go", - "line": 90, - "kind": "function", - "name": "dialectQuote" - }, - { - "file": "internal/db/dialect.go", - "line": 94, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/db/dialect.go", - "line": 95, - "kind": "local-variable", - "name": "j" - }, - { - "file": "internal/db/dialect.go", - "line": 113, - "kind": "var", - "name": "id" - }, - { - "file": "internal/db/dialect.go", - "line": 114, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/dialect.go", - "line": 119, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/dialect.go", - "line": 119, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/dialect_test.go", - "line": 13, - "kind": "local-variable", - "name": "cases" - }, - { - "file": "internal/db/dialect_test.go", - "line": 70, - "kind": "range-variable", - "name": "c" - }, - { - "file": "internal/db/dialect_test.go", - "line": 72, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/dialect_test.go", - "line": 83, - "kind": "local-variable", - "name": "cases" - }, - { - "file": "internal/db/dialect_test.go", - "line": 94, - "kind": "range-variable", - "name": "c" - }, - { - "file": "internal/db/dialect_test.go", - "line": 95, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/dialect_test.go", - "line": 104, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/dialect_test.go", - "line": 107, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/dialect_test.go", - "line": 110, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/dialect_test.go", - "line": 117, - "kind": "local-variable", - "name": "cases" - }, - { - "file": "internal/db/dialect_test.go", - "line": 127, - "kind": "range-variable", - "name": "c" - }, - { - "file": "internal/db/dialect_test.go", - "line": 128, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/dialect_test.go", - "line": 136, - "kind": "local-variable", - "name": "in" - }, - { - "file": "internal/db/dialect_test.go", - "line": 138, - "kind": "local-variable", - "name": "want" - }, - { - "file": "internal/db/dialect_test.go", - "line": 139, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/extras.go", - "line": 24, - "kind": "function", - "name": "UpdateByID" - }, - { - "file": "internal/db/extras.go", - "line": 25, - "kind": "local-variable", - "name": "kwType" - }, - { - "file": "internal/db/extras.go", - "line": 29, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 29, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/extras.go", - "line": 36, - "kind": "local-variable", - "name": "affected" - }, - { - "file": "internal/db/extras.go", - "line": 36, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 42, - "kind": "function", - "name": "DeleteByID" - }, - { - "file": "internal/db/extras.go", - "line": 43, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 43, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/extras.go", - "line": 47, - "kind": "local-variable", - "name": "affected" - }, - { - "file": "internal/db/extras.go", - "line": 47, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 55, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 55, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/extras.go", - "line": 62, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/extras.go", - "line": 64, - "kind": "var", - "name": "r" - }, - { - "file": "internal/db/extras.go", - "line": 65, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 86, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 86, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/extras.go", - "line": 91, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 94, - "kind": "range-variable", - "name": "row" - }, - { - "file": "internal/db/extras.go", - "line": 95, - "kind": "local-variable", - "name": "kwType" - }, - { - "file": "internal/db/extras.go", - "line": 99, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 110, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 110, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/extras.go", - "line": 116, - "kind": "var", - "name": "ids" - }, - { - "file": "internal/db/extras.go", - "line": 118, - "kind": "var", - "name": "id" - }, - { - "file": "internal/db/extras.go", - "line": 119, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 137, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 137, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/extras.go", - "line": 146, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 156, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 163, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 163, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/extras.go", - "line": 169, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/extras.go", - "line": 171, - "kind": "var", - "name": "r" - }, - { - "file": "internal/db/extras.go", - "line": 172, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 195, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 195, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/extras.go", - "line": 202, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/extras.go", - "line": 204, - "kind": "var", - "name": "c" - }, - { - "file": "internal/db/extras.go", - "line": 205, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/extras.go", - "line": 206, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 221, - "kind": "local-variable", - "name": "config" - }, - { - "file": "internal/db/extras.go", - "line": 221, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 233, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 237, - "kind": "local-variable", - "name": "config" - }, - { - "file": "internal/db/extras.go", - "line": 237, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 249, - "kind": "local-variable", - "name": "row" - }, - { - "file": "internal/db/extras.go", - "line": 252, - "kind": "var", - "name": "c" - }, - { - "file": "internal/db/extras.go", - "line": 253, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/extras.go", - "line": 254, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 261, - "kind": "local-variable", - "name": "config" - }, - { - "file": "internal/db/extras.go", - "line": 261, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 271, - "kind": "local-variable", - "name": "config" - }, - { - "file": "internal/db/extras.go", - "line": 271, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 275, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 275, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/extras.go", - "line": 283, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 283, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/extras.go", - "line": 292, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 298, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 298, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/extras.go", - "line": 302, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 302, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/extras.go", - "line": 311, - "kind": "local-variable", - "name": "row" - }, - { - "file": "internal/db/extras.go", - "line": 313, - "kind": "var", - "name": "c" - }, - { - "file": "internal/db/extras.go", - "line": 314, - "kind": "var", - "name": "userID" - }, - { - "file": "internal/db/extras.go", - "line": 315, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 321, - "kind": "local-variable", - "name": "config" - }, - { - "file": "internal/db/extras.go", - "line": 321, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 331, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 331, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/extras.go", - "line": 341, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/extras.go", - "line": 343, - "kind": "var", - "name": "id" - }, - { - "file": "internal/db/extras.go", - "line": 344, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 354, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 354, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/extras.go", - "line": 359, - "kind": "var", - "name": "userID" - }, - { - "file": "internal/db/extras.go", - "line": 360, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 366, - "kind": "range-variable", - "name": "channelID" - }, - { - "file": "internal/db/extras.go", - "line": 367, - "kind": "var", - "name": "exists" - }, - { - "file": "internal/db/extras.go", - "line": 368, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 377, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 380, - "kind": "range-variable", - "name": "cid" - }, - { - "file": "internal/db/extras.go", - "line": 381, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 401, - "kind": "var", - "name": "v" - }, - { - "file": "internal/db/extras.go", - "line": 402, - "kind": "local-variable", - "name": "keyCol" - }, - { - "file": "internal/db/extras.go", - "line": 403, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 418, - "kind": "local-variable", - "name": "keyCol" - }, - { - "file": "internal/db/extras.go", - "line": 419, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 419, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/extras.go", - "line": 424, - "kind": "local-variable", - "name": "m" - }, - { - "file": "internal/db/extras.go", - "line": 426, - "kind": "var", - "name": "k" - }, - { - "file": "internal/db/extras.go", - "line": 426, - "kind": "var", - "name": "v" - }, - { - "file": "internal/db/extras.go", - "line": 427, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 444, - "kind": "local-variable", - "name": "encrypted" - }, - { - "file": "internal/db/extras.go", - "line": 444, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 450, - "kind": "local-variable", - "name": "keyCol" - }, - { - "file": "internal/db/extras.go", - "line": 451, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 463, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 463, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/extras.go", - "line": 468, - "kind": "local-variable", - "name": "keyCol" - }, - { - "file": "internal/db/extras.go", - "line": 469, - "kind": "local-variable", - "name": "query" - }, - { - "file": "internal/db/extras.go", - "line": 473, - "kind": "range-variable", - "name": "key" - }, - { - "file": "internal/db/extras.go", - "line": 473, - "kind": "range-variable", - "name": "value" - }, - { - "file": "internal/db/extras.go", - "line": 475, - "kind": "local-variable", - "name": "encrypted" - }, - { - "file": "internal/db/extras.go", - "line": 475, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 481, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 495, - "kind": "local-variable", - "name": "all" - }, - { - "file": "internal/db/extras.go", - "line": 495, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 499, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/db/extras.go", - "line": 500, - "kind": "range-variable", - "name": "k" - }, - { - "file": "internal/db/extras.go", - "line": 501, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/extras.go", - "line": 501, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/db/extras.go", - "line": 532, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 532, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/extras.go", - "line": 541, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/extras.go", - "line": 543, - "kind": "var", - "name": "r" - }, - { - "file": "internal/db/extras.go", - "line": 544, - "kind": "var", - "name": "isMulti" - }, - { - "file": "internal/db/extras.go", - "line": 544, - "kind": "var", - "name": "multiQty" - }, - { - "file": "internal/db/extras.go", - "line": 545, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 558, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 584, - "kind": "function", - "name": "UpsertBasicTx" - }, - { - "file": "internal/db/extras.go", - "line": 599, - "kind": "local-variable", - "name": "remoteIDs" - }, - { - "file": "internal/db/extras.go", - "line": 600, - "kind": "local-variable", - "name": "validRows" - }, - { - "file": "internal/db/extras.go", - "line": 601, - "kind": "range-variable", - "name": "row" - }, - { - "file": "internal/db/extras.go", - "line": 607, - "kind": "local-variable", - "name": "exists" - }, - { - "file": "internal/db/extras.go", - "line": 614, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 614, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/extras.go", - "line": 618, - "kind": "local-variable", - "name": "rollback" - }, - { - "file": "internal/db/extras.go", - "line": 622, - "kind": "range-variable", - "name": "index" - }, - { - "file": "internal/db/extras.go", - "line": 623, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 627, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 635, - "kind": "local-variable", - "name": "args" - }, - { - "file": "internal/db/extras.go", - "line": 637, - "kind": "local-variable", - "name": "deleteQuery" - }, - { - "file": "internal/db/extras.go", - "line": 639, - "kind": "local-variable", - "name": "placeholders" - }, - { - "file": "internal/db/extras.go", - "line": 640, - "kind": "range-variable", - "name": "itemID" - }, - { - "file": "internal/db/extras.go", - "line": 646, - "kind": "local-variable", - "name": "deletedResult" - }, - { - "file": "internal/db/extras.go", - "line": 646, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 650, - "kind": "local-variable", - "name": "deleted" - }, - { - "file": "internal/db/extras.go", - "line": 650, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 655, - "kind": "local-variable", - "name": "ruleArgs" - }, - { - "file": "internal/db/extras.go", - "line": 657, - "kind": "local-variable", - "name": "ruleQuery" - }, - { - "file": "internal/db/extras.go", - "line": 661, - "kind": "local-variable", - "name": "placeholders" - }, - { - "file": "internal/db/extras.go", - "line": 662, - "kind": "range-variable", - "name": "itemID" - }, - { - "file": "internal/db/extras.go", - "line": 668, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 671, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 677, - "kind": "function", - "name": "upsertBasic" - }, - { - "file": "internal/db/extras.go", - "line": 701, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 712, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 712, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/extras.go", - "line": 717, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 722, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 732, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras.go", - "line": 740, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 9, - "kind": "function", - "name": "TestExtraRepositoriesCRUD" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 10, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 10, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 12, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 13, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 13, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 16, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 17, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 21, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 21, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 25, - "kind": "local-variable", - "name": "keywords" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 29, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 32, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 36, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 39, - "kind": "local-variable", - "name": "replies" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 43, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 47, - "kind": "local-variable", - "name": "item" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 48, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 51, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 54, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 57, - "kind": "local-variable", - "name": "items" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 61, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 69, - "kind": "local-variable", - "name": "channelID" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 69, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 75, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 78, - "kind": "local-variable", - "name": "bindings" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 82, - "kind": "local-variable", - "name": "channels" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 87, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 90, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 94, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 97, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 100, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 100, - "kind": "local-variable", - "name": "public" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 104, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 109, - "kind": "function", - "name": "TestItemsSyncFromRemoteReconcilesAndPreservesLocalSettings" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 110, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 110, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 112, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 113, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 113, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 117, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 117, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 121, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 125, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 130, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 133, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 136, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 139, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 139, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 148, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 148, - "kind": "local-variable", - "name": "result" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 159, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 159, - "kind": "local-variable", - "name": "items" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 166, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 166, - "kind": "local-variable", - "name": "item" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 174, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 177, - "kind": "var", - "name": "itemDeletedAt" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 178, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 185, - "kind": "var", - "name": "ruleDeletedAt" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 186, - "kind": "var", - "name": "ruleEnabled" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 187, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 194, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 194, - "kind": "local-variable", - "name": "rules" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 201, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 201, - "kind": "local-variable", - "name": "matched" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 213, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 225, - "kind": "function", - "name": "TestItemsDeleteSoftDeletesRelatedAutomationRule" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 226, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 226, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 228, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 229, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 229, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 232, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 232, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 236, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 239, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 242, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 242, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 250, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 253, - "kind": "var", - "name": "itemDeletedAt" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 253, - "kind": "var", - "name": "ruleDeletedAt" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 254, - "kind": "var", - "name": "ruleEnabled" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 255, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_repository_test.go", - "line": 258, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 14, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_test.go", - "line": 14, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/extras_test.go", - "line": 16, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_test.go", - "line": 17, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/extras_test.go", - "line": 28, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 31, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 31, - "kind": "local-variable", - "name": "kws" - }, - { - "file": "internal/db/extras_test.go", - "line": 43, - "kind": "range-variable", - "name": "k" - }, - { - "file": "internal/db/extras_test.go", - "line": 58, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_test.go", - "line": 58, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/extras_test.go", - "line": 60, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_test.go", - "line": 62, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 62, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/extras_test.go", - "line": 69, - "kind": "function", - "name": "TestItemReplies_SetDelete" - }, - { - "file": "internal/db/extras_test.go", - "line": 70, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_test.go", - "line": 70, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/extras_test.go", - "line": 72, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_test.go", - "line": 73, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/extras_test.go", - "line": 83, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 83, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/extras_test.go", - "line": 96, - "kind": "local-variable", - "name": "all" - }, - { - "file": "internal/db/extras_test.go", - "line": 96, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 101, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 104, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 110, - "kind": "function", - "name": "TestDefaultReplies_GetAndRecord" - }, - { - "file": "internal/db/extras_test.go", - "line": 111, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_test.go", - "line": 111, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/extras_test.go", - "line": 113, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_test.go", - "line": 114, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/extras_test.go", - "line": 124, - "kind": "local-variable", - "name": "dr" - }, - { - "file": "internal/db/extras_test.go", - "line": 124, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 149, - "kind": "function", - "name": "TestNotifications_GetChannelAndAccountChannels" - }, - { - "file": "internal/db/extras_test.go", - "line": 150, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_test.go", - "line": 150, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/extras_test.go", - "line": 152, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_test.go", - "line": 153, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/extras_test.go", - "line": 153, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/extras_test.go", - "line": 160, - "kind": "local-variable", - "name": "chID" - }, - { - "file": "internal/db/extras_test.go", - "line": 170, - "kind": "local-variable", - "name": "channels" - }, - { - "file": "internal/db/extras_test.go", - "line": 170, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 187, - "kind": "function", - "name": "TestNotificationsRejectCrossUserBindings" - }, - { - "file": "internal/db/extras_test.go", - "line": 188, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_test.go", - "line": 188, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/extras_test.go", - "line": 190, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_test.go", - "line": 191, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/extras_test.go", - "line": 191, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/extras_test.go", - "line": 192, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 192, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/extras_test.go", - "line": 195, - "kind": "local-variable", - "name": "u2" - }, - { - "file": "internal/db/extras_test.go", - "line": 196, - "kind": "local-variable", - "name": "ownCh" - }, - { - "file": "internal/db/extras_test.go", - "line": 199, - "kind": "local-variable", - "name": "otherCh" - }, - { - "file": "internal/db/extras_test.go", - "line": 203, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 206, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 211, - "kind": "local-variable", - "name": "bindings" - }, - { - "file": "internal/db/extras_test.go", - "line": 211, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 218, - "kind": "local-variable", - "name": "channels" - }, - { - "file": "internal/db/extras_test.go", - "line": 218, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 229, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_test.go", - "line": 229, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/extras_test.go", - "line": 231, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_test.go", - "line": 243, - "kind": "local-variable", - "name": "all" - }, - { - "file": "internal/db/extras_test.go", - "line": 243, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 250, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/extras_test.go", - "line": 258, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_test.go", - "line": 258, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/extras_test.go", - "line": 260, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_test.go", - "line": 269, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 269, - "kind": "local-variable", - "name": "pub" - }, - { - "file": "internal/db/extras_test.go", - "line": 280, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/extras_test.go", - "line": 283, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/extras_test.go", - "line": 286, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/extras_test.go", - "line": 289, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/extras_test.go", - "line": 297, - "kind": "function", - "name": "TestCookies_DeleteAndStatuses" - }, - { - "file": "internal/db/extras_test.go", - "line": 298, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_test.go", - "line": 298, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/extras_test.go", - "line": 300, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_test.go", - "line": 301, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/extras_test.go", - "line": 304, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 304, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/db/extras_test.go", - "line": 317, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 320, - "kind": "local-variable", - "name": "details" - }, - { - "file": "internal/db/extras_test.go", - "line": 320, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 338, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 355, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 358, - "kind": "local-variable", - "name": "d" - }, - { - "file": "internal/db/extras_test.go", - "line": 369, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 376, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 379, - "kind": "var", - "name": "stale" - }, - { - "file": "internal/db/extras_test.go", - "line": 380, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 387, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_test.go", - "line": 387, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/extras_test.go", - "line": 389, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_test.go", - "line": 390, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/extras_test.go", - "line": 390, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/extras_test.go", - "line": 396, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/db/extras_test.go", - "line": 414, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_test.go", - "line": 414, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/extras_test.go", - "line": 416, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_test.go", - "line": 417, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/extras_test.go", - "line": 420, - "kind": "local-variable", - "name": "pd" - }, - { - "file": "internal/db/extras_test.go", - "line": 429, - "kind": "function", - "name": "TestCookies_SetPauseAndAutomaticExpiry" - }, - { - "file": "internal/db/extras_test.go", - "line": 430, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_test.go", - "line": 430, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/extras_test.go", - "line": 432, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/extras_test.go", - "line": 433, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/extras_test.go", - "line": 435, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 435, - "kind": "local-variable", - "name": "pausedUntil" - }, - { - "file": "internal/db/extras_test.go", - "line": 439, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 439, - "kind": "local-variable", - "name": "paused" - }, - { - "file": "internal/db/extras_test.go", - "line": 439, - "kind": "local-variable", - "name": "storedUntil" - }, - { - "file": "internal/db/extras_test.go", - "line": 443, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 449, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/extras_test.go", - "line": 449, - "kind": "local-variable", - "name": "until" - }, - { - "file": "internal/db/extras_test.go", - "line": 454, - "kind": "function", - "name": "TestCookiesGetStatusFailsClosedOnDatabaseError" - }, - { - "file": "internal/db/extras_test.go", - "line": 455, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/extras_test.go", - "line": 455, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/extras_test.go", - "line": 457, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 73, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 73, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 78, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 86, - "kind": "range-variable", - "name": "row" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 108, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 124, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 125, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 147, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 147, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 154, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 156, - "kind": "var", - "name": "batch" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 157, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 172, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 172, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 183, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 185, - "kind": "var", - "name": "batch" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 186, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 198, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 198, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 208, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 210, - "kind": "var", - "name": "r" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 211, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 225, - "kind": "local-variable", - "name": "statuses" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 229, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 229, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 239, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 241, - "kind": "var", - "name": "r" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 242, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 256, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 264, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 264, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 269, - "kind": "var", - "name": "status" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 269, - "kind": "var", - "name": "token" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 270, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 276, - "kind": "local-variable", - "name": "running" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 278, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 278, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 283, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 283, - "kind": "local-variable", - "name": "rowsErr" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 296, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 296, - "kind": "local-variable", - "name": "rowsErr" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 301, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 304, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 312, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 312, - "kind": "local-variable", - "name": "rowsErr" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 318, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 324, - "kind": "function", - "name": "FinalizeCanceled" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 325, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 325, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 337, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 337, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 341, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 344, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 363, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 363, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 368, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 368, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 374, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 374, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 378, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 381, - "kind": "var", - "name": "failed" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 381, - "kind": "var", - "name": "success" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 381, - "kind": "var", - "name": "total" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 381, - "kind": "var", - "name": "unfinished" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 382, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 392, - "kind": "local-variable", - "name": "status" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 403, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 409, - "kind": "function", - "name": "finalBatchStatus" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 422, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 422, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 427, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 427, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 433, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 433, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 437, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 440, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 446, - "kind": "function", - "name": "markUnfinishedFailedTx" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 447, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 453, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 459, - "kind": "function", - "name": "recountBatchTx" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 460, - "kind": "var", - "name": "failed" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 460, - "kind": "var", - "name": "success" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 460, - "kind": "var", - "name": "total" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 461, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 467, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 473, - "kind": "function", - "name": "Delete" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 474, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 474, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 478, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 484, - "kind": "function", - "name": "ExpiredUploads" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 488, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 488, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 497, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 499, - "kind": "var", - "name": "batch" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 500, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 510, - "kind": "function", - "name": "ClearUploadDir" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 511, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 517, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 525, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 525, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 530, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 530, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 538, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 538, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 554, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 562, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 562, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 568, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 568, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 575, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 575, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 581, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 581, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 587, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 587, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 593, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 593, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 599, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 599, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 604, - "kind": "var", - "name": "failed" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 604, - "kind": "var", - "name": "success" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 604, - "kind": "var", - "name": "total" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 604, - "kind": "var", - "name": "unfinished" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 605, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 616, - "kind": "local-variable", - "name": "status" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 617, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 617, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 623, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 623, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 627, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 635, - "kind": "var", - "name": "status" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 636, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 648, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 655, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 655, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 664, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 664, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 671, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 671, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 677, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 677, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 686, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 686, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 692, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 692, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 705, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 705, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 711, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 711, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 717, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 717, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 723, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 723, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 732, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 744, - "kind": "function", - "name": "MarkRowFailedKind" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 745, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 753, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 758, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 768, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 773, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 783, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 794, - "kind": "var", - "name": "failed" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 794, - "kind": "var", - "name": "success" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 794, - "kind": "var", - "name": "total" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 795, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches.go", - "line": 802, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 9, - "kind": "function", - "name": "TestFailClaimedBatchRequiresCurrentWorker" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 10, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 10, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 12, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 13, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 13, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 16, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 16, - "kind": "local-variable", - "name": "owner" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 20, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 25, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 25, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 28, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 28, - "kind": "local-variable", - "name": "released" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 31, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 31, - "kind": "local-variable", - "name": "released" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 34, - "kind": "local-variable", - "name": "batch" - }, - { - "file": "internal/db/item_publish_batches_lease_test.go", - "line": 34, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/migrate_test.go", - "line": 15, - "kind": "local-variable", - "name": "tmp" - }, - { - "file": "internal/db/migrate_test.go", - "line": 16, - "kind": "local-variable", - "name": "dbPath" - }, - { - "file": "internal/db/migrate_test.go", - "line": 18, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/migrate_test.go", - "line": 19, - "kind": "local-variable", - "name": "db" - }, - { - "file": "internal/db/migrate_test.go", - "line": 19, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/migrate_test.go", - "line": 25, - "kind": "local-variable", - "name": "checks" - }, - { - "file": "internal/db/migrate_test.go", - "line": 62, - "kind": "range-variable", - "name": "c" - }, - { - "file": "internal/db/migrate_test.go", - "line": 91, - "kind": "local-variable", - "name": "db2" - }, - { - "file": "internal/db/migrate_test.go", - "line": 91, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/migrate_test.go", - "line": 98, - "kind": "function", - "name": "columnExists" - }, - { - "file": "internal/db/migrate_test.go", - "line": 100, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/migrate_test.go", - "line": 100, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/migrate_test.go", - "line": 106, - "kind": "var", - "name": "name" - }, - { - "file": "internal/db/migrate_test.go", - "line": 107, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/migrate_test.go", - "line": 117, - "kind": "function", - "name": "TestLatestMigrationsDownUpSQLite" - }, - { - "file": "internal/db/migrate_test.go", - "line": 118, - "kind": "local-variable", - "name": "tmp" - }, - { - "file": "internal/db/migrate_test.go", - "line": 119, - "kind": "local-variable", - "name": "dbPath" - }, - { - "file": "internal/db/migrate_test.go", - "line": 120, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/migrate_test.go", - "line": 121, - "kind": "local-variable", - "name": "d" - }, - { - "file": "internal/db/migrate_test.go", - "line": 121, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/migrate_test.go", - "line": 127, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/migrate_test.go", - "line": 133, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/migrate_test.go", - "line": 161, - "kind": "range-variable", - "name": "table" - }, - { - "file": "internal/db/migrate_test.go", - "line": 167, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/migrate_test.go", - "line": 170, - "kind": "range-variable", - "name": "c" - }, - { - "file": "internal/db/migrate_test.go", - "line": 194, - "kind": "var", - "name": "val" - }, - { - "file": "internal/db/migrate_test.go", - "line": 195, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/migrate_test.go", - "line": 200, - "kind": "function", - "name": "tableExists" - }, - { - "file": "internal/db/migrate_test.go", - "line": 202, - "kind": "var", - "name": "name" - }, - { - "file": "internal/db/migrate_test.go", - "line": 203, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 47, - "kind": "local-variable", - "name": "targets" - }, - { - "file": "internal/db/multidb_test.go", - "line": 48, - "kind": "local-variable", - "name": "u" - }, - { - "file": "internal/db/multidb_test.go", - "line": 51, - "kind": "local-variable", - "name": "u" - }, - { - "file": "internal/db/multidb_test.go", - "line": 57, - "kind": "function", - "name": "sqliteTarget" - }, - { - "file": "internal/db/multidb_test.go", - "line": 59, - "kind": "local-variable", - "name": "dbPath" - }, - { - "file": "internal/db/multidb_test.go", - "line": 60, - "kind": "local-variable", - "name": "db" - }, - { - "file": "internal/db/multidb_test.go", - "line": 60, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 71, - "kind": "local-variable", - "name": "dsn" - }, - { - "file": "internal/db/multidb_test.go", - "line": 72, - "kind": "local-variable", - "name": "slash" - }, - { - "file": "internal/db/multidb_test.go", - "line": 76, - "kind": "local-variable", - "name": "baseDSN" - }, - { - "file": "internal/db/multidb_test.go", - "line": 78, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/db/multidb_test.go", - "line": 78, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 82, - "kind": "local-variable", - "name": "dbName" - }, - { - "file": "internal/db/multidb_test.go", - "line": 83, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 86, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 89, - "kind": "local-variable", - "name": "db" - }, - { - "file": "internal/db/multidb_test.go", - "line": 89, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 94, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/multidb_test.go", - "line": 106, - "kind": "local-variable", - "name": "rest" - }, - { - "file": "internal/db/multidb_test.go", - "line": 108, - "kind": "local-variable", - "name": "slash" - }, - { - "file": "internal/db/multidb_test.go", - "line": 112, - "kind": "local-variable", - "name": "server" - }, - { - "file": "internal/db/multidb_test.go", - "line": 114, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/db/multidb_test.go", - "line": 114, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 118, - "kind": "local-variable", - "name": "dbName" - }, - { - "file": "internal/db/multidb_test.go", - "line": 119, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 122, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 125, - "kind": "local-variable", - "name": "db" - }, - { - "file": "internal/db/multidb_test.go", - "line": 125, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 130, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/multidb_test.go", - "line": 140, - "kind": "range-variable", - "name": "tg" - }, - { - "file": "internal/db/multidb_test.go", - "line": 143, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/multidb_test.go", - "line": 144, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/multidb_test.go", - "line": 148, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 148, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/multidb_test.go", - "line": 151, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/multidb_test.go", - "line": 153, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/multidb_test.go", - "line": 154, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 161, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 161, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/db/multidb_test.go", - "line": 169, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 173, - "kind": "local-variable", - "name": "enabled" - }, - { - "file": "internal/db/multidb_test.go", - "line": 173, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 185, - "kind": "function", - "name": "TestMultiDB_ReliabilityStateAndSearch" - }, - { - "file": "internal/db/multidb_test.go", - "line": 186, - "kind": "range-variable", - "name": "tg" - }, - { - "file": "internal/db/multidb_test.go", - "line": 189, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/multidb_test.go", - "line": 190, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/multidb_test.go", - "line": 191, - "kind": "local-variable", - "name": "suffix" - }, - { - "file": "internal/db/multidb_test.go", - "line": 192, - "kind": "local-variable", - "name": "username" - }, - { - "file": "internal/db/multidb_test.go", - "line": 193, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 193, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/multidb_test.go", - "line": 196, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/multidb_test.go", - "line": 197, - "kind": "local-variable", - "name": "cookieID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 198, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 201, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 201, - "kind": "local-variable", - "name": "keywordID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 205, - "kind": "local-variable", - "name": "unchangedKeyword" - }, - { - "file": "internal/db/multidb_test.go", - "line": 206, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 209, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 212, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 212, - "kind": "local-variable", - "name": "paused" - }, - { - "file": "internal/db/multidb_test.go", - "line": 216, - "kind": "local-variable", - "name": "batchID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 217, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 222, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 222, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 225, - "kind": "local-variable", - "name": "batchRows" - }, - { - "file": "internal/db/multidb_test.go", - "line": 226, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 226, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 229, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 229, - "kind": "local-variable", - "name": "marked" - }, - { - "file": "internal/db/multidb_test.go", - "line": 232, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 232, - "kind": "local-variable", - "name": "finished" - }, - { - "file": "internal/db/multidb_test.go", - "line": 235, - "kind": "local-variable", - "name": "cancelBatchID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 236, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 241, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 241, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 244, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 244, - "kind": "local-variable", - "name": "running" - }, - { - "file": "internal/db/multidb_test.go", - "line": 244, - "kind": "local-variable", - "name": "token" - }, - { - "file": "internal/db/multidb_test.go", - "line": 247, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 247, - "kind": "local-variable", - "name": "finalized" - }, - { - "file": "internal/db/multidb_test.go", - "line": 251, - "kind": "local-variable", - "name": "uncertainBatchID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 252, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 257, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 257, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 260, - "kind": "local-variable", - "name": "uncertainRows" - }, - { - "file": "internal/db/multidb_test.go", - "line": 261, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 261, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 264, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 264, - "kind": "local-variable", - "name": "marked" - }, - { - "file": "internal/db/multidb_test.go", - "line": 267, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 267, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 275, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 275, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 281, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 281, - "kind": "local-variable", - "name": "runID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 281, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/db/multidb_test.go", - "line": 286, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 286, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/multidb_test.go", - "line": 289, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 292, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 295, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 295, - "kind": "local-variable", - "name": "runIssues" - }, - { - "file": "internal/db/multidb_test.go", - "line": 299, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 302, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 302, - "kind": "local-variable", - "name": "fencedRunID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 302, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/db/multidb_test.go", - "line": 307, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 310, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 310, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 313, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 313, - "kind": "local-variable", - "name": "fencedRun" - }, - { - "file": "internal/db/multidb_test.go", - "line": 317, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 320, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 323, - "kind": "local-variable", - "name": "deferred" - }, - { - "file": "internal/db/multidb_test.go", - "line": 324, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 328, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 331, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 331, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 335, - "kind": "local-variable", - "name": "itemID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 336, - "kind": "local-variable", - "name": "orderID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 337, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 340, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 343, - "kind": "local-variable", - "name": "empty" - }, - { - "file": "internal/db/multidb_test.go", - "line": 344, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 347, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 347, - "kind": "local-variable", - "name": "orders" - }, - { - "file": "internal/db/multidb_test.go", - "line": 347, - "kind": "local-variable", - "name": "total" - }, - { - "file": "internal/db/multidb_test.go", - "line": 355, - "kind": "function", - "name": "TestMultiDB_SettingsQuoteKey" - }, - { - "file": "internal/db/multidb_test.go", - "line": 356, - "kind": "range-variable", - "name": "tg" - }, - { - "file": "internal/db/multidb_test.go", - "line": 359, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/multidb_test.go", - "line": 360, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/multidb_test.go", - "line": 362, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 365, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 368, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/multidb_test.go", - "line": 371, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 371, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/multidb_test.go", - "line": 375, - "kind": "local-variable", - "name": "all" - }, - { - "file": "internal/db/multidb_test.go", - "line": 375, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 380, - "kind": "local-variable", - "name": "username" - }, - { - "file": "internal/db/multidb_test.go", - "line": 381, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 381, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/multidb_test.go", - "line": 384, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/multidb_test.go", - "line": 385, - "kind": "local-variable", - "name": "keyCol" - }, - { - "file": "internal/db/multidb_test.go", - "line": 386, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 395, - "kind": "var", - "name": "value" - }, - { - "file": "internal/db/multidb_test.go", - "line": 396, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 407, - "kind": "range-variable", - "name": "tg" - }, - { - "file": "internal/db/multidb_test.go", - "line": 410, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/multidb_test.go", - "line": 411, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/multidb_test.go", - "line": 413, - "kind": "local-variable", - "name": "oid" - }, - { - "file": "internal/db/multidb_test.go", - "line": 417, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/multidb_test.go", - "line": 418, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/multidb_test.go", - "line": 419, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 431, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 431, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/multidb_test.go", - "line": 469, - "kind": "range-variable", - "name": "tg" - }, - { - "file": "internal/db/multidb_test.go", - "line": 472, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/multidb_test.go", - "line": 473, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/multidb_test.go", - "line": 475, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/multidb_test.go", - "line": 479, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/multidb_test.go", - "line": 480, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 483, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 494, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 494, - "kind": "local-variable", - "name": "items" - }, - { - "file": "internal/db/multidb_test.go", - "line": 516, - "kind": "range-variable", - "name": "tg" - }, - { - "file": "internal/db/multidb_test.go", - "line": 519, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/multidb_test.go", - "line": 520, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/multidb_test.go", - "line": 522, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/multidb_test.go", - "line": 524, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/multidb_test.go", - "line": 525, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/multidb_test.go", - "line": 526, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 530, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 530, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 548, - "kind": "local-variable", - "name": "run" - }, - { - "file": "internal/db/multidb_test.go", - "line": 556, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 556, - "kind": "local-variable", - "name": "id1" - }, - { - "file": "internal/db/multidb_test.go", - "line": 556, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/db/multidb_test.go", - "line": 567, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 567, - "kind": "local-variable", - "name": "id3" - }, - { - "file": "internal/db/multidb_test.go", - "line": 567, - "kind": "local-variable", - "name": "started3" - }, - { - "file": "internal/db/multidb_test.go", - "line": 583, - "kind": "range-variable", - "name": "tg" - }, - { - "file": "internal/db/multidb_test.go", - "line": 586, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/multidb_test.go", - "line": 587, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/multidb_test.go", - "line": 588, - "kind": "local-variable", - "name": "suffix" - }, - { - "file": "internal/db/multidb_test.go", - "line": 589, - "kind": "local-variable", - "name": "username" - }, - { - "file": "internal/db/multidb_test.go", - "line": 590, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 590, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/multidb_test.go", - "line": 593, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/multidb_test.go", - "line": 594, - "kind": "local-variable", - "name": "cookieID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 595, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 599, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 605, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 605, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 609, - "kind": "local-variable", - "name": "before" - }, - { - "file": "internal/db/multidb_test.go", - "line": 610, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 614, - "kind": "local-variable", - "name": "intentionalDue" - }, - { - "file": "internal/db/multidb_test.go", - "line": 615, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 621, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 625, - "kind": "var", - "name": "credentialDue" - }, - { - "file": "internal/db/multidb_test.go", - "line": 625, - "kind": "var", - "name": "normalDue" - }, - { - "file": "internal/db/multidb_test.go", - "line": 626, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 629, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 642, - "kind": "function", - "name": "TestMultiDB_AutomationSafeCheckpointRetry" - }, - { - "file": "internal/db/multidb_test.go", - "line": 643, - "kind": "range-variable", - "name": "tg" - }, - { - "file": "internal/db/multidb_test.go", - "line": 646, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/multidb_test.go", - "line": 647, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/multidb_test.go", - "line": 648, - "kind": "local-variable", - "name": "suffix" - }, - { - "file": "internal/db/multidb_test.go", - "line": 649, - "kind": "local-variable", - "name": "username" - }, - { - "file": "internal/db/multidb_test.go", - "line": 650, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 650, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/multidb_test.go", - "line": 653, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/multidb_test.go", - "line": 654, - "kind": "local-variable", - "name": "cookieID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 655, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 658, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 658, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 665, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 665, - "kind": "local-variable", - "name": "runID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 665, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/db/multidb_test.go", - "line": 672, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 672, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/multidb_test.go", - "line": 675, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 678, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 678, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/multidb_test.go", - "line": 681, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 684, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 687, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 690, - "kind": "local-variable", - "name": "due" - }, - { - "file": "internal/db/multidb_test.go", - "line": 690, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 694, - "kind": "local-variable", - "name": "newLease" - }, - { - "file": "internal/db/multidb_test.go", - "line": 695, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 695, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 699, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 702, - "kind": "local-variable", - "name": "current" - }, - { - "file": "internal/db/multidb_test.go", - "line": 702, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 712, - "kind": "range-variable", - "name": "tg" - }, - { - "file": "internal/db/multidb_test.go", - "line": 715, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/multidb_test.go", - "line": 716, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/multidb_test.go", - "line": 718, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/multidb_test.go", - "line": 720, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/multidb_test.go", - "line": 721, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/multidb_test.go", - "line": 722, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 726, - "kind": "local-variable", - "name": "chID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 726, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 732, - "kind": "local-variable", - "name": "channels" - }, - { - "file": "internal/db/multidb_test.go", - "line": 736, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 739, - "kind": "local-variable", - "name": "bindings" - }, - { - "file": "internal/db/multidb_test.go", - "line": 751, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 754, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 754, - "kind": "local-variable", - "name": "messages" - }, - { - "file": "internal/db/multidb_test.go", - "line": 758, - "kind": "local-variable", - "name": "completed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 758, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 765, - "kind": "function", - "name": "TestMultiDB_LatestMigrationsDownUp" - }, - { - "file": "internal/db/multidb_test.go", - "line": 766, - "kind": "range-variable", - "name": "tg" - }, - { - "file": "internal/db/multidb_test.go", - "line": 769, - "kind": "local-variable", - "name": "gooseDialect" - }, - { - "file": "internal/db/multidb_test.go", - "line": 769, - "kind": "local-variable", - "name": "subdir" - }, - { - "file": "internal/db/multidb_test.go", - "line": 770, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 774, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/db/multidb_test.go", - "line": 775, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 797, - "kind": "range-variable", - "name": "table" - }, - { - "file": "internal/db/multidb_test.go", - "line": 803, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 806, - "kind": "range-variable", - "name": "c" - }, - { - "file": "internal/db/multidb_test.go", - "line": 839, - "kind": "function", - "name": "TestMultiDB_ChatAndAccountTasks" - }, - { - "file": "internal/db/multidb_test.go", - "line": 840, - "kind": "range-variable", - "name": "tg" - }, - { - "file": "internal/db/multidb_test.go", - "line": 843, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/multidb_test.go", - "line": 844, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/multidb_test.go", - "line": 845, - "kind": "local-variable", - "name": "suffix" - }, - { - "file": "internal/db/multidb_test.go", - "line": 846, - "kind": "local-variable", - "name": "username" - }, - { - "file": "internal/db/multidb_test.go", - "line": 847, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 847, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/multidb_test.go", - "line": 850, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/multidb_test.go", - "line": 851, - "kind": "local-variable", - "name": "cookieID" - }, - { - "file": "internal/db/multidb_test.go", - "line": 852, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 856, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 856, - "kind": "local-variable", - "name": "settings" - }, - { - "file": "internal/db/multidb_test.go", - "line": 864, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 867, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 867, - "kind": "local-variable", - "name": "stored" - }, - { - "file": "internal/db/multidb_test.go", - "line": 871, - "kind": "local-variable", - "name": "enabled" - }, - { - "file": "internal/db/multidb_test.go", - "line": 871, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 876, - "kind": "local-variable", - "name": "run" - }, - { - "file": "internal/db/multidb_test.go", - "line": 877, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 877, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 880, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 880, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 883, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 886, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 886, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 889, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 889, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 892, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 895, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/multidb_test.go", - "line": 895, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 899, - "kind": "local-variable", - "name": "session" - }, - { - "file": "internal/db/multidb_test.go", - "line": 900, - "kind": "local-variable", - "name": "incoming" - }, - { - "file": "internal/db/multidb_test.go", - "line": 901, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 901, - "kind": "local-variable", - "name": "inserted" - }, - { - "file": "internal/db/multidb_test.go", - "line": 904, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 904, - "kind": "local-variable", - "name": "inserted" - }, - { - "file": "internal/db/multidb_test.go", - "line": 907, - "kind": "local-variable", - "name": "outgoing" - }, - { - "file": "internal/db/multidb_test.go", - "line": 908, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 908, - "kind": "local-variable", - "name": "inserted" - }, - { - "file": "internal/db/multidb_test.go", - "line": 911, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 911, - "kind": "local-variable", - "name": "sessions" - }, - { - "file": "internal/db/multidb_test.go", - "line": 915, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 915, - "kind": "local-variable", - "name": "messages" - }, - { - "file": "internal/db/multidb_test.go", - "line": 919, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 932, - "kind": "range-variable", - "name": "tg" - }, - { - "file": "internal/db/multidb_test.go", - "line": 935, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/multidb_test.go", - "line": 936, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/multidb_test.go", - "line": 938, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/multidb_test.go", - "line": 940, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/multidb_test.go", - "line": 942, - "kind": "local-variable", - "name": "cf" - }, - { - "file": "internal/db/multidb_test.go", - "line": 949, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 949, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/db/multidb_test.go", - "line": 953, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 953, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/multidb_test.go", - "line": 973, - "kind": "range-variable", - "name": "tg" - }, - { - "file": "internal/db/multidb_test.go", - "line": 976, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/multidb_test.go", - "line": 977, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/multidb_test.go", - "line": 979, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/multidb_test.go", - "line": 981, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/multidb_test.go", - "line": 982, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/multidb_test.go", - "line": 983, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 986, - "kind": "local-variable", - "name": "oid" - }, - { - "file": "internal/db/multidb_test.go", - "line": 987, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 993, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 997, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 997, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1007, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1010, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1013, - "kind": "var", - "name": "shippedAt" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1014, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1029, - "kind": "function", - "name": "migrationTestSubdir" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1044, - "kind": "function", - "name": "columnExistsForDialect" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1046, - "kind": "var", - "name": "query" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1047, - "kind": "var", - "name": "args" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1050, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1050, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1056, - "kind": "var", - "name": "name" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1057, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1064, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1077, - "kind": "var", - "name": "count" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1078, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1084, - "kind": "function", - "name": "tableExistsForDialect" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1086, - "kind": "var", - "name": "query" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1087, - "kind": "var", - "name": "args" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1101, - "kind": "var", - "name": "count" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1102, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/multidb_test.go", - "line": 1108, - "kind": "function", - "name": "boolPtr" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 9, - "kind": "function", - "name": "TestNotificationOutboxLeaseFencesStaleWorker" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 10, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 10, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 12, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 13, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 13, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 16, - "kind": "local-variable", - "name": "owner" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 17, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 17, - "kind": "local-variable", - "name": "result" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 21, - "kind": "local-variable", - "name": "channelID" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 22, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 25, - "kind": "var", - "name": "lastError" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 25, - "kind": "var", - "name": "status" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 25, - "kind": "var", - "name": "workerToken" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 26, - "kind": "var", - "name": "attempts" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 27, - "kind": "var", - "name": "leaseExpiresAt" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 27, - "kind": "var", - "name": "nextAttemptAt" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 28, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 37, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 38, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 38, - "kind": "local-variable", - "name": "first" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 42, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 42, - "kind": "local-variable", - "name": "second" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 46, - "kind": "local-variable", - "name": "completed" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 46, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 49, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 49, - "kind": "local-variable", - "name": "retried" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 52, - "kind": "local-variable", - "name": "early" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 52, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 55, - "kind": "local-variable", - "name": "due" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 55, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 59, - "kind": "local-variable", - "name": "completed" - }, - { - "file": "internal/db/notification_outbox_test.go", - "line": 59, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 28, - "kind": "var", - "name": "exists" - }, - { - "file": "internal/db/notifications.go", - "line": 29, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 35, - "kind": "type", - "name": "NotificationOutboxInput" - }, - { - "file": "internal/db/notifications.go", - "line": 41, - "kind": "type", - "name": "NotificationOutboxMessage" - }, - { - "file": "internal/db/notifications.go", - "line": 65, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 65, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/notifications.go", - "line": 75, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/notifications.go", - "line": 77, - "kind": "var", - "name": "item" - }, - { - "file": "internal/db/notifications.go", - "line": 78, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/notifications.go", - "line": 79, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 91, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 94, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 103, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 110, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 118, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 118, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/notifications.go", - "line": 130, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/notifications.go", - "line": 132, - "kind": "var", - "name": "c" - }, - { - "file": "internal/db/notifications.go", - "line": 133, - "kind": "var", - "name": "userID" - }, - { - "file": "internal/db/notifications.go", - "line": 134, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 151, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 151, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/notifications.go", - "line": 156, - "kind": "range-variable", - "name": "message" - }, - { - "file": "internal/db/notifications.go", - "line": 157, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 173, - "kind": "local-variable", - "name": "nowUnix" - }, - { - "file": "internal/db/notifications.go", - "line": 174, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 174, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/notifications.go", - "line": 181, - "kind": "var", - "name": "candidates" - }, - { - "file": "internal/db/notifications.go", - "line": 183, - "kind": "var", - "name": "message" - }, - { - "file": "internal/db/notifications.go", - "line": 184, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 190, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 193, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/notifications.go", - "line": 194, - "kind": "local-variable", - "name": "leaseExpiresAt" - }, - { - "file": "internal/db/notifications.go", - "line": 195, - "kind": "range-variable", - "name": "message" - }, - { - "file": "internal/db/notifications.go", - "line": 196, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 196, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/notifications.go", - "line": 203, - "kind": "local-variable", - "name": "count" - }, - { - "file": "internal/db/notifications.go", - "line": 203, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 215, - "kind": "function", - "name": "CompleteOutbox" - }, - { - "file": "internal/db/notifications.go", - "line": 216, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 216, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/notifications.go", - "line": 220, - "kind": "local-variable", - "name": "count" - }, - { - "file": "internal/db/notifications.go", - "line": 220, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 224, - "kind": "function", - "name": "RetryOutbox" - }, - { - "file": "internal/db/notifications.go", - "line": 225, - "kind": "local-variable", - "name": "status" - }, - { - "file": "internal/db/notifications.go", - "line": 229, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/notifications.go", - "line": 229, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/notifications.go", - "line": 235, - "kind": "local-variable", - "name": "count" - }, - { - "file": "internal/db/notifications.go", - "line": 235, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders.go", - "line": 13, - "kind": "var", - "name": "orderAmountPattern" - }, - { - "file": "internal/db/orders.go", - "line": 14, - "kind": "var", - "name": "groupedOrderAmountPattern" - }, - { - "file": "internal/db/orders.go", - "line": 16, - "kind": "var", - "name": "ErrOrderConflict" - }, - { - "file": "internal/db/orders.go", - "line": 18, - "kind": "const", - "name": "maxOrderUpsertRetries" - }, - { - "file": "internal/db/orders.go", - "line": 63, - "kind": "type", - "name": "sqlExecer" - }, - { - "file": "internal/db/orders.go", - "line": 67, - "kind": "type", - "name": "sqlQueryExecer" - }, - { - "file": "internal/db/orders.go", - "line": 77, - "kind": "function", - "name": "PatchTx" - }, - { - "file": "internal/db/orders.go", - "line": 81, - "kind": "function", - "name": "patchOrder" - }, - { - "file": "internal/db/orders.go", - "line": 83, - "kind": "local-variable", - "name": "normalized" - }, - { - "file": "internal/db/orders.go", - "line": 83, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/orders.go", - "line": 89, - "kind": "local-variable", - "name": "set" - }, - { - "file": "internal/db/orders.go", - "line": 90, - "kind": "local-variable", - "name": "args" - }, - { - "file": "internal/db/orders.go", - "line": 91, - "kind": "local-variable", - "name": "addString" - }, - { - "file": "internal/db/orders.go", - "line": 118, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders.go", - "line": 135, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders.go", - "line": 135, - "kind": "local-variable", - "name": "result" - }, - { - "file": "internal/db/orders.go", - "line": 141, - "kind": "local-variable", - "name": "changed" - }, - { - "file": "internal/db/orders.go", - "line": 141, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders.go", - "line": 145, - "kind": "function", - "name": "upsertOrder" - }, - { - "file": "internal/db/orders.go", - "line": 151, - "kind": "local-variable", - "name": "normalized" - }, - { - "file": "internal/db/orders.go", - "line": 151, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/orders.go", - "line": 166, - "kind": "local-variable", - "name": "attempt" - }, - { - "file": "internal/db/orders.go", - "line": 167, - "kind": "var", - "name": "deletedAt" - }, - { - "file": "internal/db/orders.go", - "line": 167, - "kind": "var", - "name": "existingCookie" - }, - { - "file": "internal/db/orders.go", - "line": 167, - "kind": "var", - "name": "existingStatus" - }, - { - "file": "internal/db/orders.go", - "line": 168, - "kind": "var", - "name": "version" - }, - { - "file": "internal/db/orders.go", - "line": 169, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders.go", - "line": 178, - "kind": "local-variable", - "name": "current" - }, - { - "file": "internal/db/orders.go", - "line": 182, - "kind": "local-variable", - "name": "args" - }, - { - "file": "internal/db/orders.go", - "line": 182, - "kind": "local-variable", - "name": "set" - }, - { - "file": "internal/db/orders.go", - "line": 191, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders.go", - "line": 191, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/orders.go", - "line": 196, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/orders.go", - "line": 196, - "kind": "local-variable", - "name": "rowsErr" - }, - { - "file": "internal/db/orders.go", - "line": 207, - "kind": "function", - "name": "orderUpsertAssignments" - }, - { - "file": "internal/db/orders.go", - "line": 208, - "kind": "local-variable", - "name": "set" - }, - { - "file": "internal/db/orders.go", - "line": 209, - "kind": "local-variable", - "name": "args" - }, - { - "file": "internal/db/orders.go", - "line": 210, - "kind": "local-variable", - "name": "add" - }, - { - "file": "internal/db/orders.go", - "line": 257, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders.go", - "line": 257, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/db/orders.go", - "line": 272, - "kind": "local-variable", - "name": "early" - }, - { - "file": "internal/db/orders.go", - "line": 273, - "kind": "local-variable", - "name": "advanced" - }, - { - "file": "internal/db/orders.go", - "line": 304, - "kind": "var", - "name": "ord" - }, - { - "file": "internal/db/orders.go", - "line": 305, - "kind": "var", - "name": "isBargain" - }, - { - "file": "internal/db/orders.go", - "line": 305, - "kind": "var", - "name": "sysShipped" - }, - { - "file": "internal/db/orders.go", - "line": 305, - "kind": "var", - "name": "version" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "amount" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "buyerID" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "buyerReviewedAt" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "chatID" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "completedAt" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "cookieID" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "createdAt" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "itemID" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "lastReviewRequestAt" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "paidAt" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "qty" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "receiverAddr" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "receiverCity" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "receiverName" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "receiverPhone" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "shippedAt" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "specName" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "specValue" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "status" - }, - { - "file": "internal/db/orders.go", - "line": 306, - "kind": "var", - "name": "updatedAt" - }, - { - "file": "internal/db/orders.go", - "line": 307, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders.go", - "line": 351, - "kind": "function", - "name": "boolToInt" - }, - { - "file": "internal/db/orders.go", - "line": 358, - "kind": "function", - "name": "joinSet" - }, - { - "file": "internal/db/orders.go", - "line": 359, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/db/orders.go", - "line": 360, - "kind": "range-variable", - "name": "i" - }, - { - "file": "internal/db/orders.go", - "line": 360, - "kind": "range-variable", - "name": "p" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 9, - "kind": "function", - "name": "TestOrderUpsertConcurrentStatusNeverRegresses" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 10, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 10, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 12, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 13, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 16, - "kind": "local-variable", - "name": "owner" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 17, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 20, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 24, - "kind": "local-variable", - "name": "start" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 25, - "kind": "local-variable", - "name": "errCh" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 26, - "kind": "var", - "name": "wg" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 27, - "kind": "range-variable", - "name": "status" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 28, - "kind": "local-variable", - "name": "status" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 33, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 43, - "kind": "range-variable", - "name": "err" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 48, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 48, - "kind": "local-variable", - "name": "order" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 52, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 59, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 62, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_concurrency_test.go", - "line": 66, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 12, - "kind": "function", - "name": "TestOrdersByCookiePageScansBeyondLegacyLimit" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 13, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 13, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 15, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 16, - "kind": "local-variable", - "name": "cookieID" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 17, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 18, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 23, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 23, - "kind": "local-variable", - "name": "first" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 27, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 27, - "kind": "local-variable", - "name": "third" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 33, - "kind": "function", - "name": "TestOrdersSoftDeleteMissingForCookie" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 34, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 34, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 36, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 37, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 38, - "kind": "range-variable", - "name": "orderID" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 39, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 43, - "kind": "local-variable", - "name": "deleted" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 43, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 47, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 50, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 53, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 62, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 63, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 63, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 66, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 69, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 70, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 80, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 80, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 82, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 83, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 90, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 90, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 92, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 93, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 95, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 102, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 108, - "kind": "function", - "name": "TestOrdersUpsertNormalizesAndRejectsAmountsAtRepositoryBoundary" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 109, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 109, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 111, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 112, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 113, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 116, - "kind": "local-variable", - "name": "order" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 120, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 127, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 130, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 133, - "kind": "range-variable", - "name": "invalid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 134, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 140, - "kind": "function", - "name": "TestOrders_PatchCanExplicitlyClearFields" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 141, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 141, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 143, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 144, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 145, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 150, - "kind": "local-variable", - "name": "empty" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 151, - "kind": "local-variable", - "name": "shipped" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 152, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 155, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 155, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 164, - "kind": "function", - "name": "TestOrders_ListForUserSearchesAcrossJoinedFields" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 165, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 165, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 167, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 168, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 168, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 169, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 172, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 175, - "kind": "range-variable", - "name": "search" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 176, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 176, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 176, - "kind": "local-variable", - "name": "total" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 183, - "kind": "function", - "name": "TestOrders_UpsertRejectsCookieTakeover" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 184, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 184, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 186, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 187, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 187, - "kind": "local-variable", - "name": "userID" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 188, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 192, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 195, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 198, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 198, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 209, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 209, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 211, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 212, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 214, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 217, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 224, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 240, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 249, - "kind": "function", - "name": "TestOrdersUpsertDoesNotRegressAdvancedStatus" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 250, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 250, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 252, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 253, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 254, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 257, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 260, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 260, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 274, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 274, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 276, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 282, - "kind": "function", - "name": "TestOrders_ByCookieAndTitles" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 283, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 283, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 285, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 286, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 290, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 342, - "kind": "local-variable", - "name": "cases" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 349, - "kind": "range-variable", - "name": "in" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 349, - "kind": "range-variable", - "name": "want" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 350, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 358, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 358, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 360, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 361, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 363, - "kind": "local-variable", - "name": "cf" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 368, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 368, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 389, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 392, - "kind": "local-variable", - "name": "got2" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 399, - "kind": "local-variable", - "name": "all" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 399, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 412, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 415, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 422, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 422, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 424, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 432, - "kind": "function", - "name": "TestItems_GetAndFlags" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 433, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 433, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 435, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 436, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 450, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 455, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 455, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 472, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 472, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 474, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 475, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 484, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 485, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 501, - "kind": "local-variable", - "name": "second" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 505, - "kind": "local-variable", - "name": "third" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 515, - "kind": "function", - "name": "TestCards_RestoreBatchDataReturnsReservedValueToFront" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 516, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 516, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 518, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 519, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 520, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 520, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 526, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 526, - "kind": "local-variable", - "name": "reserved" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 530, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 533, - "kind": "local-variable", - "name": "again" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 533, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 541, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 541, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 543, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 544, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 551, - "kind": "local-variable", - "name": "cf" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 552, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 564, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 581, - "kind": "local-variable", - "name": "cases" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 593, - "kind": "range-variable", - "name": "c" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 594, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 599, - "kind": "range-variable", - "name": "i" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 619, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 619, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 621, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 622, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 629, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 629, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 631, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 633, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 637, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 643, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 656, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 656, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 658, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 660, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 662, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 665, - "kind": "local-variable", - "name": "exp" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 674, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 674, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 687, - "kind": "function", - "name": "TestSession_GetRejectsInactiveUser" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 688, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 688, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 690, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 692, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 693, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 693, - "kind": "local-variable", - "name": "sid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 697, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 700, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 709, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 709, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 711, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 715, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 715, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 719, - "kind": "local-variable", - "name": "byEmail" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 719, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 723, - "kind": "local-variable", - "name": "byID" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 723, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 731, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 731, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 733, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 734, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 737, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 740, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 743, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 750, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 750, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 752, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 753, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 753, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 762, - "kind": "function", - "name": "TestUsersCreatePropagatesDatabaseErrors" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 763, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 763, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 765, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 768, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 768, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 775, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 775, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 777, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 777, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 785, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 785, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 787, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 791, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 791, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 791, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 799, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 799, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 801, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 803, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 808, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 808, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 808, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 821, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 821, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 823, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 826, - "kind": "local-variable", - "name": "u1" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 830, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 838, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 845, - "kind": "local-variable", - "name": "renamed" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 859, - "kind": "local-variable", - "name": "ok2" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 874, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 874, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 876, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 883, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 883, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 885, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 886, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 894, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 894, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 913, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 913, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 915, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 916, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 926, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 942, - "kind": "var", - "name": "n" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 949, - "kind": "function", - "name": "TestWSMessages_AddBatchAndDeleteBefore" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 950, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 950, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 952, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 953, - "kind": "local-variable", - "name": "cid" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 955, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 961, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 967, - "kind": "local-variable", - "name": "deleted" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 967, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 974, - "kind": "var", - "name": "direction" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 974, - "kind": "var", - "name": "parseStatus" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 974, - "kind": "var", - "name": "rawText" - }, - { - "file": "internal/db/orders_delivery_test.go", - "line": 975, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 48, - "kind": "local-variable", - "name": "where" - }, - { - "file": "internal/db/orders_ext.go", - "line": 49, - "kind": "local-variable", - "name": "args" - }, - { - "file": "internal/db/orders_ext.go", - "line": 54, - "kind": "local-variable", - "name": "statuses" - }, - { - "file": "internal/db/orders_ext.go", - "line": 55, - "kind": "local-variable", - "name": "placeholders" - }, - { - "file": "internal/db/orders_ext.go", - "line": 56, - "kind": "range-variable", - "name": "st" - }, - { - "file": "internal/db/orders_ext.go", - "line": 62, - "kind": "local-variable", - "name": "search" - }, - { - "file": "internal/db/orders_ext.go", - "line": 63, - "kind": "local-variable", - "name": "pattern" - }, - { - "file": "internal/db/orders_ext.go", - "line": 67, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/db/orders_ext.go", - "line": 71, - "kind": "local-variable", - "name": "whereSQL" - }, - { - "file": "internal/db/orders_ext.go", - "line": 73, - "kind": "var", - "name": "total" - }, - { - "file": "internal/db/orders_ext.go", - "line": 74, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 83, - "kind": "local-variable", - "name": "queryArgs" - }, - { - "file": "internal/db/orders_ext.go", - "line": 85, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 85, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/orders_ext.go", - "line": 101, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/db/orders_ext.go", - "line": 103, - "kind": "var", - "name": "r" - }, - { - "file": "internal/db/orders_ext.go", - "line": 104, - "kind": "var", - "name": "amount" - }, - { - "file": "internal/db/orders_ext.go", - "line": 104, - "kind": "var", - "name": "buyerID" - }, - { - "file": "internal/db/orders_ext.go", - "line": 104, - "kind": "var", - "name": "itemDetail" - }, - { - "file": "internal/db/orders_ext.go", - "line": 104, - "kind": "var", - "name": "itemID" - }, - { - "file": "internal/db/orders_ext.go", - "line": 104, - "kind": "var", - "name": "itemTitle" - }, - { - "file": "internal/db/orders_ext.go", - "line": 104, - "kind": "var", - "name": "qty" - }, - { - "file": "internal/db/orders_ext.go", - "line": 104, - "kind": "var", - "name": "receiverAddr" - }, - { - "file": "internal/db/orders_ext.go", - "line": 104, - "kind": "var", - "name": "receiverCity" - }, - { - "file": "internal/db/orders_ext.go", - "line": 104, - "kind": "var", - "name": "receiverName" - }, - { - "file": "internal/db/orders_ext.go", - "line": 104, - "kind": "var", - "name": "receiverPhone" - }, - { - "file": "internal/db/orders_ext.go", - "line": 104, - "kind": "var", - "name": "specName" - }, - { - "file": "internal/db/orders_ext.go", - "line": 104, - "kind": "var", - "name": "specValue" - }, - { - "file": "internal/db/orders_ext.go", - "line": 105, - "kind": "var", - "name": "isBargain" - }, - { - "file": "internal/db/orders_ext.go", - "line": 105, - "kind": "var", - "name": "sysShipped" - }, - { - "file": "internal/db/orders_ext.go", - "line": 106, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 130, - "kind": "function", - "name": "normalizedStatusCandidates" - }, - { - "file": "internal/db/orders_ext.go", - "line": 171, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 171, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/orders_ext.go", - "line": 180, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/orders_ext.go", - "line": 182, - "kind": "var", - "name": "r" - }, - { - "file": "internal/db/orders_ext.go", - "line": 183, - "kind": "var", - "name": "amount" - }, - { - "file": "internal/db/orders_ext.go", - "line": 183, - "kind": "var", - "name": "buyerID" - }, - { - "file": "internal/db/orders_ext.go", - "line": 183, - "kind": "var", - "name": "itemID" - }, - { - "file": "internal/db/orders_ext.go", - "line": 183, - "kind": "var", - "name": "qty" - }, - { - "file": "internal/db/orders_ext.go", - "line": 183, - "kind": "var", - "name": "receiverAddr" - }, - { - "file": "internal/db/orders_ext.go", - "line": 183, - "kind": "var", - "name": "receiverCity" - }, - { - "file": "internal/db/orders_ext.go", - "line": 183, - "kind": "var", - "name": "receiverName" - }, - { - "file": "internal/db/orders_ext.go", - "line": 183, - "kind": "var", - "name": "receiverPhone" - }, - { - "file": "internal/db/orders_ext.go", - "line": 183, - "kind": "var", - "name": "specName" - }, - { - "file": "internal/db/orders_ext.go", - "line": 183, - "kind": "var", - "name": "specValue" - }, - { - "file": "internal/db/orders_ext.go", - "line": 184, - "kind": "var", - "name": "isBargain" - }, - { - "file": "internal/db/orders_ext.go", - "line": 184, - "kind": "var", - "name": "sysShipped" - }, - { - "file": "internal/db/orders_ext.go", - "line": 185, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 214, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 214, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/orders_ext.go", - "line": 219, - "kind": "local-variable", - "name": "orderIDs" - }, - { - "file": "internal/db/orders_ext.go", - "line": 221, - "kind": "var", - "name": "orderID" - }, - { - "file": "internal/db/orders_ext.go", - "line": 222, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 228, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 232, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 236, - "kind": "local-variable", - "name": "deleted" - }, - { - "file": "internal/db/orders_ext.go", - "line": 237, - "kind": "range-variable", - "name": "orderID" - }, - { - "file": "internal/db/orders_ext.go", - "line": 238, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/orders_ext.go", - "line": 241, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 241, - "kind": "local-variable", - "name": "result" - }, - { - "file": "internal/db/orders_ext.go", - "line": 247, - "kind": "local-variable", - "name": "changed" - }, - { - "file": "internal/db/orders_ext.go", - "line": 247, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 266, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/orders_ext.go", - "line": 266, - "kind": "local-variable", - "name": "t" - }, - { - "file": "internal/db/orders_ext.go", - "line": 277, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 277, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/orders_ext.go", - "line": 282, - "kind": "local-variable", - "name": "m" - }, - { - "file": "internal/db/orders_ext.go", - "line": 284, - "kind": "var", - "name": "id" - }, - { - "file": "internal/db/orders_ext.go", - "line": 284, - "kind": "var", - "name": "title" - }, - { - "file": "internal/db/orders_ext.go", - "line": 285, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 315, - "kind": "var", - "name": "exists" - }, - { - "file": "internal/db/orders_ext.go", - "line": 316, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 322, - "kind": "var", - "name": "cf" - }, - { - "file": "internal/db/orders_ext.go", - "line": 323, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/orders_ext.go", - "line": 323, - "kind": "var", - "name": "isMultiSpec" - }, - { - "file": "internal/db/orders_ext.go", - "line": 324, - "kind": "var", - "name": "apiCfg" - }, - { - "file": "internal/db/orders_ext.go", - "line": 324, - "kind": "var", - "name": "dataContent" - }, - { - "file": "internal/db/orders_ext.go", - "line": 324, - "kind": "var", - "name": "desc" - }, - { - "file": "internal/db/orders_ext.go", - "line": 324, - "kind": "var", - "name": "imageURL" - }, - { - "file": "internal/db/orders_ext.go", - "line": 324, - "kind": "var", - "name": "specName" - }, - { - "file": "internal/db/orders_ext.go", - "line": 324, - "kind": "var", - "name": "specValue" - }, - { - "file": "internal/db/orders_ext.go", - "line": 324, - "kind": "var", - "name": "textContent" - }, - { - "file": "internal/db/orders_ext.go", - "line": 325, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 351, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 351, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/orders_ext.go", - "line": 359, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/orders_ext.go", - "line": 361, - "kind": "var", - "name": "cf" - }, - { - "file": "internal/db/orders_ext.go", - "line": 362, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/orders_ext.go", - "line": 362, - "kind": "var", - "name": "isMultiSpec" - }, - { - "file": "internal/db/orders_ext.go", - "line": 363, - "kind": "var", - "name": "apiCfg" - }, - { - "file": "internal/db/orders_ext.go", - "line": 363, - "kind": "var", - "name": "dataContent" - }, - { - "file": "internal/db/orders_ext.go", - "line": 363, - "kind": "var", - "name": "desc" - }, - { - "file": "internal/db/orders_ext.go", - "line": 363, - "kind": "var", - "name": "imageURL" - }, - { - "file": "internal/db/orders_ext.go", - "line": 363, - "kind": "var", - "name": "specName" - }, - { - "file": "internal/db/orders_ext.go", - "line": 363, - "kind": "var", - "name": "specValue" - }, - { - "file": "internal/db/orders_ext.go", - "line": 363, - "kind": "var", - "name": "textContent" - }, - { - "file": "internal/db/orders_ext.go", - "line": 364, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 395, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 407, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/orders_ext.go", - "line": 411, - "kind": "function", - "name": "nullable" - }, - { - "file": "internal/db/password.go", - "line": 17, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/db/password.go", - "line": 17, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/password.go", - "line": 26, - "kind": "local-variable", - "name": "sum" - }, - { - "file": "internal/db/password.go", - "line": 48, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 17, - "kind": "function", - "name": "init" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 26, - "kind": "function", - "name": "Open" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 27, - "kind": "local-variable", - "name": "c" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 27, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 41, - "kind": "function", - "name": "ExecContext" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 42, - "kind": "local-variable", - "name": "ex" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 42, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 49, - "kind": "function", - "name": "QueryContext" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 50, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 50, - "kind": "local-variable", - "name": "qx" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 57, - "kind": "function", - "name": "PrepareContext" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 58, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 58, - "kind": "local-variable", - "name": "px" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 65, - "kind": "function", - "name": "BeginTx" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 66, - "kind": "local-variable", - "name": "bx" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 66, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 73, - "kind": "function", - "name": "Ping" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 74, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 74, - "kind": "local-variable", - "name": "p" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 80, - "kind": "function", - "name": "IsValid" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 81, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 81, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 87, - "kind": "function", - "name": "CheckNamedValue" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 88, - "kind": "local-variable", - "name": "nc" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 88, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 94, - "kind": "function", - "name": "ResetSession" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 95, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 95, - "kind": "local-variable", - "name": "rs" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 105, - "kind": "var", - "name": "b" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 107, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 108, - "kind": "local-variable", - "name": "inDouble" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 108, - "kind": "local-variable", - "name": "inSingle" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 109, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/db/pgx_compat.go", - "line": 110, - "kind": "local-variable", - "name": "ch" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 22, - "kind": "function", - "name": "TestPublishBatches_CreateGetRows" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 23, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 23, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 25, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 26, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 28, - "kind": "local-variable", - "name": "batch" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 29, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 34, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 63, - "kind": "local-variable", - "name": "r0" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 77, - "kind": "function", - "name": "TestPublishBatchesListAndRecoverInterrupted" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 78, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 78, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 80, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 81, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 82, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 87, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 90, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 90, - "kind": "local-variable", - "name": "listed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 94, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 94, - "kind": "local-variable", - "name": "recoverable" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 98, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 101, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 109, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 109, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 111, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 112, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 127, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 127, - "kind": "local-variable", - "name": "st" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 137, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 147, - "kind": "local-variable", - "name": "rowID" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 148, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 170, - "kind": "local-variable", - "name": "batch" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 189, - "kind": "local-variable", - "name": "pendingAfter" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 195, - "kind": "range-variable", - "name": "rr" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 204, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 204, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 206, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 207, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 207, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 211, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 211, - "kind": "local-variable", - "name": "pending" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 217, - "kind": "function", - "name": "TestPublishBatches_ClaimsAreAtomicAndLeaseCanBeRecovered" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 218, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 218, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 220, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 221, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 222, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 228, - "kind": "local-variable", - "name": "future" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 229, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 229, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 232, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 233, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 233, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 236, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 236, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 243, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 243, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 246, - "kind": "local-variable", - "name": "batch" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 246, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 254, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 254, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 257, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 257, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 260, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 260, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 263, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 263, - "kind": "local-variable", - "name": "marked" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 266, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 266, - "kind": "local-variable", - "name": "marked" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 269, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 269, - "kind": "local-variable", - "name": "finished" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 272, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 272, - "kind": "local-variable", - "name": "finished" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 277, - "kind": "function", - "name": "TestPublishBatches_ResetFailedKeepsValidationFailures" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 278, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 278, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 280, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 281, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 282, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 288, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 291, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 291, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 303, - "kind": "function", - "name": "TestPublishBatchLeaseTakeoverQuarantinesRemoteStartedRow" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 304, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 304, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 306, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 307, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 308, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 311, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 311, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 314, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 315, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 315, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 318, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 318, - "kind": "local-variable", - "name": "marked" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 322, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 322, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 329, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 329, - "kind": "local-variable", - "name": "pending" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 334, - "kind": "function", - "name": "TestPublishBatchCancelPreservesRemoteCheckpointBeforeFinalizing" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 335, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 335, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 337, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 338, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 339, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 342, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 342, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 345, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 346, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 346, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 349, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 349, - "kind": "local-variable", - "name": "running" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 349, - "kind": "local-variable", - "name": "token" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 353, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 353, - "kind": "local-variable", - "name": "saved" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 356, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 359, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 359, - "kind": "local-variable", - "name": "finalized" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 368, - "kind": "function", - "name": "TestFinalizeBatchRejectsUnfinishedRows" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 369, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 369, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 371, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 372, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 373, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 378, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 378, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 381, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 381, - "kind": "local-variable", - "name": "finalized" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 384, - "kind": "local-variable", - "name": "batch" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 388, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 389, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 389, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 392, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 392, - "kind": "local-variable", - "name": "marked" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 395, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 395, - "kind": "local-variable", - "name": "finalized" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 395, - "kind": "local-variable", - "name": "status" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 405, - "kind": "function", - "name": "TestExpiredCancelingBatchIsRecoverableAndFinalizedSafely" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 406, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 406, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 408, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 409, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 410, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 416, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 416, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 419, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 420, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 420, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 423, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 423, - "kind": "local-variable", - "name": "marked" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 426, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 426, - "kind": "local-variable", - "name": "running" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 429, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 429, - "kind": "local-variable", - "name": "recoverable" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 433, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 433, - "kind": "local-variable", - "name": "finalized" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 436, - "kind": "local-variable", - "name": "batch" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 449, - "kind": "function", - "name": "TestPublishBatchFinalizersFenceStaleWorker" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 450, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 450, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 452, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 453, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 456, - "kind": "local-variable", - "name": "batchID" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 457, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 460, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 460, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 463, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 464, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 464, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 467, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 467, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 470, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 470, - "kind": "local-variable", - "name": "running" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 470, - "kind": "local-variable", - "name": "token" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 474, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 474, - "kind": "local-variable", - "name": "finalized" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 481, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 481, - "kind": "local-variable", - "name": "finalized" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 487, - "kind": "local-variable", - "name": "batchID" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 488, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 491, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 491, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 494, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 494, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 497, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 497, - "kind": "local-variable", - "name": "finalized" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 500, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 504, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 504, - "kind": "local-variable", - "name": "finalized" - }, - { - "file": "internal/db/publish_batches_test.go", - "line": 504, - "kind": "local-variable", - "name": "status" - }, - { - "file": "internal/db/renewal.go", - "line": 63, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 63, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/renewal.go", - "line": 79, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 79, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/renewal.go", - "line": 94, - "kind": "function", - "name": "scanRenewalAccounts" - }, - { - "file": "internal/db/renewal.go", - "line": 95, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/renewal.go", - "line": 97, - "kind": "var", - "name": "a" - }, - { - "file": "internal/db/renewal.go", - "line": 98, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/renewal.go", - "line": 98, - "kind": "var", - "name": "showBrowser" - }, - { - "file": "internal/db/renewal.go", - "line": 99, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 104, - "kind": "var", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 130, - "kind": "local-variable", - "name": "encryptedCookie" - }, - { - "file": "internal/db/renewal.go", - "line": 130, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 134, - "kind": "local-variable", - "name": "encryptedMetadata" - }, - { - "file": "internal/db/renewal.go", - "line": 134, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 138, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 138, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/renewal.go", - "line": 146, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 146, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/renewal.go", - "line": 157, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 169, - "kind": "var", - "name": "s" - }, - { - "file": "internal/db/renewal.go", - "line": 170, - "kind": "var", - "name": "disabled" - }, - { - "file": "internal/db/renewal.go", - "line": 171, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 189, - "kind": "local-variable", - "name": "disabled" - }, - { - "file": "internal/db/renewal.go", - "line": 193, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 218, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 235, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 252, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 269, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 269, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/renewal.go", - "line": 276, - "kind": "local-variable", - "name": "statuses" - }, - { - "file": "internal/db/renewal.go", - "line": 278, - "kind": "var", - "name": "status" - }, - { - "file": "internal/db/renewal.go", - "line": 279, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 288, - "kind": "function", - "name": "CleanupLogs" - }, - { - "file": "internal/db/renewal.go", - "line": 292, - "kind": "local-variable", - "name": "cutoff" - }, - { - "file": "internal/db/renewal.go", - "line": 293, - "kind": "range-variable", - "name": "table" - }, - { - "file": "internal/db/renewal.go", - "line": 298, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 310, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 310, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/renewal.go", - "line": 317, - "kind": "var", - "name": "statuses" - }, - { - "file": "internal/db/renewal.go", - "line": 319, - "kind": "var", - "name": "status" - }, - { - "file": "internal/db/renewal.go", - "line": 320, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal.go", - "line": 328, - "kind": "function", - "name": "firstNonEmpty" - }, - { - "file": "internal/db/renewal.go", - "line": 329, - "kind": "range-variable", - "name": "v" - }, - { - "file": "internal/db/renewal_test.go", - "line": 10, - "kind": "function", - "name": "TestUpdateRenewalCookieEncryptsCookieAndMetadataAtRest" - }, - { - "file": "internal/db/renewal_test.go", - "line": 12, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/renewal_test.go", - "line": 12, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/renewal_test.go", - "line": 14, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/renewal_test.go", - "line": 15, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 15, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/renewal_test.go", - "line": 18, - "kind": "local-variable", - "name": "owner" - }, - { - "file": "internal/db/renewal_test.go", - "line": 19, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 22, - "kind": "local-variable", - "name": "metadata" - }, - { - "file": "internal/db/renewal_test.go", - "line": 23, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 27, - "kind": "var", - "name": "rawCookie" - }, - { - "file": "internal/db/renewal_test.go", - "line": 27, - "kind": "var", - "name": "rawMetadata" - }, - { - "file": "internal/db/renewal_test.go", - "line": 28, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 31, - "kind": "range-variable", - "name": "name" - }, - { - "file": "internal/db/renewal_test.go", - "line": 31, - "kind": "range-variable", - "name": "raw" - }, - { - "file": "internal/db/renewal_test.go", - "line": 36, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/db/renewal_test.go", - "line": 36, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 43, - "kind": "local-variable", - "name": "accounts" - }, - { - "file": "internal/db/renewal_test.go", - "line": 43, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 52, - "kind": "function", - "name": "TestUpdateRenewalCookieRejectsMissingAccount" - }, - { - "file": "internal/db/renewal_test.go", - "line": 53, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/renewal_test.go", - "line": 53, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/renewal_test.go", - "line": 55, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 61, - "kind": "function", - "name": "TestFlatCookieUpdateClearsSnapshotAndPreservesOtherMetadata" - }, - { - "file": "internal/db/renewal_test.go", - "line": 63, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/renewal_test.go", - "line": 63, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/renewal_test.go", - "line": 65, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/renewal_test.go", - "line": 66, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 66, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/renewal_test.go", - "line": 69, - "kind": "local-variable", - "name": "owner" - }, - { - "file": "internal/db/renewal_test.go", - "line": 70, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 73, - "kind": "local-variable", - "name": "metadata" - }, - { - "file": "internal/db/renewal_test.go", - "line": 74, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 77, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 80, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/db/renewal_test.go", - "line": 80, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 87, - "kind": "var", - "name": "rawMetadata" - }, - { - "file": "internal/db/renewal_test.go", - "line": 88, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 96, - "kind": "function", - "name": "TestEncryptLegacySecretsMigratesCookieMetadata" - }, - { - "file": "internal/db/renewal_test.go", - "line": 98, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/renewal_test.go", - "line": 98, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/renewal_test.go", - "line": 100, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/renewal_test.go", - "line": 101, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 101, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/renewal_test.go", - "line": 104, - "kind": "local-variable", - "name": "owner" - }, - { - "file": "internal/db/renewal_test.go", - "line": 105, - "kind": "local-variable", - "name": "metadata" - }, - { - "file": "internal/db/renewal_test.go", - "line": 106, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 111, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 114, - "kind": "var", - "name": "raw" - }, - { - "file": "internal/db/renewal_test.go", - "line": 115, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/renewal_test.go", - "line": 121, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/db/renewal_test.go", - "line": 121, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 63, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 63, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/reply.go", - "line": 70, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/reply.go", - "line": 72, - "kind": "var", - "name": "kw" - }, - { - "file": "internal/db/reply.go", - "line": 73, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 89, - "kind": "var", - "name": "dr" - }, - { - "file": "internal/db/reply.go", - "line": 90, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/reply.go", - "line": 90, - "kind": "var", - "name": "replyOnce" - }, - { - "file": "internal/db/reply.go", - "line": 91, - "kind": "var", - "name": "content" - }, - { - "file": "internal/db/reply.go", - "line": 91, - "kind": "var", - "name": "imageURL" - }, - { - "file": "internal/db/reply.go", - "line": 92, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 110, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 133, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 133, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/reply.go", - "line": 140, - "kind": "var", - "name": "out" - }, - { - "file": "internal/db/reply.go", - "line": 142, - "kind": "var", - "name": "item" - }, - { - "file": "internal/db/reply.go", - "line": 143, - "kind": "var", - "name": "enabled" - }, - { - "file": "internal/db/reply.go", - "line": 143, - "kind": "var", - "name": "replyOnce" - }, - { - "file": "internal/db/reply.go", - "line": 144, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 156, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 162, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 168, - "kind": "var", - "name": "n" - }, - { - "file": "internal/db/reply.go", - "line": 169, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 178, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/db/reply.go", - "line": 179, - "kind": "local-variable", - "name": "leaseExpiresAt" - }, - { - "file": "internal/db/reply.go", - "line": 180, - "kind": "local-variable", - "name": "query" - }, - { - "file": "internal/db/reply.go", - "line": 183, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 183, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/reply.go", - "line": 187, - "kind": "local-variable", - "name": "affected" - }, - { - "file": "internal/db/reply.go", - "line": 191, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 191, - "kind": "local-variable", - "name": "record" - }, - { - "file": "internal/db/reply.go", - "line": 208, - "kind": "local-variable", - "name": "affected" - }, - { - "file": "internal/db/reply.go", - "line": 214, - "kind": "var", - "name": "record" - }, - { - "file": "internal/db/reply.go", - "line": 215, - "kind": "var", - "name": "imageSent" - }, - { - "file": "internal/db/reply.go", - "line": 215, - "kind": "var", - "name": "textSent" - }, - { - "file": "internal/db/reply.go", - "line": 216, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 226, - "kind": "local-variable", - "name": "column" - }, - { - "file": "internal/db/reply.go", - "line": 235, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 240, - "kind": "function", - "name": "MarkRecordFailed" - }, - { - "file": "internal/db/reply.go", - "line": 241, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 246, - "kind": "function", - "name": "MarkRecordSent" - }, - { - "file": "internal/db/reply.go", - "line": 247, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 255, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply.go", - "line": 269, - "kind": "var", - "name": "ir" - }, - { - "file": "internal/db/reply.go", - "line": 270, - "kind": "var", - "name": "content" - }, - { - "file": "internal/db/reply.go", - "line": 271, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 10, - "kind": "function", - "name": "TestDefaultReplyClaimReclaimsExpiredPendingLease" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 11, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 12, - "kind": "local-variable", - "name": "database" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 12, - "kind": "local-variable", - "name": "dialect" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 12, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 17, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 19, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 19, - "kind": "local-variable", - "name": "result" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 23, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 23, - "kind": "local-variable", - "name": "userID" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 27, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 31, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 31, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 31, - "kind": "local-variable", - "name": "initial" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 43, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 43, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/reply_state_test.go", - "line": 43, - "kind": "local-variable", - "name": "reclaimed" - }, - { - "file": "internal/db/repository_test.go", - "line": 9, - "kind": "function", - "name": "newTestDB" - }, - { - "file": "internal/db/repository_test.go", - "line": 11, - "kind": "local-variable", - "name": "dbPath" - }, - { - "file": "internal/db/repository_test.go", - "line": 12, - "kind": "local-variable", - "name": "db" - }, - { - "file": "internal/db/repository_test.go", - "line": 12, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 16, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/repository_test.go", - "line": 22, - "kind": "local-variable", - "name": "legacy" - }, - { - "file": "internal/db/repository_test.go", - "line": 23, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 23, - "kind": "local-variable", - "name": "matched" - }, - { - "file": "internal/db/repository_test.go", - "line": 23, - "kind": "local-variable", - "name": "needsUpgrade" - }, - { - "file": "internal/db/repository_test.go", - "line": 27, - "kind": "local-variable", - "name": "matched2" - }, - { - "file": "internal/db/repository_test.go", - "line": 35, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 35, - "kind": "local-variable", - "name": "h" - }, - { - "file": "internal/db/repository_test.go", - "line": 39, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 39, - "kind": "local-variable", - "name": "matched" - }, - { - "file": "internal/db/repository_test.go", - "line": 39, - "kind": "local-variable", - "name": "needsUpgrade" - }, - { - "file": "internal/db/repository_test.go", - "line": 47, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/repository_test.go", - "line": 47, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/repository_test.go", - "line": 49, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/repository_test.go", - "line": 56, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 56, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/repository_test.go", - "line": 60, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 63, - "kind": "local-variable", - "name": "init" - }, - { - "file": "internal/db/repository_test.go", - "line": 84, - "kind": "local-variable", - "name": "okOld" - }, - { - "file": "internal/db/repository_test.go", - "line": 88, - "kind": "local-variable", - "name": "okNew" - }, - { - "file": "internal/db/repository_test.go", - "line": 96, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/repository_test.go", - "line": 96, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/repository_test.go", - "line": 98, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/repository_test.go", - "line": 101, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/repository_test.go", - "line": 103, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 103, - "kind": "local-variable", - "name": "sid" - }, - { - "file": "internal/db/repository_test.go", - "line": 107, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 107, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/db/repository_test.go", - "line": 111, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 114, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 121, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/repository_test.go", - "line": 121, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/repository_test.go", - "line": 123, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/repository_test.go", - "line": 125, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 132, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/db/repository_test.go", - "line": 133, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 136, - "kind": "local-variable", - "name": "d" - }, - { - "file": "internal/db/repository_test.go", - "line": 136, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 140, - "kind": "local-variable", - "name": "all" - }, - { - "file": "internal/db/repository_test.go", - "line": 144, - "kind": "local-variable", - "name": "pd" - }, - { - "file": "internal/db/repository_test.go", - "line": 147, - "kind": "local-variable", - "name": "enabled" - }, - { - "file": "internal/db/repository_test.go", - "line": 147, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 150, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 153, - "kind": "local-variable", - "name": "enabled" - }, - { - "file": "internal/db/repository_test.go", - "line": 153, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 158, - "kind": "function", - "name": "TestCookieLoginAudit" - }, - { - "file": "internal/db/repository_test.go", - "line": 159, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/repository_test.go", - "line": 159, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/db/repository_test.go", - "line": 161, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/repository_test.go", - "line": 163, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 166, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/db/repository_test.go", - "line": 167, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 170, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 173, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 176, - "kind": "local-variable", - "name": "d" - }, - { - "file": "internal/db/repository_test.go", - "line": 176, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 187, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 190, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 193, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/repository_test.go", - "line": 193, - "kind": "local-variable", - "name": "logs" - }, - { - "file": "internal/db/risk_control_logs.go", - "line": 36, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 18, - "kind": "const", - "name": "encryptedValuePrefix" - }, - { - "file": "internal/db/secrets.go", - "line": 19, - "kind": "const", - "name": "cookieMetadataScope" - }, - { - "file": "internal/db/secrets.go", - "line": 26, - "kind": "function", - "name": "secretCodecFromEnvironment" - }, - { - "file": "internal/db/secrets.go", - "line": 27, - "kind": "local-variable", - "name": "codec" - }, - { - "file": "internal/db/secrets.go", - "line": 31, - "kind": "function", - "name": "newSecretCodec" - }, - { - "file": "internal/db/secrets.go", - "line": 32, - "kind": "local-variable", - "name": "codec" - }, - { - "file": "internal/db/secrets.go", - "line": 36, - "kind": "local-variable", - "name": "digest" - }, - { - "file": "internal/db/secrets.go", - "line": 37, - "kind": "local-variable", - "name": "block" - }, - { - "file": "internal/db/secrets.go", - "line": 37, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 41, - "kind": "local-variable", - "name": "aead" - }, - { - "file": "internal/db/secrets.go", - "line": 41, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 49, - "kind": "function", - "name": "encrypt" - }, - { - "file": "internal/db/secrets.go", - "line": 54, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 62, - "kind": "local-variable", - "name": "nonce" - }, - { - "file": "internal/db/secrets.go", - "line": 63, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 66, - "kind": "local-variable", - "name": "sealed" - }, - { - "file": "internal/db/secrets.go", - "line": 76, - "kind": "local-variable", - "name": "codec" - }, - { - "file": "internal/db/secrets.go", - "line": 77, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 77, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/secrets.go", - "line": 83, - "kind": "type", - "name": "cookieSecret" - }, - { - "file": "internal/db/secrets.go", - "line": 84, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 84, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/secrets.go", - "line": 88, - "kind": "var", - "name": "cookies" - }, - { - "file": "internal/db/secrets.go", - "line": 90, - "kind": "var", - "name": "row" - }, - { - "file": "internal/db/secrets.go", - "line": 91, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 97, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 100, - "kind": "range-variable", - "name": "row" - }, - { - "file": "internal/db/secrets.go", - "line": 101, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 101, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/db/secrets.go", - "line": 105, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 105, - "kind": "local-variable", - "name": "password" - }, - { - "file": "internal/db/secrets.go", - "line": 109, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 109, - "kind": "local-variable", - "name": "metadata" - }, - { - "file": "internal/db/secrets.go", - "line": 114, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 120, - "kind": "type", - "name": "tokenSecret" - }, - { - "file": "internal/db/secrets.go", - "line": 125, - "kind": "var", - "name": "tokens" - }, - { - "file": "internal/db/secrets.go", - "line": 127, - "kind": "var", - "name": "row" - }, - { - "file": "internal/db/secrets.go", - "line": 128, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 134, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 137, - "kind": "range-variable", - "name": "row" - }, - { - "file": "internal/db/secrets.go", - "line": 138, - "kind": "local-variable", - "name": "deviceID" - }, - { - "file": "internal/db/secrets.go", - "line": 138, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 142, - "kind": "local-variable", - "name": "accessToken" - }, - { - "file": "internal/db/secrets.go", - "line": 142, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 147, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 153, - "kind": "local-variable", - "name": "keyCol" - }, - { - "file": "internal/db/secrets.go", - "line": 158, - "kind": "local-variable", - "name": "settings" - }, - { - "file": "internal/db/secrets.go", - "line": 160, - "kind": "var", - "name": "key" - }, - { - "file": "internal/db/secrets.go", - "line": 160, - "kind": "var", - "name": "value" - }, - { - "file": "internal/db/secrets.go", - "line": 161, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 169, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 172, - "kind": "range-variable", - "name": "key" - }, - { - "file": "internal/db/secrets.go", - "line": 172, - "kind": "range-variable", - "name": "value" - }, - { - "file": "internal/db/secrets.go", - "line": 173, - "kind": "local-variable", - "name": "encrypted" - }, - { - "file": "internal/db/secrets.go", - "line": 173, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 178, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 184, - "kind": "type", - "name": "channelSecret" - }, - { - "file": "internal/db/secrets.go", - "line": 192, - "kind": "var", - "name": "channels" - }, - { - "file": "internal/db/secrets.go", - "line": 194, - "kind": "var", - "name": "row" - }, - { - "file": "internal/db/secrets.go", - "line": 195, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 201, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 204, - "kind": "range-variable", - "name": "row" - }, - { - "file": "internal/db/secrets.go", - "line": 205, - "kind": "local-variable", - "name": "encrypted" - }, - { - "file": "internal/db/secrets.go", - "line": 205, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 210, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 219, - "kind": "function", - "name": "decrypt" - }, - { - "file": "internal/db/secrets.go", - "line": 226, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 226, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/db/secrets.go", - "line": 230, - "kind": "local-variable", - "name": "nonce" - }, - { - "file": "internal/db/secrets.go", - "line": 231, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets.go", - "line": 231, - "kind": "local-variable", - "name": "plain" - }, - { - "file": "internal/db/secrets.go", - "line": 238, - "kind": "function", - "name": "isSensitiveSettingKey" - }, - { - "file": "internal/db/secrets_test.go", - "line": 10, - "kind": "function", - "name": "TestSensitiveRepositoriesEncryptAtRestAndDecryptOnRead" - }, - { - "file": "internal/db/secrets_test.go", - "line": 12, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/secrets_test.go", - "line": 12, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/secrets_test.go", - "line": 14, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/secrets_test.go", - "line": 15, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 15, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/secrets_test.go", - "line": 18, - "kind": "local-variable", - "name": "owner" - }, - { - "file": "internal/db/secrets_test.go", - "line": 19, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 22, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 25, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 28, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 31, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 34, - "kind": "local-variable", - "name": "channelID" - }, - { - "file": "internal/db/secrets_test.go", - "line": 34, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 41, - "kind": "var", - "name": "rawCaptchaSecret" - }, - { - "file": "internal/db/secrets_test.go", - "line": 41, - "kind": "var", - "name": "rawConfig" - }, - { - "file": "internal/db/secrets_test.go", - "line": 41, - "kind": "var", - "name": "rawCookie" - }, - { - "file": "internal/db/secrets_test.go", - "line": 41, - "kind": "var", - "name": "rawDevice" - }, - { - "file": "internal/db/secrets_test.go", - "line": 41, - "kind": "var", - "name": "rawPassword" - }, - { - "file": "internal/db/secrets_test.go", - "line": 41, - "kind": "var", - "name": "rawSetting" - }, - { - "file": "internal/db/secrets_test.go", - "line": 41, - "kind": "var", - "name": "rawToken" - }, - { - "file": "internal/db/secrets_test.go", - "line": 42, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 45, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 48, - "kind": "local-variable", - "name": "keyCol" - }, - { - "file": "internal/db/secrets_test.go", - "line": 49, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 52, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 55, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 58, - "kind": "range-variable", - "name": "name" - }, - { - "file": "internal/db/secrets_test.go", - "line": 58, - "kind": "range-variable", - "name": "raw" - }, - { - "file": "internal/db/secrets_test.go", - "line": 64, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/db/secrets_test.go", - "line": 64, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 68, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 68, - "kind": "local-variable", - "name": "token" - }, - { - "file": "internal/db/secrets_test.go", - "line": 72, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 72, - "kind": "local-variable", - "name": "setting" - }, - { - "file": "internal/db/secrets_test.go", - "line": 75, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 75, - "kind": "local-variable", - "name": "setting" - }, - { - "file": "internal/db/secrets_test.go", - "line": 78, - "kind": "local-variable", - "name": "channel" - }, - { - "file": "internal/db/secrets_test.go", - "line": 78, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 84, - "kind": "function", - "name": "TestSecretCodecReadsLegacyPlaintextAndRejectsWrongKey" - }, - { - "file": "internal/db/secrets_test.go", - "line": 85, - "kind": "local-variable", - "name": "codec" - }, - { - "file": "internal/db/secrets_test.go", - "line": 86, - "kind": "local-variable", - "name": "encrypted" - }, - { - "file": "internal/db/secrets_test.go", - "line": 86, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 90, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 90, - "kind": "local-variable", - "name": "plain" - }, - { - "file": "internal/db/secrets_test.go", - "line": 93, - "kind": "local-variable", - "name": "wrong" - }, - { - "file": "internal/db/secrets_test.go", - "line": 94, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 97, - "kind": "local-variable", - "name": "withoutKey" - }, - { - "file": "internal/db/secrets_test.go", - "line": 98, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 103, - "kind": "function", - "name": "TestEncryptLegacySecretsUpgradesPlaintextAndValidatesKey" - }, - { - "file": "internal/db/secrets_test.go", - "line": 105, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/db/secrets_test.go", - "line": 105, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/db/secrets_test.go", - "line": 107, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/db/secrets_test.go", - "line": 108, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 108, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/db/secrets_test.go", - "line": 111, - "kind": "local-variable", - "name": "owner" - }, - { - "file": "internal/db/secrets_test.go", - "line": 112, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 115, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 118, - "kind": "var", - "name": "raw" - }, - { - "file": "internal/db/secrets_test.go", - "line": 119, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/secrets_test.go", - "line": 125, - "kind": "local-variable", - "name": "wrongCodec" - }, - { - "file": "internal/db/secrets_test.go", - "line": 126, - "kind": "local-variable", - "name": "wrongStore" - }, - { - "file": "internal/db/secrets_test.go", - "line": 128, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/sessions.go", - "line": 24, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/sessions.go", - "line": 24, - "kind": "local-variable", - "name": "sessionID" - }, - { - "file": "internal/db/sessions.go", - "line": 28, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/db/sessions.go", - "line": 29, - "kind": "local-variable", - "name": "expires" - }, - { - "file": "internal/db/sessions.go", - "line": 30, - "kind": "local-variable", - "name": "isAdmin" - }, - { - "file": "internal/db/sessions.go", - "line": 49, - "kind": "var", - "name": "sess" - }, - { - "file": "internal/db/sessions.go", - "line": 50, - "kind": "var", - "name": "isAdmin" - }, - { - "file": "internal/db/sessions.go", - "line": 51, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/sessions.go", - "line": 73, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/sessions.go", - "line": 79, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/sessions.go", - "line": 79, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/sessions.go", - "line": 83, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/sessions.go", - "line": 89, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/db/sessions.go", - "line": 90, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/store.go", - "line": 43, - "kind": "local-variable", - "name": "codec" - }, - { - "file": "internal/db/store.go", - "line": 78, - "kind": "function", - "name": "LockAccountCredentials" - }, - { - "file": "internal/db/store.go", - "line": 86, - "kind": "local-variable", - "name": "lock" - }, - { - "file": "internal/db/users.go", - "line": 31, - "kind": "var", - "name": "exists" - }, - { - "file": "internal/db/users.go", - "line": 32, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 48, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 48, - "kind": "local-variable", - "name": "hash" - }, - { - "file": "internal/db/users.go", - "line": 52, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 52, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/users.go", - "line": 61, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/users.go", - "line": 65, - "kind": "function", - "name": "isUniqueViolation" - }, - { - "file": "internal/db/users.go", - "line": 66, - "kind": "var", - "name": "mysqlErr" - }, - { - "file": "internal/db/users.go", - "line": 70, - "kind": "var", - "name": "pgErr" - }, - { - "file": "internal/db/users.go", - "line": 74, - "kind": "local-variable", - "name": "message" - }, - { - "file": "internal/db/users.go", - "line": 99, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 99, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/db/users.go", - "line": 109, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 109, - "kind": "local-variable", - "name": "matched" - }, - { - "file": "internal/db/users.go", - "line": 109, - "kind": "local-variable", - "name": "needsUpgrade" - }, - { - "file": "internal/db/users.go", - "line": 127, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 127, - "kind": "local-variable", - "name": "hash" - }, - { - "file": "internal/db/users.go", - "line": 131, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 131, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/users.go", - "line": 137, - "kind": "var", - "name": "userID" - }, - { - "file": "internal/db/users.go", - "line": 138, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 138, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/users.go", - "line": 144, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/db/users.go", - "line": 148, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 151, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 159, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 159, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/users.go", - "line": 165, - "kind": "var", - "name": "exists" - }, - { - "file": "internal/db/users.go", - "line": 166, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 174, - "kind": "var", - "name": "res" - }, - { - "file": "internal/db/users.go", - "line": 176, - "kind": "local-variable", - "name": "hash" - }, - { - "file": "internal/db/users.go", - "line": 176, - "kind": "local-variable", - "name": "hashErr" - }, - { - "file": "internal/db/users.go", - "line": 190, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/users.go", - "line": 193, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 201, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 201, - "kind": "local-variable", - "name": "tx" - }, - { - "file": "internal/db/users.go", - "line": 207, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 210, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 210, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/users.go", - "line": 214, - "kind": "var", - "name": "cookieIDs" - }, - { - "file": "internal/db/users.go", - "line": 216, - "kind": "var", - "name": "cookieID" - }, - { - "file": "internal/db/users.go", - "line": 217, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 223, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 232, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 236, - "kind": "range-variable", - "name": "cookieID" - }, - { - "file": "internal/db/users.go", - "line": 237, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 241, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 241, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/db/users.go", - "line": 245, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "internal/db/users.go", - "line": 253, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/users.go", - "line": 257, - "kind": "function", - "name": "scanUser" - }, - { - "file": "internal/db/users.go", - "line": 258, - "kind": "var", - "name": "usr" - }, - { - "file": "internal/db/users.go", - "line": 259, - "kind": "var", - "name": "isActive" - }, - { - "file": "internal/db/users.go", - "line": 259, - "kind": "var", - "name": "isAdmin" - }, - { - "file": "internal/db/users.go", - "line": 260, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/ws_message.go", - "line": 35, - "kind": "var", - "name": "query" - }, - { - "file": "internal/db/ws_message.go", - "line": 37, - "kind": "local-variable", - "name": "args" - }, - { - "file": "internal/db/ws_message.go", - "line": 38, - "kind": "range-variable", - "name": "i" - }, - { - "file": "internal/db/ws_message.go", - "line": 38, - "kind": "range-variable", - "name": "message" - }, - { - "file": "internal/db/ws_message.go", - "line": 53, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/ws_message.go", - "line": 59, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/db/ws_message.go", - "line": 59, - "kind": "local-variable", - "name": "result" - }, { "file": "internal/engine/account.go", "line": 61, diff --git a/docs/architecture/refactoring-master-plan.md b/docs/architecture/refactoring-master-plan.md index b8e8ff3..359cce9 100644 --- a/docs/architecture/refactoring-master-plan.md +++ b/docs/architecture/refactoring-master-plan.md @@ -628,3 +628,4 @@ npm --prefix frontend run build | 2026-08-15 | 完成阶段 10 第二个 PR 切片“前端 services/api.ts 注释基线清零” | 为 API 适配层全部导出函数、局部变量、请求参数和内联响应字段补齐中文注释,明确认证、账号、聊天、订单、商品、卡密、自动化、设置和通知接口的数据职责;增强注释检查器对调用参数、类型字面量和循环变量内联注释的识别能力,`services/api.ts` 注释基线清零;前端注释门禁、类型检查和 185 个测试通过并合并为一个可回滚提交 | 阶段 10:前端 components/hooks 注释基线按领域清零 | | 2026-08-15 | 完成阶段 10 第三个 PR 切片“前端 components/hooks 注释基线按领域清零” | 为账号、聊天、仪表盘、设置、规则、商品、卡密、订单、通知和二维码等组件、Hook、状态模块及其测试补齐函数、变量、回调和字段中文注释;补强注释检查器对箭头函数主体内联注释的识别,保持路由源码断言和 JSX 行为不变;目标目录注释基线清零,前端注释门禁、类型检查、185 个测试和生产构建通过并合并为一个可回滚提交 | 阶段 10:Go 核心领域注释基线按领域清零 | | 2026-08-15 | 完成阶段 10 第四个 PR 切片“Go internal/server 注释基线按领域清零” | 为 HTTP handlers、应用服务、事务边界、批量发布、登录/二维码、请求解析、测试辅助和错误处理代码补齐函数、变量、字段及常量中文注释;增强 Go 注释检查器对多行文档块与分组 const/var 注释的识别;`internal/server` 注释基线清零,Server 定向测试和 Go 注释门禁通过,合并为一个可回滚提交 | 阶段 10:继续清理 Go internal/db 与 internal/xianyu 领域注释基线 | +| 2026-08-15 | 完成阶段 10 第五个 PR 切片“Go internal/db 注释基线按领域清零” | 为数据库 Store、repository、迁移/方言、多数据库适配、凭证与订单数据访问及其测试补齐函数、变量、字段和常量中文注释;`internal/db` 注释基线清零;数据库定向测试、SQLite 迁移与 CRUD 验证、Go 注释门禁通过,合并为一个可回滚提交 | 阶段 10:继续清理 Go internal/xianyu 领域注释基线 | diff --git a/internal/db/account_login_logs.go b/internal/db/account_login_logs.go index f56e490..a68a2ed 100644 --- a/internal/db/account_login_logs.go +++ b/internal/db/account_login_logs.go @@ -21,6 +21,7 @@ func (l *AccountLoginLogs) Add(ctx context.Context, log AccountLoginLog) error { if log.ErrorMessage == "" { log.ErrorMessage = log.Message } + // err 保存err,供当前处理流程使用 _, err := l.DB.ExecContext(ctx, `INSERT INTO account_login_logs ( cookie_id, user_id, owner_id, account_pk, account_identifier, @@ -38,6 +39,7 @@ func (l *AccountLoginLogs) ListByCookie(ctx context.Context, cookieID string, li if limit <= 0 { limit = 20 } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := l.DB.QueryContext(ctx, `SELECT id, cookie_id, user_id, COALESCE(owner_id,0), COALESCE(account_pk,0), COALESCE(account_identifier,''), COALESCE(username,''), method, status, @@ -52,10 +54,13 @@ func (l *AccountLoginLogs) ListByCookie(ctx context.Context, cookieID string, li return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []AccountLoginLog for rows.Next() { + // log 保存log,供当前处理流程使用 var log AccountLoginLog - if err := rows.Scan( + if // err 保存err,供当前处理流程使用 + err := rows.Scan( &log.ID, &log.CookieID, &log.UserID, &log.OwnerID, &log.AccountPK, &log.AccountIdentifier, &log.Username, &log.Method, &log.Status, &log.Message, &log.TriggerReason, &log.FailureReason, &log.ErrorMessage, diff --git a/internal/db/account_tasks.go b/internal/db/account_tasks.go index dcae6bb..ea93b66 100644 --- a/internal/db/account_tasks.go +++ b/internal/db/account_tasks.go @@ -8,6 +8,7 @@ import ( "time" ) +// AccountTaskSettings 保存账号任务设置,供当前处理流程使用 type AccountTaskSettings struct { CookieID string `json:"account_id"` AutoRateEnabled bool `json:"auto_rate_enabled"` @@ -19,6 +20,7 @@ type AccountTaskSettings struct { LastPolishAt int64 `json:"last_polish_at"` } +// AccountTaskRun 保存账号任务运行,供当前处理流程使用 type AccountTaskRun struct { ID int64 `json:"id"` RunKey string `json:"run_key"` @@ -35,18 +37,24 @@ type AccountTaskRun struct { FinishedAt int64 `json:"finished_at"` } +// AccountTaskStore 保存账号任务Store,供当前处理流程使用 type AccountTaskStore struct { DB *sql.DB Dialect Dialect } +// defaultAccountTaskSettings 负责default账号任务设置相关处理。 func defaultAccountTaskSettings(cookieID string) AccountTaskSettings { return AccountTaskSettings{CookieID: cookieID, RateContent: "不错的买家,交易愉快", PolishTime: "03:00"} } +// Get 读取当前值。 func (s *AccountTaskStore) Get(ctx context.Context, cookieID string) (AccountTaskSettings, error) { + // result 保存结果,供当前处理流程使用 result := defaultAccountTaskSettings(cookieID) + // rateEnabled、polishEnabled 保存rateEnabled、polish启用状态,供当前处理流程使用 var rateEnabled, polishEnabled int + // err 保存err,供当前处理流程使用 err := s.DB.QueryRowContext(ctx, `SELECT auto_rate_enabled,rate_content,auto_polish_enabled,polish_time, last_rate_scan_at,last_polish_date,last_polish_at FROM account_task_settings WHERE cookie_id=?`, cookieID).Scan( &rateEnabled, &result.RateContent, &polishEnabled, &result.PolishTime, &result.LastRateScanAt, @@ -59,6 +67,7 @@ func (s *AccountTaskStore) Get(ctx context.Context, cookieID string) (AccountTas return result, err } +// Upsert 负责Upsert相关处理。 func (s *AccountTaskStore) Upsert(ctx context.Context, settings AccountTaskSettings) error { settings.RateContent = strings.TrimSpace(settings.RateContent) if settings.RateContent == "" { @@ -67,7 +76,9 @@ func (s *AccountTaskStore) Upsert(ctx context.Context, settings AccountTaskSetti if settings.PolishTime == "" { settings.PolishTime = "03:00" } + // now 保存now,供当前处理流程使用 now := time.Now().UTC().Unix() + // query 保存查询,供当前处理流程使用 query := `INSERT INTO account_task_settings (cookie_id,auto_rate_enabled,rate_content,auto_polish_enabled,polish_time,last_rate_scan_at,last_polish_date,last_polish_at,created_at,updated_at) VALUES(?,?,?,?,?,?,?,?,?,?)` + dialectUpsert(s.Dialect, []string{"cookie_id"}, map[string]string{ @@ -75,13 +86,16 @@ func (s *AccountTaskStore) Upsert(ctx context.Context, settings AccountTaskSetti "auto_polish_enabled": "EXCLUDED.auto_polish_enabled", "polish_time": "EXCLUDED.polish_time", "updated_at": "EXCLUDED.updated_at", }) + // err 保存err,供当前处理流程使用 _, err := s.DB.ExecContext(ctx, query, settings.CookieID, boolInt(settings.AutoRateEnabled), settings.RateContent, boolInt(settings.AutoPolishEnabled), settings.PolishTime, settings.LastRateScanAt, settings.LastPolishDate, settings.LastPolishAt, now, now) return err } +// Enabled 负责启用状态相关处理。 func (s *AccountTaskStore) Enabled(ctx context.Context) ([]AccountTaskSettings, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := s.DB.QueryContext(ctx, `SELECT s.cookie_id,s.auto_rate_enabled,s.rate_content,s.auto_polish_enabled,s.polish_time, s.last_rate_scan_at,s.last_polish_date,s.last_polish_at FROM account_task_settings s JOIN cookies c ON c.id=s.cookie_id @@ -90,11 +104,15 @@ func (s *AccountTaskStore) Enabled(ctx context.Context) ([]AccountTaskSettings, return nil, err } defer rows.Close() + // result 保存结果,供当前处理流程使用 var result []AccountTaskSettings for rows.Next() { + // row 保存row,供当前处理流程使用 var row AccountTaskSettings + // rate、polish 保存rate、polish,供当前处理流程使用 var rate, polish int - if err := rows.Scan(&row.CookieID, &rate, &row.RateContent, &polish, &row.PolishTime, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&row.CookieID, &rate, &row.RateContent, &polish, &row.PolishTime, &row.LastRateScanAt, &row.LastPolishDate, &row.LastPolishAt); err != nil { return nil, err } @@ -105,6 +123,7 @@ func (s *AccountTaskStore) Enabled(ctx context.Context) ([]AccountTaskSettings, } // ClaimRun creates a run or atomically reclaims a due failed run. +// ClaimRun 负责Claim运行相关处理。 func (s *AccountTaskStore) ClaimRun(ctx context.Context, run AccountTaskRun, now int64) (bool, error) { return s.claimRun(ctx, run, now, false) } @@ -112,25 +131,32 @@ func (s *AccountTaskStore) ClaimRun(ctx context.Context, run AccountTaskRun, now // ClaimRunImmediately creates a run or immediately reclaims a failed run. It is // intended for an explicit user retry; scheduled workers should keep using // ClaimRun so repeated platform failures still honor their retry delay. +// ClaimRunImmediately 负责Claim运行Immediately相关处理。 func (s *AccountTaskStore) ClaimRunImmediately(ctx context.Context, run AccountTaskRun, now int64) (bool, error) { return s.claimRun(ctx, run, now, true) } +// claimRun 负责claim运行相关处理。 func (s *AccountTaskStore) claimRun(ctx context.Context, run AccountTaskRun, now int64, immediate bool) (bool, error) { + // retryCondition 保存重试Condition,供当前处理流程使用 retryCondition := "next_retry_at<=?" + // args 保存args,供当前处理流程使用 args := []any{now, run.RunKey, now} if immediate { retryCondition = "1=1" args = args[:2] } + // res、err 保存res、err,供当前处理流程使用 res, err := s.DB.ExecContext(ctx, `UPDATE account_task_runs SET status='running',started_at=?,finished_at=0,error_message='' WHERE run_key=? AND status='failed' AND `+retryCondition, args...) if err != nil { return false, err } - if n, _ := res.RowsAffected(); n > 0 { + if // n 保存n,供当前处理流程使用 + n, _ := res.RowsAffected(); n > 0 { return true, nil } + // query 保存查询,供当前处理流程使用 query := dialectInsertIgnorePrefix(s.Dialect) + ` INTO account_task_runs (run_key,cookie_id,task_type,target_id,run_date,status,success_count,failed_count,error_message,next_retry_at,started_at,finished_at) VALUES(?,?,?,?,?,'running',0,0,'',0,?,0)` + dialectInsertIgnore(s.Dialect, []string{"run_key"}) @@ -138,40 +164,52 @@ func (s *AccountTaskStore) claimRun(ctx context.Context, run AccountTaskRun, now if err != nil { return false, err } + // n 保存n,供当前处理流程使用 n, _ := res.RowsAffected() return n > 0, nil } +// FinishRun 负责Finish运行相关处理。 func (s *AccountTaskStore) FinishRun(ctx context.Context, runKey, status string, success, failed int, message string, nextRetryAt int64) error { + // err 保存err,供当前处理流程使用 _, err := s.DB.ExecContext(ctx, `UPDATE account_task_runs SET status=?,success_count=?,failed_count=?,error_message=?,next_retry_at=?,finished_at=? WHERE run_key=?`, status, success, failed, message, nextRetryAt, time.Now().UTC().Unix(), runKey) return err } +// MarkRateScan 负责MarkRateScan相关处理。 func (s *AccountTaskStore) MarkRateScan(ctx context.Context, cookieID string, at int64) error { + // err 保存err,供当前处理流程使用 _, err := s.DB.ExecContext(ctx, `UPDATE account_task_settings SET last_rate_scan_at=?,updated_at=? WHERE cookie_id=?`, at, at, cookieID) return err } +// MarkPolished 负责MarkPolished相关处理。 func (s *AccountTaskStore) MarkPolished(ctx context.Context, cookieID, date string, at int64) error { + // err 保存err,供当前处理流程使用 _, err := s.DB.ExecContext(ctx, `UPDATE account_task_settings SET last_polish_date=?,last_polish_at=?,updated_at=? WHERE cookie_id=?`, date, at, at, cookieID) return err } +// RecentRuns 负责Recent运行记录相关处理。 func (s *AccountTaskStore) RecentRuns(ctx context.Context, cookieID string, limit int) ([]AccountTaskRun, error) { if limit <= 0 || limit > 100 { limit = 20 } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := s.DB.QueryContext(ctx, `SELECT id,run_key,cookie_id,task_type,target_id,run_date,status,success_count,failed_count, error_message,next_retry_at,started_at,finished_at FROM account_task_runs WHERE cookie_id=? ORDER BY id DESC LIMIT ?`, cookieID, limit) if err != nil { return nil, err } defer rows.Close() + // result 保存结果,供当前处理流程使用 var result []AccountTaskRun for rows.Next() { + // row 保存row,供当前处理流程使用 var row AccountTaskRun - if err := rows.Scan(&row.ID, &row.RunKey, &row.CookieID, &row.TaskType, &row.TargetID, &row.RunDate, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&row.ID, &row.RunKey, &row.CookieID, &row.TaskType, &row.TargetID, &row.RunDate, &row.Status, &row.SuccessCount, &row.FailedCount, &row.ErrorMessage, &row.NextRetryAt, &row.StartedAt, &row.FinishedAt); err != nil { return nil, err @@ -181,6 +219,7 @@ func (s *AccountTaskStore) RecentRuns(ctx context.Context, cookieID string, limi return result, rows.Err() } +// boolInt 负责boolInt相关处理。 func boolInt(v bool) int { if v { return 1 diff --git a/internal/db/account_tokens.go b/internal/db/account_tokens.go index c0c7c03..6b4947b 100644 --- a/internal/db/account_tokens.go +++ b/internal/db/account_tokens.go @@ -10,6 +10,7 @@ import ( // AccountToken 持久化最近一次页面运行实例的 device_id 和 token 请求元数据。 // accessToken 不用于后续 WebSocket 注册;官方消息页在每次 loginV2/reConnect // 前都会重新获取 token,页面重载后也会生成新的 device_id。 +// AccountToken 保存账号令牌,供当前处理流程使用 type AccountToken struct { CookieID string DeviceID string @@ -27,8 +28,10 @@ type AccountTokens struct { // Get 取账号缓存的 device_id + accessToken。无记录返回 ErrNotFound。 func (t *AccountTokens) Get(ctx context.Context, cookieID string) (AccountToken, error) { + // tk 保存tk,供当前处理流程使用 var tk AccountToken tk.CookieID = cookieID + // err 保存err,供当前处理流程使用 err := t.DB.QueryRowContext(ctx, `SELECT device_id, access_token, expire_at, cookie_fingerprint FROM account_tokens WHERE cookie_id=?`, cookieID).Scan(&tk.DeviceID, &tk.AccessToken, &tk.ExpireAt, &tk.CookieFingerprint) @@ -56,11 +59,14 @@ func (t *AccountTokens) Save(ctx context.Context, cookieID, deviceID, accessToke // SaveBound persists an access token together with the page-runtime device ID // and canonical Cookie state from which it was issued. +// SaveBound 保存Bound。 func (t *AccountTokens) SaveBound(ctx context.Context, cookieID, deviceID, accessToken string, expireAt int64, cookieFingerprint string) error { + // encryptedDeviceID、err 保存encryptedDeviceID、err,供当前处理流程使用 encryptedDeviceID, err := t.codec.encrypt("device-id", cookieID, deviceID) if err != nil { return err } + // encryptedToken、err 保存encryptedToken、err,供当前处理流程使用 encryptedToken, err := t.codec.encrypt("access-token", cookieID, accessToken) if err != nil { return err @@ -84,17 +90,20 @@ func (t *AccountTokens) SaveBound(ctx context.Context, cookieID, deviceID, acces // GetOrCreateDeviceID returns the permanent device ID for an account. The // candidate is persisted only when the account has no identity yet. +// GetOrCreateDeviceID 读取OrCreateDeviceID。 func (t *AccountTokens) GetOrCreateDeviceID(ctx context.Context, cookieID, candidate string) (string, error) { if candidate == "" { return "", fmt.Errorf("device_id 不能为空") } + // encryptedCandidate、err 保存encryptedCandidate、err,供当前处理流程使用 encryptedCandidate, err := t.codec.encrypt("device-id", cookieID, candidate) if err != nil { return "", err } // Insert-once makes concurrent account starts converge on the same identity. // A normal upsert can let two starters each observe a different winning ID. - if _, err := t.DB.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := t.DB.ExecContext(ctx, dialectInsertIgnorePrefix(t.Dialect)+` INTO account_tokens (cookie_id, device_id, access_token, expire_at, updated_at) VALUES (?, ?, '', 0, CURRENT_TIMESTAMP)`+dialectInsertIgnore(t.Dialect, []string{"cookie_id"}), cookieID, encryptedCandidate); err != nil { @@ -102,11 +111,13 @@ func (t *AccountTokens) GetOrCreateDeviceID(ctx context.Context, cookieID, candi } // Upgrade the only legacy state that had no identity. The conditional update // is also first-writer-wins under concurrent starts. - if _, err := t.DB.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := t.DB.ExecContext(ctx, `UPDATE account_tokens SET device_id=?, updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND device_id=''`, encryptedCandidate, cookieID); err != nil { return "", fmt.Errorf("补全 account_tokens device_id: %w", err) } + // tk、err 保存tk、err,供当前处理流程使用 tk, err := t.Get(ctx, cookieID) if err != nil { return "", err @@ -116,7 +127,9 @@ func (t *AccountTokens) GetOrCreateDeviceID(ctx context.Context, cookieID, candi // Clear clears only the expiring access token. The permanent device_id row is // retained across session expiry, login refresh, risk recovery and restarts. +// Clear 负责Clear相关处理。 func (t *AccountTokens) Clear(ctx context.Context, cookieID string) error { + // encryptedToken、err 保存encryptedToken、err,供当前处理流程使用 encryptedToken, err := t.codec.encrypt("access-token", cookieID, "") if err != nil { return err diff --git a/internal/db/account_tokens_test.go b/internal/db/account_tokens_test.go index c4b70d8..bc18bdd 100644 --- a/internal/db/account_tokens_test.go +++ b/internal/db/account_tokens_test.go @@ -10,14 +10,18 @@ import ( // TestAccountTokens_CRUD 覆盖 account_tokens 的 Get/Save(upsert)/Clear。 func TestAccountTokens_CRUD(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() // 前置:admin 用户 + cookie 行(account_tokens 有 FK→cookies)。 store.Users.Create(ctx, "admin", "a@e.com", "pw") + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") - if err := store.Cookies.Save(ctx, "cid", "unb=1; _m_h5_tk=t;", admin.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.Save(ctx, "cid", "unb=1; _m_h5_tk=t;", admin.ID); err != nil { t.Fatalf("Save cookie: %v", err) } @@ -28,9 +32,11 @@ func TestAccountTokens_CRUD(t *testing.T) { // SaveBound(首次写入)。 expire := time.Now().Add(time.Hour).Unix() - if err := store.Tokens.SaveBound(ctx, "cid", "dev-1", "tok-1", expire, "cookie-hash-1"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Tokens.SaveBound(ctx, "cid", "dev-1", "tok-1", expire, "cookie-hash-1"); err != nil { t.Fatalf("Save: %v", err) } + // tk、err 保存tk、err,供当前处理流程使用 tk, err := store.Tokens.Get(ctx, "cid") if err != nil { t.Fatalf("Get: %v", err) @@ -63,49 +69,69 @@ func TestAccountTokens_CRUD(t *testing.T) { } } +// TestAccountTokens_SaveTracksLatestRuntimeDeviceID 负责Test账号TokensSaveTracksLatestRuntimeDeviceID相关处理。 func TestAccountTokens_SaveTracksLatestRuntimeDeviceID(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() store.Users.Create(ctx, "admin", "a@e.com", "pw") + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") - if err := store.Cookies.Save(ctx, "cid", "unb=1; _m_h5_tk=t;", admin.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.Save(ctx, "cid", "unb=1; _m_h5_tk=t;", admin.ID); err != nil { t.Fatal(err) } + // first、err 保存first、err,供当前处理流程使用 first, err := store.Tokens.GetOrCreateDeviceID(ctx, "cid", "device-first") if err != nil { t.Fatal(err) } - if err := store.Tokens.Save(ctx, "cid", "device-replacement", "token", time.Now().Add(time.Hour).Unix()); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Tokens.Save(ctx, "cid", "device-replacement", "token", time.Now().Add(time.Hour).Unix()); err != nil { t.Fatal(err) } - if err := store.Tokens.Clear(ctx, "cid"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Tokens.Clear(ctx, "cid"); err != nil { t.Fatal(err) } + // afterRestart、err 保存afterRestart、err,供当前处理流程使用 afterRestart, err := store.Tokens.GetOrCreateDeviceID(ctx, "cid", "device-after-restart") if err != nil || first != "device-first" || afterRestart != "device-replacement" { t.Fatalf("未保留最近一次运行时 device ID: first=%q after=%q err=%v", first, afterRestart, err) } } +// TestAccountTokens_ConcurrentDeviceIDCreationConverges 负责Test账号TokensConcurrentDeviceIDCreationConverges相关处理。 func TestAccountTokens_ConcurrentDeviceIDCreationConverges(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() store.Users.Create(ctx, "admin", "a@e.com", "pw") + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") - if err := store.Cookies.Save(ctx, "cid", "unb=1; _m_h5_tk=t;", admin.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.Save(ctx, "cid", "unb=1; _m_h5_tk=t;", admin.ID); err != nil { t.Fatal(err) } + // workers 保存workers,供当前处理流程使用 const workers = 12 + // results 保存results,供当前处理流程使用 results := make(chan string, workers) + // errs 保存errs,供当前处理流程使用 errs := make(chan error, workers) + // wg 保存wg,供当前处理流程使用 var wg sync.WaitGroup - for i := 0; i < workers; i++ { + for // i 保存i,供当前处理流程使用 + i := 0; i < workers; i++ { wg.Add(1) go func(i int) { defer wg.Done() + // deviceID、err 保存deviceID、err,供当前处理流程使用 deviceID, err := store.Tokens.GetOrCreateDeviceID(ctx, "cid", fmt.Sprintf("device-%d", i)) if err != nil { errs <- err @@ -117,10 +143,13 @@ func TestAccountTokens_ConcurrentDeviceIDCreationConverges(t *testing.T) { wg.Wait() close(results) close(errs) + // err 表示当前遍历过程中的err for err := range errs { t.Fatal(err) } + // permanent 保存permanent,供当前处理流程使用 var permanent string + // deviceID 表示当前遍历过程中的deviceID for deviceID := range results { if permanent == "" { permanent = deviceID @@ -129,6 +158,7 @@ func TestAccountTokens_ConcurrentDeviceIDCreationConverges(t *testing.T) { t.Fatalf("concurrent device IDs diverged: first=%q got=%q", permanent, deviceID) } } + // stored、err 保存stored、err,供当前处理流程使用 stored, err := store.Tokens.Get(ctx, "cid") if err != nil || stored.DeviceID != permanent { t.Fatalf("stored=%+v permanent=%q err=%v", stored, permanent, err) diff --git a/internal/db/ai_reply.go b/internal/db/ai_reply.go index 1d9e6d9..f06f053 100644 --- a/internal/db/ai_reply.go +++ b/internal/db/ai_reply.go @@ -36,9 +36,13 @@ type AIReply struct { // Get 取某账号 AI 回复配置。 func (a *AIReply) Get(ctx context.Context, cookieID string) (*AIReplySettings, error) { + // s 保存s,供当前处理流程使用 var s AIReplySettings + // enabled 保存启用状态,供当前处理流程使用 var enabled int + // apiKey、customPrompts 保存apiKey、customPrompts,供当前处理流程使用 var apiKey, customPrompts sql.NullString + // err 保存err,供当前处理流程使用 err := a.DB.QueryRowContext(ctx, `SELECT cookie_id, ai_enabled, COALESCE(model_name, ''), COALESCE(api_key, ''), COALESCE(base_url, ''), max_discount_percent, max_discount_amount, max_bargain_rounds, custom_prompts @@ -68,6 +72,7 @@ func (a *AIReply) Get(ctx context.Context, cookieID string) (*AIReplySettings, e // ListForUser 查询用户账号的 AI 回复配置,不读取或返回 API 密钥。 func (a *AIReply) ListForUser(ctx context.Context, userID int64) ([]AIReplySettings, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := a.DB.QueryContext(ctx, ` SELECT a.cookie_id, a.ai_enabled, a.max_discount_percent, a.max_discount_amount, a.max_bargain_rounds, COALESCE(a.custom_prompts, '') @@ -76,11 +81,15 @@ func (a *AIReply) ListForUser(ctx context.Context, userID int64) ([]AIReplySetti return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []AIReplySettings for rows.Next() { + // item 保存商品,供当前处理流程使用 var item AIReplySettings + // enabled 保存启用状态,供当前处理流程使用 var enabled int - if err := rows.Scan(&item.CookieID, &enabled, &item.MaxDiscountPercent, &item.MaxDiscountAmount, &item.MaxBargainRounds, &item.CustomPrompts); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&item.CookieID, &enabled, &item.MaxDiscountPercent, &item.MaxDiscountAmount, &item.MaxBargainRounds, &item.CustomPrompts); err != nil { return nil, err } item.AIEnabled = enabled != 0 @@ -91,6 +100,7 @@ func (a *AIReply) ListForUser(ctx context.Context, userID int64) ([]AIReplySetti // UpsertSettings 保存指定账号的 AI 回复开关和砍价约束。 func (a *AIReply) UpsertSettings(ctx context.Context, cookieID string, settings AIReplySettings) error { + // err 保存err,供当前处理流程使用 _, err := a.DB.ExecContext(ctx, `INSERT INTO ai_reply_settings (cookie_id, ai_enabled, max_discount_percent, max_discount_amount, @@ -120,6 +130,7 @@ func (a *AIReply) ConversationHistory(ctx context.Context, cookieID, chatID, ite if limit <= 0 || limit > 20 { limit = 10 } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := a.DB.QueryContext(ctx, ` SELECT role, content, COALESCE(intent,''), COALESCE(bargain_count,0) FROM ai_conversations @@ -129,18 +140,24 @@ func (a *AIReply) ConversationHistory(ctx context.Context, cookieID, chatID, ite return nil, err } defer rows.Close() + // reversed 保存reversed,供当前处理流程使用 var reversed []AIConversationMessage for rows.Next() { + // message 保存消息,供当前处理流程使用 var message AIConversationMessage - if err := rows.Scan(&message.Role, &message.Content, &message.Intent, &message.BargainCount); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&message.Role, &message.Content, &message.Intent, &message.BargainCount); err != nil { return nil, err } reversed = append(reversed, message) } - if err := rows.Err(); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Err(); err != nil { return nil, err } + // result 保存结果,供当前处理流程使用 result := make([]AIConversationMessage, len(reversed)) + // i 表示当前遍历过程中的i for i := range reversed { result[len(reversed)-1-i] = reversed[i] } @@ -149,7 +166,9 @@ func (a *AIReply) ConversationHistory(ctx context.Context, cookieID, chatID, ite // CurrentBargainCount 返回会话目前的砍价轮次。 func (a *AIReply) CurrentBargainCount(ctx context.Context, cookieID, chatID, itemID string) (int, error) { + // count 保存数量,供当前处理流程使用 var count int + // err 保存err,供当前处理流程使用 err := a.DB.QueryRowContext(ctx, ` SELECT COALESCE(MAX(bargain_count),0) FROM ai_conversations WHERE cookie_id=? AND chat_id=? AND item_id=?`, cookieID, chatID, itemID).Scan(&count) @@ -158,6 +177,7 @@ func (a *AIReply) CurrentBargainCount(ctx context.Context, cookieID, chatID, ite // AddConversation 追加一条会话消息。 func (a *AIReply) AddConversation(ctx context.Context, cookieID, chatID, userID, itemID string, message AIConversationMessage) error { + // err 保存err,供当前处理流程使用 _, err := a.DB.ExecContext(ctx, ` INSERT INTO ai_conversations (cookie_id,chat_id,user_id,item_id,role,content,intent,bargain_count) VALUES (?,?,?,?,?,?,?,?)`, cookieID, chatID, userID, itemID, message.Role, message.Content, message.Intent, message.BargainCount) @@ -166,17 +186,22 @@ func (a *AIReply) AddConversation(ctx context.Context, cookieID, chatID, userID, // AddConversationExchange 原子保存一轮用户消息与 AI 回复,避免上游调用失败时 // 留下半轮历史并错误消耗砍价轮次。 +// AddConversationExchange 新增ConversationExchange。 func (a *AIReply) AddConversationExchange(ctx context.Context, cookieID, chatID, userID, itemID string, userMessage, assistantMessage AIConversationMessage) error { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := a.DB.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() + // query 保存查询,供当前处理流程使用 query := `INSERT INTO ai_conversations (cookie_id,chat_id,user_id,item_id,role,content,intent,bargain_count) VALUES (?,?,?,?,?,?,?,?)` + // message 表示当前遍历过程中的消息 for _, message := range []AIConversationMessage{userMessage, assistantMessage} { - if _, err := tx.ExecContext(ctx, query, cookieID, chatID, userID, itemID, message.Role, message.Content, message.Intent, message.BargainCount); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, query, cookieID, chatID, userID, itemID, message.Role, message.Content, message.Intent, message.BargainCount); err != nil { return err } } diff --git a/internal/db/automation.go b/internal/db/automation.go index 072572b..0c67717 100644 --- a/internal/db/automation.go +++ b/internal/db/automation.go @@ -10,6 +10,7 @@ import ( "time" ) +// ErrAutomationRunActive 保存Err自动化运行Active,供当前处理流程使用 var ErrAutomationRunActive = errors.New("规则仍有待处理的自动化运行") // SafeRetryErrorPrefix 标记当前动作明确没有产生外部副作用,可以从动作游标安全恢复。 @@ -19,6 +20,7 @@ const SafeRetryErrorPrefix = "[safe_retry]" // // 自动化中心不区分触发来源:WS 系统事件、计划任务、后台手动触发都通过 // trigger_type + action 编排表达;真正的防重由 automation_runs.trigger_key 保证。 +// AutomationRules 保存自动化规则列表,供当前处理流程使用 type AutomationRules struct { DB *sql.DB Dialect Dialect @@ -26,7 +28,9 @@ type AutomationRules struct { // ExistsPublishRule 判断指定发布自动化规则是否已经存在,避免重复创建同一规则。 func (a *AutomationRules) ExistsPublishRule(ctx context.Context, input AutomationRuleInput) (bool, error) { + // exists 保存exists,供当前处理流程使用 var exists bool + // err 保存err,供当前处理流程使用 err := a.DB.QueryRowContext(ctx, `SELECT EXISTS( SELECT 1 FROM automation_rules WHERE user_id=? AND cookie_id=? AND item_id=? AND trigger_type=? AND name=? AND deleted_at IS NULL @@ -36,6 +40,7 @@ func (a *AutomationRules) ExistsPublishRule(ctx context.Context, input Automatio // AutomationRule 是一条自动化规则。规则只描述“什么时候、对哪个商品生效”, // 具体做什么放在 AutomationAction 中,便于组合付款发货、评价赠品、求评价等流程。 +// AutomationRule 保存自动化规则,供当前处理流程使用 type AutomationRule struct { ID int64 UserID int64 @@ -94,6 +99,7 @@ type AutomationRun struct { // ErrAutomationRunLeaseLost 表示自动化运行已被更高 attempt_count 的 worker 接管。 var ErrAutomationRunLeaseLost = errors.New("自动化运行租约已失效") +// DeferredAutomationTask 保存Deferred自动化任务,供当前处理流程使用 type DeferredAutomationTask struct { ID int64 TaskKey string @@ -105,8 +111,10 @@ type DeferredAutomationTask struct { ErrorMessage string } +// ErrDeferredTaskLeaseLost 保存ErrDeferred任务LeaseLost,供当前处理流程使用 var ErrDeferredTaskLeaseLost = errors.New("延迟自动化任务租约已失效") +// AutomationRunIssue 保存自动化运行问题,供当前处理流程使用 type AutomationRunIssue struct { ID int64 `json:"id"` CookieID string `json:"cookie_id"` @@ -120,6 +128,7 @@ type AutomationRunIssue struct { UpdatedAt string `json:"updated_at"` } +// DeferredAutomationIssue 保存Deferred自动化问题,供当前处理流程使用 type DeferredAutomationIssue struct { ID int64 `json:"id"` CookieID string `json:"cookie_id"` @@ -153,8 +162,11 @@ type AutomationRuleListFilter struct { Offset int } +// automationRuleWhere 负责自动化规则Where相关处理。 func automationRuleWhere(f AutomationRuleListFilter) (string, []any) { + // where 保存where,供当前处理流程使用 where := []string{"r.user_id=?", "r.deleted_at IS NULL"} + // args 保存args,供当前处理流程使用 args := []any{f.UserID} if f.CookieID != "" { where = append(where, "r.cookie_id=?") @@ -168,7 +180,9 @@ func automationRuleWhere(f AutomationRuleListFilter) (string, []any) { where = append(where, "r.enabled=?") args = append(args, boolToInt(*f.Enabled)) } - if search := strings.ToLower(strings.TrimSpace(f.Search)); search != "" { + if // search 保存搜索,供当前处理流程使用 + search := strings.ToLower(strings.TrimSpace(f.Search)); search != "" { + // pattern 保存pattern,供当前处理流程使用 pattern := "%" + search + "%" where = append(where, `(LOWER(COALESCE(r.name,'')) LIKE ? OR LOWER(COALESCE(r.item_id,'')) LIKE ? @@ -192,16 +206,20 @@ type AutomationActionInput struct { // ListForUser 返回用户下全部自动化规则和动作。 func (a *AutomationRules) ListForUser(ctx context.Context, userID int64) ([]AutomationRule, error) { + // rules、err 保存rules、err,供当前处理流程使用 rules, _, err := a.ListPageForUser(ctx, AutomationRuleListFilter{UserID: userID}) return rules, err } // ListPageForUser 按用户隔离筛选并分页查询自动化规则和动作。 func (a *AutomationRules) ListPageForUser(ctx context.Context, f AutomationRuleListFilter) ([]AutomationRule, int, error) { + // whereSQL、args 保存whereSQL、args,供当前处理流程使用 whereSQL, args := automationRuleWhere(f) + // total 保存总数,供当前处理流程使用 var total int - if err := a.DB.QueryRowContext(ctx, ` + if // err 保存err,供当前处理流程使用 + err := a.DB.QueryRowContext(ctx, ` SELECT COUNT(*) FROM automation_rules r LEFT JOIN item_info i ON i.cookie_id=r.cookie_id AND i.item_id=r.item_id AND i.deleted_at IS NULL @@ -209,12 +227,15 @@ SELECT COUNT(*) return nil, 0, err } + // queryArgs 保存查询Args,供当前处理流程使用 queryArgs := append([]any{}, args...) + // limitSQL 保存上限SQL,供当前处理流程使用 limitSQL := "" if f.Limit > 0 { limitSQL = " LIMIT ? OFFSET ?" queryArgs = append(queryArgs, f.Limit, f.Offset) } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := a.DB.QueryContext(ctx, ` SELECT r.id,r.user_id,r.cookie_id,r.item_id,COALESCE(i.item_title,''),r.name,r.trigger_type,r.enabled, r.priority,r.config_json,r.created_at,r.updated_at @@ -226,15 +247,20 @@ SELECT r.id,r.user_id,r.cookie_id,r.item_id,COALESCE(i.item_title,''),r.name,r.t return nil, 0, err } defer rows.Close() + // out 保存out,供当前处理流程使用 out := []AutomationRule{} for rows.Next() { + // r 保存r,供当前处理流程使用 var r AutomationRule + // enabled 保存启用状态,供当前处理流程使用 var enabled int - if err := rows.Scan(&r.ID, &r.UserID, &r.CookieID, &r.ItemID, &r.ItemTitle, &r.Name, &r.TriggerType, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&r.ID, &r.UserID, &r.CookieID, &r.ItemID, &r.ItemTitle, &r.Name, &r.TriggerType, &enabled, &r.Priority, &r.ConfigJSON, &r.CreatedAt, &r.UpdatedAt); err != nil { return nil, 0, err } r.Enabled = enabled != 0 + // acts、err 保存acts、err,供当前处理流程使用 acts, err := a.Actions(ctx, r.ID) if err != nil { return nil, 0, err @@ -247,8 +273,11 @@ SELECT r.id,r.user_id,r.cookie_id,r.item_id,COALESCE(i.item_title,''),r.name,r.t // CountByTriggerForUser 返回同一筛选条件下各触发类型的规则数量。 // 该统计不受分页影响,确保页面汇总与 total 使用同一数据集。 +// CountByTriggerForUser 负责数量ByTriggerFor用户相关处理。 func (a *AutomationRules) CountByTriggerForUser(ctx context.Context, f AutomationRuleListFilter) (map[string]int, error) { + // whereSQL、args 保存whereSQL、args,供当前处理流程使用 whereSQL, args := automationRuleWhere(f) + // rows、err 保存rows、err,供当前处理流程使用 rows, err := a.DB.QueryContext(ctx, ` SELECT r.trigger_type, COUNT(*) FROM automation_rules r @@ -259,11 +288,15 @@ SELECT r.trigger_type, COUNT(*) return nil, err } defer rows.Close() + // counts 保存counts,供当前处理流程使用 counts := map[string]int{} for rows.Next() { + // triggerType 保存trigger类型,供当前处理流程使用 var triggerType string + // count 保存数量,供当前处理流程使用 var count int - if err := rows.Scan(&triggerType, &count); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&triggerType, &count); err != nil { return nil, err } counts[triggerType] = count @@ -273,7 +306,9 @@ SELECT r.trigger_type, COUNT(*) // Match 查询某事件可触发的规则。商品级规则存在时只返回商品级规则; // 没有商品级规则时才回退到账号级规则,避免两层规则叠加导致重复发货。 +// Match 负责Match相关处理。 func (a *AutomationRules) Match(ctx context.Context, cookieID, itemID, triggerType string) ([]AutomationRule, error) { + // out、err 保存out、err,供当前处理流程使用 out, err := a.matchScope(ctx, cookieID, itemID, triggerType) if err != nil || len(out) > 0 || itemID == "" { return highestPriorityRule(out), err @@ -282,6 +317,7 @@ func (a *AutomationRules) Match(ctx context.Context, cookieID, itemID, triggerTy return highestPriorityRule(out), err } +// highestPriorityRule 负责highest优先级规则相关处理。 func highestPriorityRule(rules []AutomationRule) []AutomationRule { if len(rules) <= 1 { return rules @@ -291,8 +327,11 @@ func highestPriorityRule(rules []AutomationRule) []AutomationRule { // Get 返回指定规则及其动作。 func (a *AutomationRules) Get(ctx context.Context, ruleID int64) (*AutomationRule, error) { + // rule 保存规则,供当前处理流程使用 var rule AutomationRule + // enabled 保存启用状态,供当前处理流程使用 var enabled int + // err 保存err,供当前处理流程使用 err := a.DB.QueryRowContext(ctx, ` SELECT r.id,r.user_id,r.cookie_id,r.item_id,COALESCE(i.item_title,''),r.name,r.trigger_type,r.enabled, r.priority,r.config_json,r.created_at,r.updated_at @@ -311,7 +350,9 @@ SELECT r.id,r.user_id,r.cookie_id,r.item_id,COALESCE(i.item_title,''),r.name,r.t return &rule, err } +// matchScope 负责matchScope相关处理。 func (a *AutomationRules) matchScope(ctx context.Context, cookieID, itemID, triggerType string) ([]AutomationRule, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := a.DB.QueryContext(ctx, ` SELECT r.id,r.user_id,r.cookie_id,r.item_id,COALESCE(i.item_title,''),r.name,r.trigger_type,r.enabled, r.priority,r.config_json,r.created_at,r.updated_at @@ -327,15 +368,20 @@ SELECT r.id,r.user_id,r.cookie_id,r.item_id,COALESCE(i.item_title,''),r.name,r.t return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 out := []AutomationRule{} for rows.Next() { + // r 保存r,供当前处理流程使用 var r AutomationRule + // enabled 保存启用状态,供当前处理流程使用 var enabled int - if err := rows.Scan(&r.ID, &r.UserID, &r.CookieID, &r.ItemID, &r.ItemTitle, &r.Name, &r.TriggerType, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&r.ID, &r.UserID, &r.CookieID, &r.ItemID, &r.ItemTitle, &r.Name, &r.TriggerType, &enabled, &r.Priority, &r.ConfigJSON, &r.CreatedAt, &r.UpdatedAt); err != nil { return nil, err } r.Enabled = enabled != 0 + // acts、err 保存acts、err,供当前处理流程使用 acts, err := a.Actions(ctx, r.ID) if err != nil { return nil, err @@ -348,16 +394,19 @@ SELECT r.id,r.user_id,r.cookie_id,r.item_id,COALESCE(i.item_title,''),r.name,r.t // Create 创建规则和动作。 func (a *AutomationRules) Create(ctx context.Context, in AutomationRuleInput) (int64, error) { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := a.DB.BeginTx(ctx, nil) if err != nil { return 0, err } defer tx.Rollback() + // id、err 保存id、err,供当前处理流程使用 id, err := createAutomationRuleTx(ctx, tx, a.Dialect, in) if err != nil { return 0, err } - if err := tx.Commit(); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.Commit(); err != nil { return 0, err } return id, nil @@ -365,11 +414,13 @@ func (a *AutomationRules) Create(ctx context.Context, in AutomationRuleInput) (i // Update 替换规则和动作。动作采用删除重建,避免前端携带展示字段造成局部更新不一致。 func (a *AutomationRules) Update(ctx context.Context, userID, ruleID int64, in AutomationRuleInput) error { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := a.DB.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() + // res、err 保存res、err,供当前处理流程使用 res, err := tx.ExecContext(ctx, ` UPDATE automation_rules SET cookie_id=?,item_id=?,name=?,trigger_type=?,enabled=?,priority=?,config_json=?,updated_at=CURRENT_TIMESTAMP @@ -378,14 +429,18 @@ UPDATE automation_rules if err != nil { return err } - if n, _ := res.RowsAffected(); n == 0 { + if // n 保存n,供当前处理流程使用 + n, _ := res.RowsAffected(); n == 0 { return ErrNotFound } - if _, err := tx.ExecContext(ctx, `DELETE FROM automation_rule_actions WHERE rule_id=?`, ruleID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `DELETE FROM automation_rule_actions WHERE rule_id=?`, ruleID); err != nil { return err } + // act 表示当前遍历过程中的act for _, act := range in.Actions { - if err := insertAutomationActionTx(ctx, tx, ruleID, act); err != nil { + if // err 保存err,供当前处理流程使用 + err := insertAutomationActionTx(ctx, tx, ruleID, act); err != nil { return err } } @@ -394,6 +449,7 @@ UPDATE automation_rules // Delete 逻辑删除规则,保留动作和执行记录以便审计;逻辑删除后不再出现在规则列表和匹配结果中。 func (a *AutomationRules) Delete(ctx context.Context, userID, ruleID int64) error { + // res、err 保存res、err,供当前处理流程使用 res, err := a.DB.ExecContext(ctx, `UPDATE automation_rules SET deleted_at=CURRENT_TIMESTAMP, enabled=0, updated_at=CURRENT_TIMESTAMP WHERE id=? AND user_id=? AND deleted_at IS NULL AND NOT EXISTS ( @@ -402,9 +458,12 @@ func (a *AutomationRules) Delete(ctx context.Context, userID, ruleID int64) erro if err != nil { return err } - if n, _ := res.RowsAffected(); n == 0 { + if // n 保存n,供当前处理流程使用 + n, _ := res.RowsAffected(); n == 0 { + // exists 保存exists,供当前处理流程使用 var exists int - if err := a.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM automation_rules WHERE id=? AND user_id=? AND deleted_at IS NULL`, ruleID, userID).Scan(&exists); err != nil { + if // err 保存err,供当前处理流程使用 + err := a.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM automation_rules WHERE id=? AND user_id=? AND deleted_at IS NULL`, ruleID, userID).Scan(&exists); err != nil { return err } if exists > 0 { @@ -417,6 +476,7 @@ func (a *AutomationRules) Delete(ctx context.Context, userID, ruleID int64) erro // Actions 返回规则动作。 func (a *AutomationRules) Actions(ctx context.Context, ruleID int64) ([]AutomationAction, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := a.DB.QueryContext(ctx, ` SELECT a.id,a.rule_id,a.action_type,COALESCE(a.card_id,0),COALESCE(c.name,''),a.delivery_count, a.message_template,a.delay_seconds,a.config_json,a.enabled,a.sort_order @@ -428,11 +488,15 @@ SELECT a.id,a.rule_id,a.action_type,COALESCE(a.card_id,0),COALESCE(c.name,''),a. return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 out := []AutomationAction{} for rows.Next() { + // act 保存act,供当前处理流程使用 var act AutomationAction + // enabled 保存启用状态,供当前处理流程使用 var enabled int - if err := rows.Scan(&act.ID, &act.RuleID, &act.ActionType, &act.CardID, &act.CardName, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&act.ID, &act.RuleID, &act.ActionType, &act.CardID, &act.CardName, &act.DeliveryCount, &act.MessageTemplate, &act.DelaySeconds, &act.ConfigJSON, &enabled, &act.SortOrder); err != nil { return nil, err @@ -445,21 +509,27 @@ SELECT a.id,a.rule_id,a.action_type,COALESCE(a.card_id,0),COALESCE(c.name,''),a. // TryStartRun 以 UNIQUE(rule_id, trigger_key) 作为持久化防重。 // 返回 started=false 表示该规则对该触发已执行或正在执行,调用方应直接跳过。 +// TryStartRun 负责Try开始运行相关处理。 func (a *AutomationRules) TryStartRun(ctx context.Context, run AutomationRun) (int64, bool, error) { + // now 保存now,供当前处理流程使用 now := time.Now().UTC().Unix() + // leaseExpiresAt 保存leaseExpiresAt,供当前处理流程使用 leaseExpiresAt := run.LeaseExpiresAt if leaseExpiresAt <= now { leaseExpiresAt = now + int64((5*time.Minute)/time.Second) } + // query 保存查询,供当前处理流程使用 query := dialectInsertIgnorePrefix(a.Dialect) + ` INTO automation_runs (rule_id,cookie_id,item_id,order_id,buyer_id,chat_id,trigger_type,trigger_key,status,raw_event_json,lease_expires_at,attempt_count,next_retry_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)` + dialectInsertIgnore(a.Dialect, []string{"rule_id", "trigger_key"}) + // args 保存args,供当前处理流程使用 args := []any{run.RuleID, run.CookieID, run.ItemID, run.OrderID, run.BuyerID, run.ChatID, run.TriggerType, run.TriggerKey, "running", validJSON(run.RawEventJSON), leaseExpiresAt, 1, 0} if a.Dialect == DialectPostgres { // pgx 不支持 LastInsertId;用 RETURNING id。ON CONFLICT DO NOTHING 冲突时无行返回 → 未启动。 var id int64 + // err 保存err,供当前处理流程使用 err := a.DB.QueryRowContext(ctx, query+" RETURNING id", args...).Scan(&id) if err != nil { if errors.Is(err, sql.ErrNoRows) { @@ -470,18 +540,23 @@ func (a *AutomationRules) TryStartRun(ctx context.Context, run AutomationRun) (i return id, true, nil } + // res、err 保存res、err,供当前处理流程使用 res, err := a.DB.ExecContext(ctx, query, args...) if err != nil { return 0, false, err } - if n, _ := res.RowsAffected(); n == 0 { + if // n 保存n,供当前处理流程使用 + n, _ := res.RowsAffected(); n == 0 { return a.reclaimRun(ctx, run.RuleID, run.TriggerKey, leaseExpiresAt, now) } + // id 保存标识,供当前处理流程使用 id, _ := res.LastInsertId() return id, true, nil } +// reclaimRun 负责reclaim运行相关处理。 func (a *AutomationRules) reclaimRun(ctx context.Context, ruleID int64, triggerKey string, leaseExpiresAt, now int64) (int64, bool, error) { + // res、err 保存res、err,供当前处理流程使用 res, err := a.DB.ExecContext(ctx, `UPDATE automation_runs SET status='running',error_message='',lease_expires_at=?,next_retry_at=0, attempt_count=attempt_count+1,updated_at=CURRENT_TIMESTAMP @@ -493,11 +568,14 @@ func (a *AutomationRules) reclaimRun(ctx context.Context, ruleID int64, triggerK if err != nil { return 0, false, err } - if n, rowsErr := res.RowsAffected(); rowsErr != nil || n != 1 { + if // n、rowsErr 保存n、rowsErr,供当前处理流程使用 + n, rowsErr := res.RowsAffected(); rowsErr != nil || n != 1 { return 0, false, rowsErr } + // id 保存标识,供当前处理流程使用 var id int64 - if err := a.DB.QueryRowContext(ctx, + if // err 保存err,供当前处理流程使用 + err := a.DB.QueryRowContext(ctx, `SELECT id FROM automation_runs WHERE rule_id=? AND trigger_key=?`, ruleID, triggerKey).Scan(&id); err != nil { return 0, false, err } @@ -506,8 +584,11 @@ func (a *AutomationRules) reclaimRun(ctx context.Context, ruleID int64, triggerK // GetRun 返回自动化运行及动作检查点。 func (a *AutomationRules) GetRun(ctx context.Context, id int64) (*AutomationRun, error) { + // run 保存运行,供当前处理流程使用 var run AutomationRun + // actionStarted 保存动作Started,供当前处理流程使用 var actionStarted int + // err 保存err,供当前处理流程使用 err := a.DB.QueryRowContext(ctx, `SELECT id,rule_id,cookie_id,item_id,order_id,buyer_id,chat_id,trigger_type,trigger_key, status,sent_count,error_message,raw_event_json,lease_expires_at,attempt_count,next_retry_at,action_cursor,action_started FROM automation_runs WHERE id=?`, id).Scan(&run.ID, &run.RuleID, &run.CookieID, &run.ItemID, &run.OrderID, @@ -523,17 +604,20 @@ func (a *AutomationRules) GetRun(ctx context.Context, id int64) (*AutomationRun, // StartRunAction 在外部副作用前持久化 started;崩溃恢复看到 started 时不会盲目重放。 func (a *AutomationRules) StartRunAction(ctx context.Context, runID int64, attempt, cursor int, leaseExpiresAt int64) (bool, error) { + // res、err 保存res、err,供当前处理流程使用 res, err := a.DB.ExecContext(ctx, `UPDATE automation_runs SET action_started=1,lease_expires_at=?,updated_at=CURRENT_TIMESTAMP WHERE id=? AND attempt_count=? AND status='running' AND action_cursor=? AND action_started=0`, leaseExpiresAt, runID, attempt, cursor) if err != nil { return false, err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() return err == nil && n == 1, err } // AdvanceRunAction 在动作明确成功后推进游标并累计已发送数量。 func (a *AutomationRules) AdvanceRunAction(ctx context.Context, runID int64, attempt, cursor, sentDelta int) error { + // res、err 保存res、err,供当前处理流程使用 res, err := a.DB.ExecContext(ctx, `UPDATE automation_runs SET action_cursor=?,action_started=0,sent_count=sent_count+?,updated_at=CURRENT_TIMESTAMP WHERE id=? AND attempt_count=? AND status='running' AND action_cursor=? AND action_started=1`, cursor+1, sentDelta, runID, attempt, cursor) @@ -543,7 +627,9 @@ func (a *AutomationRules) AdvanceRunAction(ctx context.Context, runID int64, att return requireAutomationRunOwner(res) } +// AbortRunAction 负责Abort运行动作相关处理。 func (a *AutomationRules) AbortRunAction(ctx context.Context, runID int64, attempt, cursor int) error { + // res、err 保存res、err,供当前处理流程使用 res, err := a.DB.ExecContext(ctx, `UPDATE automation_runs SET action_started=0,updated_at=CURRENT_TIMESTAMP WHERE id=? AND attempt_count=? AND status='running' AND action_cursor=?`, runID, attempt, cursor) if err != nil { @@ -552,7 +638,9 @@ func (a *AutomationRules) AbortRunAction(ctx context.Context, runID int64, attem return requireAutomationRunOwner(res) } +// RenewRunLease 负责Renew运行Lease相关处理。 func (a *AutomationRules) RenewRunLease(ctx context.Context, runID int64, attempt int, leaseExpiresAt int64) error { + // res、err 保存res、err,供当前处理流程使用 res, err := a.DB.ExecContext(ctx, `UPDATE automation_runs SET lease_expires_at=?,updated_at=CURRENT_TIMESTAMP WHERE id=? AND attempt_count=? AND status='running'`, leaseExpiresAt, runID, attempt) if err != nil { @@ -561,7 +649,9 @@ func (a *AutomationRules) RenewRunLease(ctx context.Context, runID int64, attemp return requireAutomationRunOwner(res) } +// QuarantineRun 负责Quarantine运行相关处理。 func (a *AutomationRules) QuarantineRun(ctx context.Context, runID int64, attempt int, reason string) error { + // res、err 保存res、err,供当前处理流程使用 res, err := a.DB.ExecContext(ctx, `UPDATE automation_runs SET status='needs_review',error_message=?,lease_expires_at=0,next_retry_at=0,updated_at=CURRENT_TIMESTAMP WHERE id=? AND attempt_count=? AND status IN ('running','failed')`, reason, runID, attempt) @@ -571,7 +661,9 @@ func (a *AutomationRules) QuarantineRun(ctx context.Context, runID int64, attemp return requireAutomationRunOwner(res) } +// QuarantineRunResult 负责Quarantine运行结果相关处理。 func (a *AutomationRules) QuarantineRunResult(ctx context.Context, runID int64, attempt, sentCount int, reason string) error { + // res、err 保存res、err,供当前处理流程使用 res, err := a.DB.ExecContext(ctx, `UPDATE automation_runs SET status='needs_review',sent_count=?,error_message=?,lease_expires_at=0,next_retry_at=0,updated_at=CURRENT_TIMESTAMP WHERE id=? AND attempt_count=? AND status IN ('running','failed')`, sentCount, reason, runID, attempt) @@ -583,6 +675,7 @@ func (a *AutomationRules) QuarantineRunResult(ctx context.Context, runID int64, // PostponeRecoveryRun 把暂时不能执行的账号移到恢复队列尾部,避免固定的前 100 条饿死后续任务。 func (a *AutomationRules) PostponeRecoveryRun(ctx context.Context, runID int64, attempt int, retryAt int64) error { + // res、err 保存res、err,供当前处理流程使用 res, err := a.DB.ExecContext(ctx, `UPDATE automation_runs SET lease_expires_at=CASE WHEN status='running' THEN ? ELSE lease_expires_at END, next_retry_at=CASE WHEN status='failed' THEN ? ELSE next_retry_at END, @@ -594,8 +687,11 @@ func (a *AutomationRules) PostponeRecoveryRun(ctx context.Context, runID int64, return requireAutomationRunOwner(res) } +// ClaimRecoveryRun 负责ClaimRecovery运行相关处理。 func (a *AutomationRules) ClaimRecoveryRun(ctx context.Context, runID, leaseExpiresAt int64) (bool, error) { + // now 保存now,供当前处理流程使用 now := time.Now().UTC().Unix() + // res、err 保存res、err,供当前处理流程使用 res, err := a.DB.ExecContext(ctx, `UPDATE automation_runs SET status='running',error_message='',lease_expires_at=?,next_retry_at=0,attempt_count=attempt_count+1,updated_at=CURRENT_TIMESTAMP WHERE id=? AND action_started=0 AND ((status='running' AND (lease_expires_at=0 OR lease_expires_at=5 THEN 'dead_letter' ELSE 'pending' END, due_at=?,lease_expires_at=0,error_message=?,updated_at=CURRENT_TIMESTAMP @@ -907,10 +1064,12 @@ func (a *AutomationRules) FinishDeferredTask(ctx context.Context, id int64, clai return requireDeferredTaskOwner(res, err) } +// deferredRetryDelay 负责deferred重试延迟相关处理。 func deferredRetryDelay(attempt int) time.Duration { if attempt < 1 { attempt = 1 } + // delay 保存延迟,供当前处理流程使用 delay := 5 * time.Minute * time.Duration(1<<(attempt-1)) if delay > time.Hour { return time.Hour @@ -923,7 +1082,8 @@ func (a *AutomationRules) WakeCredentialBlocked(ctx context.Context, cookieID st if strings.TrimSpace(cookieID) == "" { return nil } - if _, err := a.DB.ExecContext(ctx, `UPDATE automation_pending_tasks + if // err 保存err,供当前处理流程使用 + _, err := a.DB.ExecContext(ctx, `UPDATE automation_pending_tasks SET due_at=0,updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND status='pending' AND (LOWER(error_message) LIKE '%session%' OR error_message LIKE '%登录凭证%' @@ -932,6 +1092,7 @@ func (a *AutomationRules) WakeCredentialBlocked(ctx context.Context, cookieID st OR error_message LIKE '%消息连接%' OR error_message LIKE '%账号未在线%')`, cookieID); err != nil { return err } + // err 保存err,供当前处理流程使用 _, err := a.DB.ExecContext(ctx, `UPDATE automation_runs SET next_retry_at=0,updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND status='failed' AND action_started=0 @@ -943,17 +1104,21 @@ func (a *AutomationRules) WakeCredentialBlocked(ctx context.Context, cookieID st return err } +// RenewDeferredTaskLease 负责RenewDeferred任务Lease相关处理。 func (a *AutomationRules) RenewDeferredTaskLease(ctx context.Context, id int64, claimVersion int, leaseExpiresAt int64) error { + // res、err 保存res、err,供当前处理流程使用 res, err := a.DB.ExecContext(ctx, `UPDATE automation_pending_tasks SET lease_expires_at=?,updated_at=CURRENT_TIMESTAMP WHERE id=? AND status='running' AND attempt_count=?`, leaseExpiresAt, id, claimVersion) return requireDeferredTaskOwner(res, err) } +// requireDeferredTaskOwner 负责requireDeferred任务所有者相关处理。 func requireDeferredTaskOwner(res sql.Result, err error) error { if err != nil { return err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() if err != nil { return err @@ -974,14 +1139,18 @@ func (a *AutomationRules) MarkOrderEventTime(ctx context.Context, orderID, field // 事件时间列是跨方言 TEXT。不能直接写 CURRENT_TIMESTAMP:Postgres 会产生 // "2006-01-02 15:04:05.999999+00",而 MySQL 的无时区文本又取决于会话时区, // 调度器无法可靠解释。统一由应用写 RFC3339 UTC,已有值仍保留(幂等)。 + // now 保存now,供当前处理流程使用 now := time.Now().UTC().Format(time.RFC3339Nano) + // err 保存err,供当前处理流程使用 _, err := a.DB.ExecContext(ctx, "UPDATE orders SET "+field+"=?, updated_at=CURRENT_TIMESTAMP WHERE order_id=? AND COALESCE("+field+",'')=''", now, orderID) return err } // IncrementReviewRequest 记录一次求评价请求。 func (a *AutomationRules) IncrementReviewRequest(ctx context.Context, orderID string) error { + // now 保存now,供当前处理流程使用 now := time.Now().UTC().Format(time.RFC3339Nano) + // err 保存err,供当前处理流程使用 _, err := a.DB.ExecContext(ctx, ` UPDATE orders SET review_request_count=review_request_count+1, @@ -998,17 +1167,21 @@ func (a *AutomationRules) DueReviewRequestOrders(ctx context.Context, limit int) // DueReviewRequestOrdersAfter 用不可变的订单 ID 作为稳定游标分页扫描,避免固定 LIMIT // 让旧订单饿死后续订单。不能使用 updated_at:执行求评价动作本身会修改该字段。 +// DueReviewRequestOrdersAfter 负责DueReview请求订单列表After相关处理。 func (a *AutomationRules) DueReviewRequestOrdersAfter(ctx context.Context, afterOrderID string, limit int) ([]Order, error) { if limit <= 0 { limit = 200 } + // cursorSQL 保存游标SQL,供当前处理流程使用 cursorSQL := "" + // args 保存args,供当前处理流程使用 args := []any{} if afterOrderID != "" { cursorSQL = " AND o.order_id>?" args = append(args, afterOrderID) } args = append(args, limit) + // rows、err 保存rows、err,供当前处理流程使用 rows, err := a.DB.QueryContext(ctx, ` SELECT order_id,item_id,buyer_id,spec_name,spec_value,quantity,amount,order_status,cookie_id,is_bargain, receiver_name,receiver_phone,receiver_address,receiver_city,version,chat_id,system_shipped, @@ -1030,15 +1203,20 @@ WHERE o.system_shipped=1 return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 out := []Order{} for rows.Next() { + // ord 保存ord,供当前处理流程使用 var ord Order + // isBargain、version、sysShipped 保存isBargain、version、sysShipped,供当前处理流程使用 var isBargain, version, sysShipped int // orders 表的可空 TEXT 列必须用 NullString 扫描,旧库数据可能为 NULL // (spec_name/spec_value 等在 init schema 中无 NOT NULL 约束)。 + // itemID、buyerID、specName、specValue、qty、amount、status、cookieID、receiverName、receiverPhone、receiverAddr、receiverCity、chatID 保存商品ID、buyerID、specName、specValue、qty、amount、status、cookieID、receiverName、receiverPhone、receiverAddr、receiverCity、chatID,供当前处理流程使用 var itemID, buyerID, specName, specValue, qty, amount, status, cookieID, receiverName, receiverPhone, receiverAddr, receiverCity, chatID sql.NullString - if err := rows.Scan(&ord.OrderID, &itemID, &buyerID, &specName, &specValue, &qty, &amount, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&ord.OrderID, &itemID, &buyerID, &specName, &specValue, &qty, &amount, &status, &cookieID, &isBargain, &receiverName, &receiverPhone, &receiverAddr, &receiverCity, &version, &chatID, &sysShipped, &ord.PaidAt, &ord.ShippedAt, &ord.CompletedAt, &ord.BuyerReviewedAt, &ord.LastReviewRequestAt, @@ -1066,10 +1244,12 @@ WHERE o.system_shipped=1 return out, rows.Err() } +// createAutomationRuleTx 负责create自动化规则Tx相关处理。 func createAutomationRuleTx(ctx context.Context, tx *sql.Tx, dialect Dialect, in AutomationRuleInput) (int64, error) { if in.Priority <= 0 { in.Priority = 100 } + // id、err 保存id、err,供当前处理流程使用 id, err := insertReturningID(ctx, tx, dialect, ` INSERT INTO automation_rules (user_id,cookie_id,item_id,name,trigger_type,enabled,priority,config_json) VALUES (?,?,?,?,?,?,?,?)`, @@ -1077,18 +1257,22 @@ VALUES (?,?,?,?,?,?,?,?)`, if err != nil { return 0, err } + // act 表示当前遍历过程中的act for _, act := range in.Actions { - if err := insertAutomationActionTx(ctx, tx, id, act); err != nil { + if // err 保存err,供当前处理流程使用 + err := insertAutomationActionTx(ctx, tx, id, act); err != nil { return 0, err } } return id, nil } +// insertAutomationActionTx 负责insert自动化动作Tx相关处理。 func insertAutomationActionTx(ctx context.Context, tx *sql.Tx, ruleID int64, act AutomationActionInput) error { if act.DeliveryCount <= 0 { act.DeliveryCount = 1 } + // err 保存err,供当前处理流程使用 _, err := tx.ExecContext(ctx, ` INSERT INTO automation_rule_actions (rule_id,action_type,card_id,delivery_count,message_template,delay_seconds,config_json,enabled,sort_order) @@ -1098,6 +1282,7 @@ VALUES (?,?,?,?,?,?,?,?,?)`, return err } +// nullInt64 负责nullInt64相关处理。 func nullInt64(v int64) any { if v <= 0 { return nil @@ -1105,12 +1290,15 @@ func nullInt64(v int64) any { return v } +// validJSON 负责有效JSON相关处理。 func validJSON(s string) string { if s == "" { return "{}" } + // v 保存v,供当前处理流程使用 var v any - if err := json.Unmarshal([]byte(s), &v); err != nil { + if // err 保存err,供当前处理流程使用 + err := json.Unmarshal([]byte(s), &v); err != nil { return "{}" } return s diff --git a/internal/db/automation_test.go b/internal/db/automation_test.go index 57e3252..313581d 100644 --- a/internal/db/automation_test.go +++ b/internal/db/automation_test.go @@ -22,14 +22,18 @@ func makeAutomationRule(cid string, uid int64, itemID, trigger string, enabled b // TestAutomation_ListForUserAndActions ListForUser + Actions 路径。 func TestAutomation_ListForUserAndActions(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) // 建一张卡券,动作里引用它。 cardID, _ := s.Cards.Create(ctx, &CardFull{Name: "卡密", Type: "text", TextContent: "C", Enabled: true, UserID: uid}) + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "i1", "paid", true, 100, AutomationActionInput{ActionType: "send_card", CardID: cardID, DeliveryCount: 2, Enabled: true, SortOrder: 1}, AutomationActionInput{ActionType: "send_msg", MessageTemplate: "hi", Enabled: false, SortOrder: 2}, @@ -42,6 +46,7 @@ func TestAutomation_ListForUserAndActions(t *testing.T) { // 先建 item_info 以验证 LEFT JOIN 取到 title。 s.Items.Upsert(ctx, &ItemInfoRow{CookieID: cid, ItemID: "i1", ItemTitle: "商品1"}) + // rules、err 保存rules、err,供当前处理流程使用 rules, err := s.Automation.ListForUser(ctx, uid) if err != nil { t.Fatalf("ListForUser: %v", err) @@ -49,6 +54,7 @@ func TestAutomation_ListForUserAndActions(t *testing.T) { if len(rules) != 1 { t.Fatalf("ListForUser len=%d want 1", len(rules)) } + // r 保存r,供当前处理流程使用 r := rules[0] if r.ID != ruleID || r.CookieID != cid || r.ItemID != "i1" || r.ItemTitle != "商品1" || !r.Enabled { t.Fatalf("rule 字段: %#v", r) @@ -82,9 +88,12 @@ func TestAutomation_ListForUserAndActions(t *testing.T) { // TestAutomation_MatchPriority 商品精确规则优先于账号级规则;enabled=false 不匹配。 func TestAutomation_MatchPriority(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) // 账号级规则(item_id 空),priority=200。 @@ -115,6 +124,7 @@ func TestAutomation_MatchPriority(t *testing.T) { t.Fatalf("Create disabled rule: %v", err) } + // matched、err 保存matched、err,供当前处理流程使用 matched, err := s.Automation.Match(ctx, cid, "i1", "paid") if err != nil { t.Fatalf("Match: %v", err) @@ -126,6 +136,7 @@ func TestAutomation_MatchPriority(t *testing.T) { if matched[0].ID != itemRuleID { t.Fatalf("Match 顺序: first id=%d want item rule %d", matched[0].ID, itemRuleID) } + // fallback、err 保存fallback、err,供当前处理流程使用 fallback, err := s.Automation.Match(ctx, cid, "other-item", "paid") if err != nil || len(fallback) != 1 || fallback[0].ItemID != "" { t.Fatalf("无商品级规则时应回退账号级: %#v err=%v", fallback, err) @@ -138,18 +149,25 @@ func TestAutomation_MatchPriority(t *testing.T) { } } +// TestAutomationMatchReturnsOnlyHighestPriorityRule 负责Test自动化MatchReturnsOnlyHighest优先级规则相关处理。 func TestAutomationMatchReturnsOnlyHighestPriorityRule(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) + // first、err 保存first、err,供当前处理流程使用 first, err := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "i1", "paid", true, 50)) if err != nil { t.Fatal(err) } - if _, err := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "i1", "paid", true, 100)); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "i1", "paid", true, 100)); err != nil { t.Fatal(err) } + // matched、err 保存matched、err,供当前处理流程使用 matched, err := s.Automation.Match(ctx, cid, "i1", "paid") if err != nil || len(matched) != 1 || matched[0].ID != first { t.Fatalf("matched=%+v err=%v", matched, err) @@ -158,11 +176,15 @@ func TestAutomationMatchReturnsOnlyHighestPriorityRule(t *testing.T) { // TestAutomation_UpdateDelete Update 替换动作 + Delete 路径。 func TestAutomation_UpdateDelete(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "i1", "paid", true, 100, AutomationActionInput{ActionType: "send_card", Enabled: true}, )) @@ -181,10 +203,12 @@ func TestAutomation_UpdateDelete(t *testing.T) { }); err != nil { t.Fatalf("Update: %v", err) } + // rules 保存规则列表,供当前处理流程使用 rules, _ := s.Automation.ListForUser(ctx, uid) if len(rules) != 1 { t.Fatalf("Update 后 len=%d want 1", len(rules)) } + // r 保存r,供当前处理流程使用 r := rules[0] if r.ItemID != "i2" || r.TriggerType != "shipped" || r.Enabled || r.Priority != 50 || len(r.Actions) != 2 { t.Fatalf("Update 后字段: %#v", r) @@ -197,16 +221,20 @@ func TestAutomation_UpdateDelete(t *testing.T) { } // Delete。 - if err := s.Automation.Delete(ctx, uid, ruleID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.Delete(ctx, uid, ruleID); err != nil { t.Fatalf("Delete: %v", err) } rules, _ = s.Automation.ListForUser(ctx, uid) if len(rules) != 0 { t.Fatalf("Delete 后 len=%d want 0", len(rules)) } + // deletedAt 保存deletedAt,供当前处理流程使用 var deletedAt string + // enabled 保存启用状态,供当前处理流程使用 var enabled int - if err := s.DB.QueryRowContext(ctx, `SELECT deleted_at, enabled FROM automation_rules WHERE id=?`, ruleID).Scan(&deletedAt, &enabled); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRowContext(ctx, `SELECT deleted_at, enabled FROM automation_rules WHERE id=?`, ruleID).Scan(&deletedAt, &enabled); err != nil { t.Fatalf("逻辑删除后规则原始行不存在: %v", err) } if deletedAt == "" || enabled != 0 { @@ -218,34 +246,44 @@ func TestAutomation_UpdateDelete(t *testing.T) { } // 跨用户 Delete → ErrNotFound(隔离校验)。 otherID, _ := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "i3", "paid", true, 100)) - if err := s.Automation.Delete(ctx, uid+999, otherID); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + err := s.Automation.Delete(ctx, uid+999, otherID); !errors.Is(err, ErrNotFound) { t.Fatalf("跨用户 Delete 应 ErrNotFound, got %v", err) } } // TestAutomation_MarkOrderEventTime 白名单字段 + 非法字段拒绝。 func TestAutomation_MarkOrderEventTime(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) s.Orders.Upsert(ctx, "o1", OrderUpsertOpts{ItemID: "i1", BuyerID: "b1", CookieID: cid}) // 白名单字段全部能更新。 for _, f := range []string{"paid_at", "shipped_at", "completed_at", "buyer_reviewed_at", "last_review_request_at"} { - if err := s.Automation.MarkOrderEventTime(ctx, "o1", f); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.MarkOrderEventTime(ctx, "o1", f); err != nil { t.Fatalf("MarkOrderEventTime(%s): %v", f, err) } } + // originalPaidAt 保存originalPaidAt,供当前处理流程使用 const originalPaidAt = "2020-01-02 03:04:05" - if _, err := s.DB.ExecContext(ctx, `UPDATE orders SET paid_at=? WHERE order_id='o1'`, originalPaidAt); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE orders SET paid_at=? WHERE order_id='o1'`, originalPaidAt); err != nil { t.Fatal(err) } - if err := s.Automation.MarkOrderEventTime(ctx, "o1", "paid_at"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.MarkOrderEventTime(ctx, "o1", "paid_at"); err != nil { t.Fatal(err) } + // paidAt 保存paidAt,供当前处理流程使用 var paidAt string - if err := s.DB.QueryRowContext(ctx, `SELECT paid_at FROM orders WHERE order_id='o1'`).Scan(&paidAt); err != nil || paidAt != originalPaidAt { + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRowContext(ctx, `SELECT paid_at FROM orders WHERE order_id='o1'`).Scan(&paidAt); err != nil || paidAt != originalPaidAt { t.Fatalf("event timestamp overwritten: %q err=%v", paidAt, err) } // 非法字段拒绝。 @@ -260,12 +298,17 @@ func TestAutomation_MarkOrderEventTime(t *testing.T) { } // TestAutomation_IncrementReviewRequest + DueReviewRequestOrders。 +// TestAutomation_ReviewRequest 负责Test自动化Review请求相关处理。 func TestAutomation_ReviewRequest(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) - if _, err := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "", "review_missing_timeout", true, 100, + if // err 保存err,供当前处理流程使用 + _, err := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "", "review_missing_timeout", true, 100, AutomationActionInput{ActionType: "send_text", MessageTemplate: "review", Enabled: true})); err != nil { t.Fatal(err) } @@ -280,9 +323,11 @@ func TestAutomation_ReviewRequest(t *testing.T) { s.Automation.MarkOrderEventTime(ctx, "o1", "paid_at") // IncrementReviewRequest。 - if err := s.Automation.IncrementReviewRequest(ctx, "o1"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.IncrementReviewRequest(ctx, "o1"); err != nil { t.Fatalf("IncrementReviewRequest: %v", err) } + // got 保存got,供当前处理流程使用 got, _ := s.Orders.Get(ctx, "o1") if got.ReviewRequestCount != 1 { t.Fatalf("ReviewRequestCount=%d want 1", got.ReviewRequestCount) @@ -322,9 +367,12 @@ func TestAutomation_ReviewRequest(t *testing.T) { // TestAutomation_CreatePriorityDefault priority<=0 时默认 100。 func TestAutomation_CreatePriorityDefault(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) // priority=0 → 应被改为 100。 @@ -335,6 +383,7 @@ func TestAutomation_CreatePriorityDefault(t *testing.T) { if err != nil { t.Fatalf("Create: %v", err) } + // rules 保存规则列表,供当前处理流程使用 rules, _ := s.Automation.ListForUser(ctx, uid) if len(rules) != 1 || rules[0].ID != ruleID || rules[0].Priority != 100 { t.Fatalf("priority 默认值: %#v", rules[0]) @@ -343,35 +392,48 @@ func TestAutomation_CreatePriorityDefault(t *testing.T) { // TestAutomation_TryStartRunPostgresBranch 占位:SQLite 走 LastInsertId 分支。 // 这里验证 SQLite 下 id 单调递增、FinishRun 后状态。 +// TestAutomation_TryStartRunAndFinishRun 负责Test自动化Try开始运行AndFinish运行相关处理。 func TestAutomation_TryStartRunAndFinishRun(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) + // ruleID 保存规则ID,供当前处理流程使用 ruleID, _ := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "i1", "paid", true, 100, AutomationActionInput{ActionType: "send_card", Enabled: true}, )) + // run 保存运行,供当前处理流程使用 run := AutomationRun{ RuleID: ruleID, CookieID: cid, ItemID: "i1", OrderID: "o1", TriggerType: "paid", TriggerKey: "paid:o1", RawEventJSON: `{"a":1}`, // 合法 JSON,验证 validJSON 透传 } + // id、started、err 保存id、started、err,供当前处理流程使用 id, started, err := s.Automation.TryStartRun(ctx, run) if err != nil || !started || id == 0 { t.Fatalf("TryStartRun: id=%d started=%v err=%v", id, started, err) } // FinishRun。 - if err := s.Automation.FinishRun(ctx, id, 1, "done", 1, ""); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.FinishRun(ctx, id, 1, "done", 1, ""); err != nil { t.Fatalf("FinishRun: %v", err) } } +// TestAutomationRecoverDefinitelyUnsentReviewRun 负责Test自动化RecoverDefinitelyUnsentReview运行相关处理。 func TestAutomationRecoverDefinitelyUnsentReviewRun(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // userID、cookieID 保存用户ID、cookieID,供当前处理流程使用 userID, cookieID := seedAccount(t, s) + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := s.Automation.Create(ctx, AutomationRuleInput{ UserID: userID, CookieID: cookieID, Name: "review", TriggerType: "review_missing_timeout", Enabled: true, Actions: []AutomationActionInput{{ActionType: "send_text", MessageTemplate: "review", Enabled: true}}, @@ -379,6 +441,7 @@ func TestAutomationRecoverDefinitelyUnsentReviewRun(t *testing.T) { if err != nil { t.Fatal(err) } + // runID、started、err 保存运行ID、started、err,供当前处理流程使用 runID, started, err := s.Automation.TryStartRun(ctx, AutomationRun{ RuleID: ruleID, CookieID: cookieID, OrderID: "legacy-ws", TriggerType: "review_missing_timeout", TriggerKey: "review_missing_timeout:legacy-ws:1", RawEventJSON: `{}`, @@ -386,16 +449,19 @@ func TestAutomationRecoverDefinitelyUnsentReviewRun(t *testing.T) { if err != nil || !started { t.Fatalf("TryStartRun: started=%v err=%v", started, err) } - if _, err := s.DB.ExecContext(ctx, `UPDATE automation_runs + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE automation_runs SET status='needs_review',sent_count=0,action_started=1, error_message='自动化动作结果需要人工核对: 账号当前没有可用 WebSocket 连接' WHERE id=?`, runID); err != nil { t.Fatal(err) } + // recovered、err 保存recovered、err,供当前处理流程使用 recovered, err := s.Automation.RecoverDefinitelyUnsentReviewRuns(ctx) if err != nil || recovered != 1 { t.Fatalf("RecoverDefinitelyUnsentReviewRuns=%d err=%v", recovered, err) } + // run、err 保存run、err,供当前处理流程使用 run, err := s.Automation.GetRun(ctx, runID) if err != nil { t.Fatal(err) @@ -405,16 +471,23 @@ func TestAutomationRecoverDefinitelyUnsentReviewRun(t *testing.T) { } } +// TestAutomation_TryStartRunRecoversStaleAndUnsentFailedRuns 负责Test自动化Try开始运行RecoversStaleAndUnsent失败运行记录相关处理。 func TestAutomation_TryStartRunRecoversStaleAndUnsentFailedRuns(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) + // ruleID 保存规则ID,供当前处理流程使用 ruleID, _ := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "i1", "paid", true, 100)) + // run 保存运行,供当前处理流程使用 run := AutomationRun{ RuleID: ruleID, CookieID: cid, ItemID: "i1", OrderID: "o-retry", TriggerType: "paid", TriggerKey: "paid:o-retry", } + // id、started、err 保存id、started、err,供当前处理流程使用 id, started, err := s.Automation.TryStartRun(ctx, run) if err != nil || !started { t.Fatalf("first start: id=%d started=%v err=%v", id, started, err) @@ -422,34 +495,41 @@ func TestAutomation_TryStartRunRecoversStaleAndUnsentFailedRuns(t *testing.T) { if _, started, err = s.Automation.TryStartRun(ctx, run); err != nil || started { t.Fatalf("active lease must deduplicate: started=%v err=%v", started, err) } - if _, err := s.DB.ExecContext(ctx, `UPDATE automation_runs SET lease_expires_at=0 WHERE id=?`, id); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE automation_runs SET lease_expires_at=0 WHERE id=?`, id); err != nil { t.Fatal(err) } + // recoveredID、started、err 保存recoveredID、started、err,供当前处理流程使用 recoveredID, started, err := s.Automation.TryStartRun(ctx, run) if err != nil || !started || recoveredID != id { t.Fatalf("legacy/stale running row should recover: id=%d started=%v err=%v", recoveredID, started, err) } + // recoveredRun、err 保存recoveredRun、err,供当前处理流程使用 recoveredRun, err := s.Automation.GetRun(ctx, id) if err != nil { t.Fatal(err) } - if err := s.Automation.FinishRun(ctx, id, recoveredRun.AttemptCount, "failed", 0, "temporary"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.FinishRun(ctx, id, recoveredRun.AttemptCount, "failed", 0, "temporary"); err != nil { t.Fatal(err) } if _, started, err = s.Automation.TryStartRun(ctx, run); err != nil || started { t.Fatalf("failed run must honor retry delay: started=%v err=%v", started, err) } - if _, err := s.DB.ExecContext(ctx, `UPDATE automation_runs SET next_retry_at=0 WHERE id=?`, id); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE automation_runs SET next_retry_at=0 WHERE id=?`, id); err != nil { t.Fatal(err) } if _, started, err = s.Automation.TryStartRun(ctx, run); err != nil || !started { t.Fatalf("unsent failed run should retry: started=%v err=%v", started, err) } + // retriedRun、err 保存retriedRun、err,供当前处理流程使用 retriedRun, err := s.Automation.GetRun(ctx, id) if err != nil { t.Fatal(err) } - if err := s.Automation.FinishRun(ctx, id, retriedRun.AttemptCount, "failed", 1, "partial"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.FinishRun(ctx, id, retriedRun.AttemptCount, "failed", 1, "partial"); err != nil { t.Fatal(err) } if _, started, err = s.Automation.TryStartRun(ctx, run); err != nil || started { @@ -457,86 +537,115 @@ func TestAutomation_TryStartRunRecoversStaleAndUnsentFailedRuns(t *testing.T) { } } +// TestAutomationRunAttemptFencesStaleWorker 负责Test自动化运行尝试次数FencesStale工作器相关处理。 func TestAutomationRunAttemptFencesStaleWorker(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "i1", "paid", true, 100, AutomationActionInput{ActionType: "send_text", MessageTemplate: "x", Enabled: true})) if err != nil { t.Fatal(err) } + // runID、started、err 保存运行ID、started、err,供当前处理流程使用 runID, started, err := s.Automation.TryStartRun(ctx, AutomationRun{ RuleID: ruleID, CookieID: cid, TriggerType: "paid", TriggerKey: "attempt-fence", LeaseExpiresAt: 1, }) if err != nil || !started { t.Fatalf("start=%v err=%v", started, err) } + // stale、err 保存stale、err,供当前处理流程使用 stale, err := s.Automation.GetRun(ctx, runID) if err != nil || stale.AttemptCount != 1 { t.Fatalf("stale run=%+v err=%v", stale, err) } - if _, err := s.DB.ExecContext(ctx, `UPDATE automation_runs SET lease_expires_at=0 WHERE id=?`, runID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE automation_runs SET lease_expires_at=0 WHERE id=?`, runID); err != nil { t.Fatal(err) } + // claimed、err 保存claimed、err,供当前处理流程使用 claimed, err := s.Automation.ClaimRecoveryRun(ctx, runID, time.Now().UTC().Add(time.Minute).Unix()) if err != nil || !claimed { t.Fatalf("claim recovery=%v err=%v", claimed, err) } + // current、err 保存current、err,供当前处理流程使用 current, err := s.Automation.GetRun(ctx, runID) if err != nil || current.AttemptCount != 2 { t.Fatalf("current run=%+v err=%v", current, err) } - if ok, err := s.Automation.StartRunAction(ctx, runID, stale.AttemptCount, 0, time.Now().Add(time.Minute).Unix()); err != nil || ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Automation.StartRunAction(ctx, runID, stale.AttemptCount, 0, time.Now().Add(time.Minute).Unix()); err != nil || ok { t.Fatalf("stale worker must not start action: ok=%v err=%v", ok, err) } - if ok, err := s.Automation.StartRunAction(ctx, runID, current.AttemptCount, 0, time.Now().Add(time.Minute).Unix()); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Automation.StartRunAction(ctx, runID, current.AttemptCount, 0, time.Now().Add(time.Minute).Unix()); err != nil || !ok { t.Fatalf("current worker start: ok=%v err=%v", ok, err) } - if err := s.Automation.FinishRun(ctx, runID, stale.AttemptCount, "failed", 0, "stale"); !errors.Is(err, ErrAutomationRunLeaseLost) { + if // err 保存err,供当前处理流程使用 + err := s.Automation.FinishRun(ctx, runID, stale.AttemptCount, "failed", 0, "stale"); !errors.Is(err, ErrAutomationRunLeaseLost) { t.Fatalf("stale finish err=%v", err) } - if err := s.Automation.QuarantineRun(ctx, runID, stale.AttemptCount, "stale"); !errors.Is(err, ErrAutomationRunLeaseLost) { + if // err 保存err,供当前处理流程使用 + err := s.Automation.QuarantineRun(ctx, runID, stale.AttemptCount, "stale"); !errors.Is(err, ErrAutomationRunLeaseLost) { t.Fatalf("stale quarantine err=%v", err) } + // afterStale、err 保存afterStale、err,供当前处理流程使用 afterStale, err := s.Automation.GetRun(ctx, runID) if err != nil || afterStale.Status != "running" || !afterStale.ActionStarted || afterStale.AttemptCount != current.AttemptCount { t.Fatalf("stale worker changed current run: %+v err=%v", afterStale, err) } - if err := s.Automation.AdvanceRunAction(ctx, runID, current.AttemptCount, 0, 1); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.AdvanceRunAction(ctx, runID, current.AttemptCount, 0, 1); err != nil { t.Fatal(err) } - if err := s.Automation.FinishRun(ctx, runID, current.AttemptCount, "success", 1, ""); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.FinishRun(ctx, runID, current.AttemptCount, "success", 1, ""); err != nil { t.Fatal(err) } } +// TestPostponeRecoveryRunCannotOverwriteNewOwnerLease 负责TestPostponeRecovery运行CannotOverwriteNew所有者Lease相关处理。 func TestPostponeRecoveryRunCannotOverwriteNewOwnerLease(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) + // ruleID 保存规则ID,供当前处理流程使用 ruleID, _ := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "item", "paid", true, 0)) + // runID、started、err 保存运行ID、started、err,供当前处理流程使用 runID, started, err := s.Automation.TryStartRun(ctx, AutomationRun{RuleID: ruleID, CookieID: cid, TriggerType: "paid", TriggerKey: "postpone-fence"}) if err != nil || !started { t.Fatalf("start run: id=%d started=%v err=%v", runID, started, err) } + // stale、err 保存stale、err,供当前处理流程使用 stale, err := s.Automation.GetRun(ctx, runID) if err != nil { t.Fatal(err) } - if _, err := s.DB.ExecContext(ctx, `UPDATE automation_runs SET lease_expires_at=0 WHERE id=?`, runID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE automation_runs SET lease_expires_at=0 WHERE id=?`, runID); err != nil { t.Fatal(err) } + // newLease 保存newLease,供当前处理流程使用 newLease := time.Now().UTC().Add(5 * time.Minute).Unix() + // claimed、err 保存claimed、err,供当前处理流程使用 claimed, err := s.Automation.ClaimRecoveryRun(ctx, runID, newLease) if err != nil || !claimed { t.Fatalf("claim=%v err=%v", claimed, err) } - if err := s.Automation.PostponeRecoveryRun(ctx, runID, stale.AttemptCount, time.Now().UTC().Add(time.Minute).Unix()); !errors.Is(err, ErrAutomationRunLeaseLost) { + if // err 保存err,供当前处理流程使用 + err := s.Automation.PostponeRecoveryRun(ctx, runID, stale.AttemptCount, time.Now().UTC().Add(time.Minute).Unix()); !errors.Is(err, ErrAutomationRunLeaseLost) { t.Fatalf("stale postpone err=%v want lease lost", err) } + // current、err 保存current、err,供当前处理流程使用 current, err := s.Automation.GetRun(ctx, runID) if err != nil || current.LeaseExpiresAt != newLease { t.Fatalf("new owner lease was overwritten: run=%+v err=%v", current, err) @@ -545,42 +654,55 @@ func TestPostponeRecoveryRunCannotOverwriteNewOwnerLease(t *testing.T) { // TestValidJSON validJSON 的非法 JSON 兜底为 {}。 func TestValidJSON(t *testing.T) { - if got := validJSON(""); got != "{}" { + if // got 保存got,供当前处理流程使用 + got := validJSON(""); got != "{}" { t.Errorf("validJSON('')=%q want {}", got) } - if got := validJSON("not json"); got != "{}" { + if // got 保存got,供当前处理流程使用 + got := validJSON("not json"); got != "{}" { t.Errorf("validJSON('not json')=%q want {}", got) } - if got := validJSON(`{"x":1}`); got != `{"x":1}` { + if // got 保存got,供当前处理流程使用 + got := validJSON(`{"x":1}`); got != `{"x":1}` { t.Errorf("validJSON 合法 JSON 应原样: %q", got) } } +// TestAutomationIssuesCanBeListedAndResolved 负责Test自动化问题列表CanBeListedAndResolved相关处理。 func TestAutomationIssuesCanBeListedAndResolved(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "", "buyer_reviewed", true, 100, AutomationActionInput{ActionType: "send_text", MessageTemplate: "x", Enabled: true})) if err != nil { t.Fatal(err) } + // runID、started、err 保存运行ID、started、err,供当前处理流程使用 runID, started, err := s.Automation.TryStartRun(ctx, AutomationRun{RuleID: ruleID, CookieID: cid, OrderID: "issue-order", TriggerType: "buyer_reviewed", TriggerKey: "issue-key", RawEventJSON: `{}`, LeaseExpiresAt: 1}) if err != nil || !started { t.Fatalf("start=%v err=%v", started, err) } - if ok, err := s.Automation.StartRunAction(ctx, runID, 1, 0, 1); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Automation.StartRunAction(ctx, runID, 1, 0, 1); err != nil || !ok { t.Fatalf("action start=%v err=%v", ok, err) } - if err := s.Automation.QuarantineRunResult(ctx, runID, 1, 1, "unknown"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.QuarantineRunResult(ctx, runID, 1, 1, "unknown"); err != nil { t.Fatal(err) } - if err := s.Automation.DeferTask(ctx, DeferredAutomationTask{TaskKey: "dead", CookieID: cid, TriggerType: "buyer_reviewed", TaskJSON: `{}`, DueAt: 0}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.DeferTask(ctx, DeferredAutomationTask{TaskKey: "dead", CookieID: cid, TriggerType: "buyer_reviewed", TaskJSON: `{}`, DueAt: 0}); err != nil { t.Fatal(err) } _, _ = s.DB.ExecContext(ctx, `UPDATE automation_pending_tasks SET status='dead_letter',attempt_count=5,error_message='bad' WHERE task_key='dead'`) + // runs、tasks、err 保存runs、tasks、err,供当前处理流程使用 runs, tasks, err := s.Automation.ListIssues(ctx, uid) if err != nil || len(runs) != 1 || len(tasks) != 1 { t.Fatalf("runs=%+v tasks=%+v err=%v", runs, tasks, err) @@ -591,29 +713,38 @@ func TestAutomationIssuesCanBeListedAndResolved(t *testing.T) { if containsString(runs[0].AllowedResolutions, "retry") { t.Fatalf("unknown external result must not allow retry: %+v", runs[0]) } - if err := s.Automation.ResolveRunIssue(ctx, uid, runID, "retry"); err == nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.ResolveRunIssue(ctx, uid, runID, "retry"); err == nil { t.Fatal("unknown external result must reject retry") } - if err := s.Automation.ResolveRunIssue(ctx, uid, runID, "continue"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.ResolveRunIssue(ctx, uid, runID, "continue"); err != nil { t.Fatal(err) } + // run 保存运行,供当前处理流程使用 run, _ := s.Automation.GetRun(ctx, runID) if run.Status != "running" || run.ActionStarted || run.ActionCursor != 1 { t.Fatalf("resolved run=%+v", run) } - if err := s.Automation.PostponeRecoveryRun(ctx, runID, run.AttemptCount, 4102444800); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.PostponeRecoveryRun(ctx, runID, run.AttemptCount, 4102444800); err != nil { t.Fatal(err) } + // due、err 保存due、err,供当前处理流程使用 due, err := s.Automation.DueRecoveryRuns(ctx, 10) if err != nil || len(due) != 0 { t.Fatalf("postponed run must leave the due queue: %+v err=%v", due, err) } - if err := s.Automation.ResolveDeferredIssue(ctx, uid, tasks[0].ID, true); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.ResolveDeferredIssue(ctx, uid, tasks[0].ID, true); err != nil { t.Fatal(err) } + // status 保存状态,供当前处理流程使用 var status string + // attempts 保存尝试次数,供当前处理流程使用 var attempts int - if err := s.DB.QueryRowContext(ctx, `SELECT status,attempt_count FROM automation_pending_tasks WHERE id=?`, tasks[0].ID).Scan(&status, &attempts); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRowContext(ctx, `SELECT status,attempt_count FROM automation_pending_tasks WHERE id=?`, tasks[0].ID).Scan(&status, &attempts); err != nil { t.Fatal(err) } if status != "pending" || attempts != 0 { @@ -621,24 +752,32 @@ func TestAutomationIssuesCanBeListedAndResolved(t *testing.T) { } } +// TestInvalidAutomationSnapshotCanOnlyBeCanceled 负责TestInvalid自动化SnapshotCanOnlyBeCanceled相关处理。 func TestInvalidAutomationSnapshotCanOnlyBeCanceled(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "", "buyer_reviewed", true, 100, AutomationActionInput{ActionType: "send_text", MessageTemplate: "x", Enabled: true})) if err != nil { t.Fatal(err) } + // runID、started、err 保存运行ID、started、err,供当前处理流程使用 runID, started, err := s.Automation.TryStartRun(ctx, AutomationRun{RuleID: ruleID, CookieID: cid, TriggerType: "buyer_reviewed", TriggerKey: "invalid-snapshot", RawEventJSON: `{}`, LeaseExpiresAt: 1}) if err != nil || !started { t.Fatalf("start=%v err=%v", started, err) } - if err := s.Automation.QuarantineRun(ctx, runID, 1, "历史运行数据无法安全解析,已移入人工检查"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.QuarantineRun(ctx, runID, 1, "历史运行数据无法安全解析,已移入人工检查"); err != nil { t.Fatal(err) } + // runs、err 保存runs、err,供当前处理流程使用 runs, _, err := s.Automation.ListIssues(ctx, uid) if err != nil || len(runs) != 1 { t.Fatalf("runs=%+v err=%v", runs, err) @@ -646,24 +785,31 @@ func TestInvalidAutomationSnapshotCanOnlyBeCanceled(t *testing.T) { if runs[0].IssueKind != "invalid_snapshot" || len(runs[0].AllowedResolutions) != 1 || runs[0].AllowedResolutions[0] != "cancel" { t.Fatalf("policy=%+v", runs[0]) } - if err := s.Automation.ResolveRunIssue(ctx, uid, runID, "retry"); err == nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.ResolveRunIssue(ctx, uid, runID, "retry"); err == nil { t.Fatal("invalid snapshot must reject retry") } + // run 保存运行,供当前处理流程使用 run, _ := s.Automation.GetRun(ctx, runID) if run.Status != "needs_review" { t.Fatalf("rejected resolution changed run: %+v", run) } - if err := s.Automation.ResolveRunIssue(ctx, uid, runID, "cancel"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.ResolveRunIssue(ctx, uid, runID, "cancel"); err != nil { t.Fatal(err) } } +// TestAutomationIssuePolicyForDisabledRuleRequiresReenableBeforeRetry 负责Test自动化问题PolicyForDisabled规则RequiresReenableBefore重试相关处理。 func TestAutomationIssuePolicyForDisabledRuleRequiresReenableBeforeRetry(t *testing.T) { + // rawBytes、err 保存原始Bytes、err,供当前处理流程使用 rawBytes, err := json.Marshal(struct{ AccountID string }{AccountID: "acc1"}) if err != nil { t.Fatal(err) } + // raw 保存原始,供当前处理流程使用 raw := string(rawBytes) + // kind、allowed 保存kind、allowed,供当前处理流程使用 kind, allowed := automationIssuePolicy(raw, false, false, 0, "自动化规则不存在或已停用,无法恢复") if kind != "rule_unavailable" || containsString(allowed, "retry") || !containsString(allowed, "cancel") { t.Fatalf("disabled policy kind=%q allowed=%v", kind, allowed) @@ -674,92 +820,126 @@ func TestAutomationIssuePolicyForDisabledRuleRequiresReenableBeforeRetry(t *test } } +// TestDeferTaskRevivesDeadLetterWithFreshAttemptBudget 负责TestDefer任务RevivesDeadLetterWithFresh尝试次数Budget相关处理。 func TestDeferTaskRevivesDeadLetterWithFreshAttemptBudget(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) + // task 保存任务,供当前处理流程使用 task := DeferredAutomationTask{TaskKey: "same", CookieID: cid, TriggerType: "buyer_reviewed", TaskJSON: `{"v":1}`, DueAt: 0} - if err := s.Automation.DeferTask(ctx, task); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.DeferTask(ctx, task); err != nil { t.Fatal(err) } _, _ = s.DB.ExecContext(ctx, `UPDATE automation_pending_tasks SET status='dead_letter',attempt_count=5 WHERE task_key='same'`) task.TaskJSON = `{"v":2}` - if err := s.Automation.DeferTask(ctx, task); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.DeferTask(ctx, task); err != nil { t.Fatal(err) } + // claimed、err 保存claimed、err,供当前处理流程使用 claimed, err := s.Automation.ClaimDueDeferredTasks(ctx, 10) if err != nil || len(claimed) != 1 { t.Fatalf("claimed=%+v err=%v", claimed, err) } } +// TestDeferredRetryBackoffAndCredentialWake 负责TestDeferred重试BackoffAndCredentialWake相关处理。 func TestDeferredRetryBackoffAndCredentialWake(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) - if err := s.Automation.DeferTask(ctx, DeferredAutomationTask{TaskKey: "wake-task", CookieID: cid, TriggerType: "order_paid", TaskJSON: `{}`, DueAt: 0, ErrorMessage: "FAIL_SYS_SESSION_EXPIRED"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.DeferTask(ctx, DeferredAutomationTask{TaskKey: "wake-task", CookieID: cid, TriggerType: "order_paid", TaskJSON: `{}`, DueAt: 0, ErrorMessage: "FAIL_SYS_SESSION_EXPIRED"}); err != nil { t.Fatal(err) } + // claimed、err 保存claimed、err,供当前处理流程使用 claimed, err := s.Automation.ClaimDueDeferredTasks(ctx, 1) if err != nil || len(claimed) != 1 { t.Fatalf("claim=%v err=%v", claimed, err) } + // before 保存before,供当前处理流程使用 before := time.Now().UTC().Unix() - if err := s.Automation.FinishDeferredTask(ctx, claimed[0].ID, claimed[0].ClaimVersion, false, "session expired"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.FinishDeferredTask(ctx, claimed[0].ID, claimed[0].ClaimVersion, false, "session expired"); err != nil { t.Fatal(err) } + // dueAt 保存dueAt,供当前处理流程使用 var dueAt int64 - if err := s.DB.QueryRowContext(ctx, `SELECT due_at FROM automation_pending_tasks WHERE id=?`, claimed[0].ID).Scan(&dueAt); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRowContext(ctx, `SELECT due_at FROM automation_pending_tasks WHERE id=?`, claimed[0].ID).Scan(&dueAt); err != nil { t.Fatal(err) } if dueAt < before+int64((5*time.Minute)/time.Second)-1 { t.Fatalf("first retry due_at=%d before=%d", dueAt, before) } - if err := s.Automation.WakeCredentialBlocked(ctx, cid); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.WakeCredentialBlocked(ctx, cid); err != nil { t.Fatal(err) } - if err := s.Automation.DeferTask(ctx, DeferredAutomationTask{TaskKey: "ws-wake", CookieID: cid, TriggerType: "buyer_reviewed", TaskJSON: `{}`, DueAt: before + 3600, ErrorMessage: "当前没有可用 WebSocket 连接"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.DeferTask(ctx, DeferredAutomationTask{TaskKey: "ws-wake", CookieID: cid, TriggerType: "buyer_reviewed", TaskJSON: `{}`, DueAt: before + 3600, ErrorMessage: "当前没有可用 WebSocket 连接"}); err != nil { t.Fatal(err) } - if err := s.Automation.WakeCredentialBlocked(ctx, cid); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.WakeCredentialBlocked(ctx, cid); err != nil { t.Fatal(err) } - if err := s.DB.QueryRowContext(ctx, `SELECT due_at FROM automation_pending_tasks WHERE task_key='ws-wake'`).Scan(&dueAt); err != nil || dueAt != 0 { + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRowContext(ctx, `SELECT due_at FROM automation_pending_tasks WHERE task_key='ws-wake'`).Scan(&dueAt); err != nil || dueAt != 0 { t.Fatalf("WS 恢复必须立即唤醒任务: due_at=%d err=%v", dueAt, err) } - if err := s.DB.QueryRowContext(ctx, `SELECT due_at FROM automation_pending_tasks WHERE id=?`, claimed[0].ID).Scan(&dueAt); err != nil || dueAt != 0 { + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRowContext(ctx, `SELECT due_at FROM automation_pending_tasks WHERE id=?`, claimed[0].ID).Scan(&dueAt); err != nil || dueAt != 0 { t.Fatalf("wake due_at=%d err=%v", dueAt, err) } - if err := s.Automation.DeferTask(ctx, DeferredAutomationTask{TaskKey: "intentional-delay", CookieID: cid, TriggerType: "buyer_reviewed", TaskJSON: `{}`, DueAt: before + 3600}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.DeferTask(ctx, DeferredAutomationTask{TaskKey: "intentional-delay", CookieID: cid, TriggerType: "buyer_reviewed", TaskJSON: `{}`, DueAt: before + 3600}); err != nil { t.Fatal(err) } - if err := s.Automation.WakeCredentialBlocked(ctx, cid); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.WakeCredentialBlocked(ctx, cid); err != nil { t.Fatal(err) } - if err := s.DB.QueryRowContext(ctx, `SELECT due_at FROM automation_pending_tasks WHERE task_key='intentional-delay'`).Scan(&dueAt); err != nil || dueAt != before+3600 { + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRowContext(ctx, `SELECT due_at FROM automation_pending_tasks WHERE task_key='intentional-delay'`).Scan(&dueAt); err != nil || dueAt != before+3600 { t.Fatalf("intentional delay must not be woken: due_at=%d err=%v", dueAt, err) } } +// TestDeferredTaskFencingRejectsStaleWorker 负责TestDeferred任务FencingRejectsStale工作器相关处理。 func TestDeferredTaskFencingRejectsStaleWorker(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) - if err := s.Automation.DeferTask(ctx, DeferredAutomationTask{ + if // err 保存err,供当前处理流程使用 + err := s.Automation.DeferTask(ctx, DeferredAutomationTask{ TaskKey: "fenced-task", CookieID: cid, TriggerType: "buyer_reviewed", TaskJSON: `{}`, DueAt: 0, }); err != nil { t.Fatal(err) } + // first、err 保存first、err,供当前处理流程使用 first, err := s.Automation.ClaimDueDeferredTasks(ctx, 1) if err != nil || len(first) != 1 { t.Fatalf("first claim=%+v err=%v", first, err) } - if _, err := s.DB.ExecContext(ctx, `UPDATE automation_pending_tasks SET lease_expires_at=0 WHERE id=?`, first[0].ID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE automation_pending_tasks SET lease_expires_at=0 WHERE id=?`, first[0].ID); err != nil { t.Fatal(err) } + // second、err 保存second、err,供当前处理流程使用 second, err := s.Automation.ClaimDueDeferredTasks(ctx, 1) if err != nil || len(second) != 1 { t.Fatalf("second claim=%+v err=%v", second, err) @@ -767,27 +947,36 @@ func TestDeferredTaskFencingRejectsStaleWorker(t *testing.T) { if second[0].ClaimVersion <= first[0].ClaimVersion { t.Fatalf("claim versions first=%d second=%d", first[0].ClaimVersion, second[0].ClaimVersion) } - if err := s.Automation.FinishDeferredTask(ctx, first[0].ID, first[0].ClaimVersion, true, ""); !errors.Is(err, ErrDeferredTaskLeaseLost) { + if // err 保存err,供当前处理流程使用 + err := s.Automation.FinishDeferredTask(ctx, first[0].ID, first[0].ClaimVersion, true, ""); !errors.Is(err, ErrDeferredTaskLeaseLost) { t.Fatalf("stale finish err=%v want ErrDeferredTaskLeaseLost", err) } - if err := s.Automation.RenewDeferredTaskLease(ctx, second[0].ID, second[0].ClaimVersion, time.Now().Add(time.Minute).Unix()); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.RenewDeferredTaskLease(ctx, second[0].ID, second[0].ClaimVersion, time.Now().Add(time.Minute).Unix()); err != nil { t.Fatalf("current renew: %v", err) } - if err := s.Automation.FinishDeferredTask(ctx, second[0].ID, second[0].ClaimVersion, true, ""); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.FinishDeferredTask(ctx, second[0].ID, second[0].ClaimVersion, true, ""); err != nil { t.Fatalf("current finish: %v", err) } } +// TestAutomationRuleDeleteRejectsActiveRun 负责Test自动化规则DeleteRejectsActive运行相关处理。 func TestAutomationRuleDeleteRejectsActiveRun(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) + // ruleID 保存规则ID,供当前处理流程使用 ruleID, _ := s.Automation.Create(ctx, makeAutomationRule(cid, uid, "", "buyer_reviewed", true, 100, AutomationActionInput{ActionType: "send_text", MessageTemplate: "x", Enabled: true})) _, _, _ = s.Automation.TryStartRun(ctx, AutomationRun{RuleID: ruleID, CookieID: cid, TriggerType: "buyer_reviewed", TriggerKey: "active", RawEventJSON: `{}`, LeaseExpiresAt: 1}) - if err := s.Automation.Delete(ctx, uid, ruleID); !errors.Is(err, ErrAutomationRunActive) { + if // err 保存err,供当前处理流程使用 + err := s.Automation.Delete(ctx, uid, ruleID); !errors.Is(err, ErrAutomationRunActive) { t.Fatalf("delete err=%v", err) } } diff --git a/internal/db/chat.go b/internal/db/chat.go index 8999162..fa69dcf 100644 --- a/internal/db/chat.go +++ b/internal/db/chat.go @@ -9,6 +9,7 @@ import ( "time" ) +// ChatSession 保存聊天会话,供当前处理流程使用 type ChatSession struct { CookieID string `json:"account_id"` ChatID string `json:"chat_id"` @@ -22,6 +23,7 @@ type ChatSession struct { UnreadCount int `json:"unread_count"` } +// ChatMessage 保存聊天消息,供当前处理流程使用 type ChatMessage struct { ID int64 `json:"id"` CookieID string `json:"account_id"` @@ -36,22 +38,29 @@ type ChatMessage struct { SentAt int64 `json:"sent_at"` } +// ChatStore 保存聊天Store,供当前处理流程使用 type ChatStore struct { DB *sql.DB Dialect Dialect } +// UpsertSession 负责Upsert会话相关处理。 func (s *ChatStore) UpsertSession(ctx context.Context, session ChatSession) error { + // now 保存now,供当前处理流程使用 now := time.Now().UTC().Unix() + // prefix 保存prefix,供当前处理流程使用 prefix := dialectInsertIgnorePrefix(s.Dialect) + // query 保存查询,供当前处理流程使用 query := prefix + ` INTO chat_sessions (cookie_id,chat_id,buyer_id,buyer_name,buyer_avatar_url,item_id,item_title,last_message,last_message_at,unread_count,created_at,updated_at) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)` + dialectInsertIgnore(s.Dialect, []string{"cookie_id", "chat_id"}) - if _, err := s.DB.ExecContext(ctx, query, session.CookieID, session.ChatID, session.BuyerID, session.BuyerName, + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, query, session.CookieID, session.ChatID, session.BuyerID, session.BuyerName, session.BuyerAvatar, session.ItemID, session.ItemTitle, session.LastMessage, session.LastMessageAt, session.UnreadCount, now, now); err != nil { return err } + // err 保存err,供当前处理流程使用 _, err := s.DB.ExecContext(ctx, `UPDATE chat_sessions SET buyer_id=CASE WHEN ?<>'' THEN ? ELSE buyer_id END, buyer_name=CASE WHEN ?<>'' THEN ? ELSE buyer_name END, @@ -68,7 +77,9 @@ func (s *ChatStore) UpsertSession(ctx context.Context, session ChatSession) erro return err } +// DeleteSession 删除会话。 func (s *ChatStore) DeleteSession(ctx context.Context, cookieID, chatID string) error { + // err 保存err,供当前处理流程使用 _, err := s.DB.ExecContext(ctx, `DELETE FROM chat_sessions WHERE cookie_id=? AND chat_id=?`, cookieID, chatID) return err } @@ -76,7 +87,9 @@ func (s *ChatStore) DeleteSession(ctx context.Context, cookieID, chatID string) // DeleteEmptySessions removes conversation shells returned by IM pagination // with visible=0 and no lastMessage. Older versions persisted these shells as // "暂无消息", although the official UI never renders them. +// DeleteEmptySessions 删除EmptySessions。 func (s *ChatStore) DeleteEmptySessions(ctx context.Context, cookieID string) error { + // err 保存err,供当前处理流程使用 _, err := s.DB.ExecContext(ctx, `DELETE FROM chat_sessions WHERE cookie_id=? AND (last_message='' OR last_message='暂无消息') AND NOT EXISTS (SELECT 1 FROM chat_messages m WHERE m.cookie_id=chat_sessions.cookie_id AND m.chat_id=chat_sessions.chat_id)`, cookieID) @@ -86,14 +99,18 @@ func (s *ChatStore) DeleteEmptySessions(ctx context.Context, cookieID string) er // SyncSessionSummary applies the authoritative last-message timestamp from the // official conversation response. observedModifyAt guards against overwriting // a genuinely newer live message that arrived after that response was built. +// SyncSessionSummary 同步会话Summary。 func (s *ChatStore) SyncSessionSummary(ctx context.Context, cookieID, chatID, summary string, sentAt, observedModifyAt int64, unread int) error { + // err 保存err,供当前处理流程使用 _, err := s.DB.ExecContext(ctx, `UPDATE chat_sessions SET last_message=?,last_message_at=?,unread_count=?,updated_at=? WHERE cookie_id=? AND chat_id=? AND last_message_at<=?`, summary, sentAt, unread, time.Now().UTC().Unix(), cookieID, chatID, observedModifyAt) return err } +// UpdateSessionIdentity 更新会话Identity。 func (s *ChatStore) UpdateSessionIdentity(ctx context.Context, cookieID, chatID, buyerID, buyerName, avatarURL string) error { + // err 保存err,供当前处理流程使用 _, err := s.DB.ExecContext(ctx, `UPDATE chat_sessions SET buyer_id=CASE WHEN ?<>'' THEN ? ELSE buyer_id END, buyer_name=CASE WHEN ?<>'' THEN ? ELSE buyer_name END, @@ -106,8 +123,11 @@ func (s *ChatStore) UpdateSessionIdentity(ctx context.Context, cookieID, chatID, // LatestUnmaskedPeerName recovers the most recent real nickname observed in // message history. Conversation summaries and profile APIs may return masked // names such as x***3, while older message extensions still contain the nick. +// LatestUnmaskedPeerName 负责LatestUnmaskedPeer名称相关处理。 func (s *ChatStore) LatestUnmaskedPeerName(ctx context.Context, cookieID, chatID string) (string, error) { + // name 保存名称,供当前处理流程使用 var name string + // err 保存err,供当前处理流程使用 err := s.DB.QueryRowContext(ctx, `SELECT sender_name FROM chat_messages WHERE cookie_id=? AND chat_id=? AND direction='incoming' AND sender_name<>'' AND sender_name NOT LIKE '%***%' AND message_type<>'system' @@ -122,6 +142,7 @@ func (s *ChatStore) LatestUnmaskedPeerName(ctx context.Context, cookieID, chatID // SaveMessage inserts a message idempotently and updates its conversation only // when the message was new. This keeps retries from inflating unread counters. +// SaveMessage 保存消息。 func (s *ChatStore) SaveMessage(ctx context.Context, session ChatSession, message ChatMessage, unread bool) (*ChatMessage, bool, error) { if s == nil || s.DB == nil { return nil, false, errors.New("聊天存储未初始化") @@ -136,7 +157,9 @@ func (s *ChatStore) SaveMessage(ctx context.Context, session ChatSession, messag message.SentAt = time.Now().UTC().UnixMilli() } message.CookieID, message.ChatID = session.CookieID, session.ChatID + // now 保存now,供当前处理流程使用 now := time.Now().UTC().Unix() + // tx、err 保存tx、err,供当前处理流程使用 tx, err := s.DB.BeginTx(ctx, nil) if err != nil { return nil, false, err @@ -144,32 +167,41 @@ func (s *ChatStore) SaveMessage(ctx context.Context, session ChatSession, messag defer tx.Rollback() // The composite foreign key on chat_messages requires the session to exist // first. Insert an empty shell without touching an existing conversation. + // sessionPrefix 保存会话Prefix,供当前处理流程使用 sessionPrefix := dialectInsertIgnorePrefix(s.Dialect) + // sessionInsert 保存会话Insert,供当前处理流程使用 sessionInsert := sessionPrefix + ` INTO chat_sessions (cookie_id,chat_id,buyer_id,buyer_name,buyer_avatar_url,item_id,item_title,last_message,last_message_at,unread_count,created_at,updated_at) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)` + dialectInsertIgnore(s.Dialect, []string{"cookie_id", "chat_id"}) - if _, err := tx.ExecContext(ctx, sessionInsert, session.CookieID, session.ChatID, session.BuyerID, + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, sessionInsert, session.CookieID, session.ChatID, session.BuyerID, session.BuyerName, session.BuyerAvatar, session.ItemID, session.ItemTitle, "", int64(0), 0, now, now); err != nil { return nil, false, fmt.Errorf("建立聊天会话: %w", err) } + // prefix 保存prefix,供当前处理流程使用 prefix := dialectInsertIgnorePrefix(s.Dialect) + // query 保存查询,供当前处理流程使用 query := prefix + ` INTO chat_messages (cookie_id,chat_id,message_key,direction,sender_id,sender_name,message_type,content,status,sent_at,created_at) VALUES(?,?,?,?,?,?,?,?,?,?,?)` + dialectInsertIgnore(s.Dialect, []string{"cookie_id", "message_key"}) + // res、err 保存res、err,供当前处理流程使用 res, err := tx.ExecContext(ctx, query, message.CookieID, message.ChatID, message.MessageKey, message.Direction, message.SenderID, message.SenderName, message.MessageType, message.Content, message.Status, message.SentAt, now) if err != nil { return nil, false, fmt.Errorf("保存聊天消息: %w", err) } + // inserted 保存inserted,供当前处理流程使用 inserted, _ := res.RowsAffected() if inserted > 0 { + // unreadDelta 保存unreadDelta,供当前处理流程使用 unreadDelta := 0 if unread { unreadDelta = 1 } - if _, err := tx.ExecContext(ctx, `UPDATE chat_sessions SET buyer_id=?,buyer_name=?,buyer_avatar_url=?, + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `UPDATE chat_sessions SET buyer_id=?,buyer_name=?,buyer_avatar_url=?, item_id=?,item_title=?,last_message=CASE WHEN last_message_at<=? THEN ? ELSE last_message END, last_message_at=CASE WHEN last_message_at<=? THEN ? ELSE last_message_at END, unread_count=unread_count+?,updated_at=? @@ -179,15 +211,20 @@ func (s *ChatStore) SaveMessage(ctx context.Context, session ChatSession, messag return nil, false, fmt.Errorf("更新聊天会话: %w", err) } } - if err := tx.Commit(); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.Commit(); err != nil { return nil, false, err } + // stored、err 保存stored、err,供当前处理流程使用 stored, err := s.GetMessageByKey(ctx, message.CookieID, message.MessageKey) return stored, inserted > 0, err } +// GetMessageByKey 读取消息ByKey。 func (s *ChatStore) GetMessageByKey(ctx context.Context, cookieID, key string) (*ChatMessage, error) { + // m 保存m,供当前处理流程使用 var m ChatMessage + // err 保存err,供当前处理流程使用 err := s.DB.QueryRowContext(ctx, `SELECT id,cookie_id,chat_id,message_key,direction,sender_id,sender_name,message_type,content,status,sent_at FROM chat_messages WHERE cookie_id=? AND message_key=?`, cookieID, key).Scan( &m.ID, &m.CookieID, &m.ChatID, &m.MessageKey, &m.Direction, &m.SenderID, &m.SenderName, @@ -200,16 +237,20 @@ func (s *ChatStore) GetMessageByKey(ctx context.Context, cookieID, key string) ( // UpdateMessageType refreshes the classification of an already persisted // message when a later history response exposes richer protocol metadata. +// UpdateMessageType 更新消息类型。 func (s *ChatStore) UpdateMessageType(ctx context.Context, cookieID, key, messageType string) error { + // err 保存err,供当前处理流程使用 _, err := s.DB.ExecContext(ctx, `UPDATE chat_messages SET message_type=? WHERE cookie_id=? AND message_key=?`, messageType, cookieID, key) return err } +// ListSessions 读取Sessions。 func (s *ChatStore) ListSessions(ctx context.Context, userID int64, cookieID string, limit int) ([]ChatSession, error) { if limit <= 0 || limit > 500 { limit = 200 } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := s.DB.QueryContext(ctx, `SELECT cs.cookie_id,cs.chat_id,cs.buyer_id,cs.buyer_name,cs.buyer_avatar_url, cs.item_id,cs.item_title,cs.last_message,cs.last_message_at,cs.unread_count FROM chat_sessions cs JOIN cookies c ON c.id=cs.cookie_id @@ -218,10 +259,13 @@ func (s *ChatStore) ListSessions(ctx context.Context, userID int64, cookieID str return nil, err } defer rows.Close() + // result 保存结果,供当前处理流程使用 var result []ChatSession for rows.Next() { + // row 保存row,供当前处理流程使用 var row ChatSession - if err := rows.Scan(&row.CookieID, &row.ChatID, &row.BuyerID, &row.BuyerName, &row.BuyerAvatar, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&row.CookieID, &row.ChatID, &row.BuyerID, &row.BuyerName, &row.BuyerAvatar, &row.ItemID, &row.ItemTitle, &row.LastMessage, &row.LastMessageAt, &row.UnreadCount); err != nil { return nil, err } @@ -230,13 +274,16 @@ func (s *ChatStore) ListSessions(ctx context.Context, userID int64, cookieID str return result, rows.Err() } +// ListMessages 读取消息列表。 func (s *ChatStore) ListMessages(ctx context.Context, userID int64, cookieID, chatID string, beforeID int64, limit int) ([]ChatMessage, error) { if limit <= 0 || limit > 200 { limit = 50 } + // query 保存查询,供当前处理流程使用 query := `SELECT m.id,m.cookie_id,m.chat_id,m.message_key,m.direction,m.sender_id,m.sender_name,m.message_type,m.content,m.status,m.sent_at FROM chat_messages m JOIN cookies c ON c.id=m.cookie_id WHERE c.user_id=? AND m.cookie_id=? AND m.chat_id=?` + // args 保存args,供当前处理流程使用 args := []any{userID, cookieID, chatID} if beforeID > 0 { query += ` AND (m.sent_at < COALESCE((SELECT older.sent_at FROM chat_messages older WHERE older.id=? AND older.cookie_id=?), m.sent_at) @@ -245,36 +292,45 @@ func (s *ChatStore) ListMessages(ctx context.Context, userID int64, cookieID, ch } query += ` ORDER BY m.sent_at DESC,m.id DESC LIMIT ?` args = append(args, limit) + // rows、err 保存rows、err,供当前处理流程使用 rows, err := s.DB.QueryContext(ctx, query, args...) if err != nil { return nil, err } defer rows.Close() + // result 保存结果,供当前处理流程使用 var result []ChatMessage for rows.Next() { + // m 保存m,供当前处理流程使用 var m ChatMessage - if err := rows.Scan(&m.ID, &m.CookieID, &m.ChatID, &m.MessageKey, &m.Direction, &m.SenderID, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&m.ID, &m.CookieID, &m.ChatID, &m.MessageKey, &m.Direction, &m.SenderID, &m.SenderName, &m.MessageType, &m.Content, &m.Status, &m.SentAt); err != nil { return nil, err } result = append(result, m) } // API returns chronological order while the query remains index-friendly. - for i, j := 0, len(result)-1; i < j; i, j = i+1, j-1 { + for // i、j 保存i、j,供当前处理流程使用 + i, j := 0, len(result)-1; i < j; i, j = i+1, j-1 { result[i], result[j] = result[j], result[i] } return result, rows.Err() } +// MarkRead 负责MarkRead相关处理。 func (s *ChatStore) MarkRead(ctx context.Context, userID int64, cookieID, chatID string) error { + // err 保存err,供当前处理流程使用 _, err := s.DB.ExecContext(ctx, `UPDATE chat_sessions SET unread_count=0,updated_at=? WHERE cookie_id=? AND chat_id=? AND EXISTS(SELECT 1 FROM cookies c WHERE c.id=chat_sessions.cookie_id AND c.user_id=?)`, time.Now().UTC().Unix(), cookieID, chatID, userID) return err } +// UpdateMessageStatus 更新消息状态。 func (s *ChatStore) UpdateMessageStatus(ctx context.Context, cookieID, key, status string) (*ChatMessage, error) { - if _, err := s.DB.ExecContext(ctx, `UPDATE chat_messages SET status=? WHERE cookie_id=? AND message_key=?`, status, cookieID, key); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE chat_messages SET status=? WHERE cookie_id=? AND message_key=?`, status, cookieID, key); err != nil { return nil, err } return s.GetMessageByKey(ctx, cookieID, key) diff --git a/internal/db/cookies.go b/internal/db/cookies.go index 644f6b9..b0b1875 100644 --- a/internal/db/cookies.go +++ b/internal/db/cookies.go @@ -10,6 +10,7 @@ import ( "time" ) +// DisableReasonManual 保存Disable原因Manual,供当前处理流程使用 const DisableReasonManual = "manual" // ErrAlreadyExists 表示创建资源时主键已经存在。调用方不得把它解释为可覆盖。 @@ -24,6 +25,7 @@ type Cookies struct { // AccountSettingsUpdate 表示账号编辑弹窗的一次原子保存。nil 字段保持原值; // ChannelIDs 非 nil 时覆盖通知绑定(空切片表示明确解绑全部)。 +// AccountSettingsUpdate 保存账号设置Update,供当前处理流程使用 type AccountSettingsUpdate struct { UserID int64 Value *string @@ -38,14 +40,18 @@ type AccountSettingsUpdate struct { // UpdateSettings 在一个事务中更新账号字段及通知绑定,避免前端并行请求只成功一部分。 func (c *Cookies) UpdateSettings(ctx context.Context, cookieID string, input AccountSettingsUpdate) (int64, error) { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := c.DB.BeginTx(ctx, nil) if err != nil { return 0, err } defer tx.Rollback() + // ownerID 保存所有者ID,供当前处理流程使用 var ownerID int64 + // metadataJSON 保存metadataJSON,供当前处理流程使用 var metadataJSON string - if err := tx.QueryRowContext(ctx, c.cookieSelectForUpdate(`user_id,COALESCE(metadata_json,'')`), cookieID).Scan(&ownerID, &metadataJSON); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.QueryRowContext(ctx, c.cookieSelectForUpdate(`user_id,COALESCE(metadata_json,'')`), cookieID).Scan(&ownerID, &metadataJSON); err != nil { if errors.Is(err, sql.ErrNoRows) { return 0, ErrNotFound } @@ -55,19 +61,24 @@ func (c *Cookies) UpdateSettings(ctx context.Context, cookieID string, input Acc return 0, ErrForbidden } + // assignments 保存assignments,供当前处理流程使用 assignments := make([]string, 0, 8) + // args 保存args,供当前处理流程使用 args := make([]any, 0, 9) if input.Value != nil { + // encrypted、err 保存encrypted、err,供当前处理流程使用 encrypted, err := c.codec.encrypt("cookie", cookieID, *input.Value) if err != nil { return 0, err } assignments = append(assignments, "value=?") args = append(args, encrypted) + // plainMetadata、err 保存plainMetadata、err,供当前处理流程使用 plainMetadata, err := c.codec.decrypt(cookieMetadataScope, cookieID, metadataJSON) if err != nil { return 0, err } + // cleanMetadata、err 保存cleanMetadata、err,供当前处理流程使用 cleanMetadata, err := c.codec.encrypt(cookieMetadataScope, cookieID, stripCookieSnapshotMetadata(plainMetadata)) if err != nil { return 0, err @@ -83,6 +94,7 @@ func (c *Cookies) UpdateSettings(ctx context.Context, cookieID string, input Acc assignments = append(assignments, "auto_confirm=?") args = append(args, boolToInt(*input.AutoConfirm)) } + // pausedUntil 保存pausedUntil,供当前处理流程使用 pausedUntil := int64(0) if input.PauseDuration != nil { if *input.PauseDuration < 0 || *input.PauseDuration > 1440 { @@ -99,6 +111,7 @@ func (c *Cookies) UpdateSettings(ctx context.Context, cookieID string, input Acc args = append(args, *input.Username) } if input.Password != nil { + // encrypted、err 保存encrypted、err,供当前处理流程使用 encrypted, err := c.codec.encrypt("login-password", cookieID, *input.Password) if err != nil { return 0, err @@ -112,12 +125,14 @@ func (c *Cookies) UpdateSettings(ctx context.Context, cookieID string, input Acc } if len(assignments) > 0 { args = append(args, cookieID, input.UserID) - if _, err := tx.ExecContext(ctx, `UPDATE cookies SET `+strings.Join(assignments, ",")+`,updated_at=CURRENT_TIMESTAMP WHERE id=? AND user_id=?`, args...); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `UPDATE cookies SET `+strings.Join(assignments, ",")+`,updated_at=CURRENT_TIMESTAMP WHERE id=? AND user_id=?`, args...); err != nil { return 0, err } } if input.PauseDuration != nil && *input.PauseDuration == 0 { - if _, err := tx.ExecContext(ctx, `UPDATE automation_pending_tasks SET due_at=0,updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND status='pending'`, cookieID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `UPDATE automation_pending_tasks SET due_at=0,updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND status='pending'`, cookieID); err != nil { return 0, err } } @@ -125,30 +140,39 @@ func (c *Cookies) UpdateSettings(ctx context.Context, cookieID string, input Acc if len(*input.ChannelIDs) > 100 { return 0, fmt.Errorf("单个账号最多绑定 100 个通知渠道") } + // seen 保存seen,供当前处理流程使用 seen := make(map[int64]struct{}, len(*input.ChannelIDs)) + // channelID 表示当前遍历过程中的渠道ID for _, channelID := range *input.ChannelIDs { - if _, duplicate := seen[channelID]; duplicate { + if // duplicate 保存duplicate,供当前处理流程使用 + _, duplicate := seen[channelID]; duplicate { continue } seen[channelID] = struct{}{} + // exists 保存exists,供当前处理流程使用 var exists bool - if err := tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM notification_channels WHERE id=? AND user_id=?)`, channelID, input.UserID).Scan(&exists); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM notification_channels WHERE id=? AND user_id=?)`, channelID, input.UserID).Scan(&exists); err != nil { return 0, err } if !exists { return 0, ErrForbidden } } - if _, err := tx.ExecContext(ctx, `DELETE FROM message_notifications WHERE cookie_id=?`, cookieID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `DELETE FROM message_notifications WHERE cookie_id=?`, cookieID); err != nil { return 0, err } + // channelID 表示当前遍历过程中的渠道ID for channelID := range seen { - if _, err := tx.ExecContext(ctx, `INSERT INTO message_notifications (cookie_id,channel_id,enabled) VALUES (?,?,1)`, cookieID, channelID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `INSERT INTO message_notifications (cookie_id,channel_id,enabled) VALUES (?,?,1)`, cookieID, channelID); err != nil { return 0, err } } } - if err := tx.Commit(); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.Commit(); err != nil { return 0, err } return pausedUntil, nil @@ -159,10 +183,12 @@ func (c *Cookies) CreateOwned(ctx context.Context, cookieID, cookieValue string, if cookieID == "" || userID <= 0 { return errors.New("账号 ID 和 user_id 不能为空") } + // encrypted、err 保存encrypted、err,供当前处理流程使用 encrypted, err := c.codec.encrypt("cookie", cookieID, cookieValue) if err != nil { return err } + // res、err 保存res、err,供当前处理流程使用 res, err := c.DB.ExecContext(ctx, dialectInsertIgnorePrefix(c.Dialect)+` INTO cookies (id, value, user_id, updated_at) VALUES (?, ?, ?, CURRENT_TIMESTAMP)`+dialectInsertIgnore(c.Dialect, []string{"id"}), @@ -170,14 +196,17 @@ func (c *Cookies) CreateOwned(ctx context.Context, cookieID, cookieValue string, if err != nil { return err } - if n, rowsErr := res.RowsAffected(); rowsErr != nil { + if // n、rowsErr 保存n、rowsErr,供当前处理流程使用 + n, rowsErr := res.RowsAffected(); rowsErr != nil { return rowsErr } else if n == 1 { return nil } + // existingOwner 保存existing所有者,供当前处理流程使用 var existingOwner int64 - if err := c.DB.QueryRowContext(ctx, `SELECT user_id FROM cookies WHERE id=?`, cookieID).Scan(&existingOwner); err != nil { + if // err 保存err,供当前处理流程使用 + err := c.DB.QueryRowContext(ctx, `SELECT user_id FROM cookies WHERE id=?`, cookieID).Scan(&existingOwner); err != nil { if errors.Is(err, sql.ErrNoRows) { return ErrNotFound } @@ -194,18 +223,23 @@ func (c *Cookies) UpdateValueOwned(ctx context.Context, cookieID, cookieValue st if cookieID == "" || userID <= 0 { return errors.New("账号 ID 和 user_id 不能为空") } + // encrypted、err 保存encrypted、err,供当前处理流程使用 encrypted, err := c.codec.encrypt("cookie", cookieID, cookieValue) if err != nil { return err } + // tx、err 保存tx、err,供当前处理流程使用 tx, err := c.DB.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() + // existingOwner 保存existing所有者,供当前处理流程使用 var existingOwner int64 + // rawMetadata 保存原始Metadata,供当前处理流程使用 var rawMetadata string - if err := tx.QueryRowContext(ctx, c.cookieSelectForUpdate(`user_id,COALESCE(metadata_json,'')`), cookieID).Scan(&existingOwner, &rawMetadata); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.QueryRowContext(ctx, c.cookieSelectForUpdate(`user_id,COALESCE(metadata_json,'')`), cookieID).Scan(&existingOwner, &rawMetadata); err != nil { if errors.Is(err, sql.ErrNoRows) { return ErrNotFound } @@ -214,17 +248,20 @@ func (c *Cookies) UpdateValueOwned(ctx context.Context, cookieID, cookieValue st if existingOwner != userID { return ErrForbidden } + // metadata、err 保存metadata、err,供当前处理流程使用 metadata, err := c.metadataWithoutCookieSnapshotValue(cookieID, rawMetadata) if err != nil { return err } + // res、err 保存res、err,供当前处理流程使用 res, err := tx.ExecContext(ctx, `UPDATE cookies SET value=?,metadata_json=?,updated_at=CURRENT_TIMESTAMP WHERE id=? AND user_id=?`, encrypted, metadata, cookieID, userID) if err != nil { return err } - if n, rowsErr := res.RowsAffected(); rowsErr != nil { + if // n、rowsErr 保存n、rowsErr,供当前处理流程使用 + n, rowsErr := res.RowsAffected(); rowsErr != nil { return rowsErr } else if n > 1 { return fmt.Errorf("更新 cookie 影响了 %d 行", n) @@ -234,35 +271,43 @@ func (c *Cookies) UpdateValueOwned(ctx context.Context, cookieID, cookieValue st // UpdateValueExisting 供续期和运行时写回使用,只能更新现存账号。 // owner 由数据库中的记录决定;账号在任务期间被删除时返回 ErrNotFound,禁止复活。 +// UpdateValueExisting 更新值Existing。 func (c *Cookies) UpdateValueExisting(ctx context.Context, cookieID, cookieValue string) error { if cookieID == "" { return errors.New("账号 ID 不能为空") } + // encrypted、err 保存encrypted、err,供当前处理流程使用 encrypted, err := c.codec.encrypt("cookie", cookieID, cookieValue) if err != nil { return err } + // tx、err 保存tx、err,供当前处理流程使用 tx, err := c.DB.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() + // rawMetadata 保存原始Metadata,供当前处理流程使用 var rawMetadata string - if err := tx.QueryRowContext(ctx, c.cookieSelectForUpdate(`COALESCE(metadata_json,'')`), cookieID).Scan(&rawMetadata); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.QueryRowContext(ctx, c.cookieSelectForUpdate(`COALESCE(metadata_json,'')`), cookieID).Scan(&rawMetadata); err != nil { if errors.Is(err, sql.ErrNoRows) { return ErrNotFound } return err } + // metadata、err 保存metadata、err,供当前处理流程使用 metadata, err := c.metadataWithoutCookieSnapshotValue(cookieID, rawMetadata) if err != nil { return err } + // res、err 保存res、err,供当前处理流程使用 res, err := tx.ExecContext(ctx, `UPDATE cookies SET value=?,metadata_json=?,updated_at=CURRENT_TIMESTAMP WHERE id=?`, encrypted, metadata, cookieID) if err != nil { return err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() if err != nil { return err @@ -273,7 +318,9 @@ func (c *Cookies) UpdateValueExisting(ctx context.Context, cookieID, cookieValue return tx.Commit() } +// cookieSelectForUpdate 负责登录凭证SelectForUpdate相关处理。 func (c *Cookies) cookieSelectForUpdate(columns string) string { + // query 保存查询,供当前处理流程使用 query := `SELECT ` + columns + ` FROM cookies WHERE id=?` if c.Dialect == DialectMySQL || c.Dialect == DialectPostgres { query += ` FOR UPDATE` @@ -281,7 +328,9 @@ func (c *Cookies) cookieSelectForUpdate(columns string) string { return query } +// metadataWithoutCookieSnapshotValue 负责metadataWithout登录凭证Snapshot值相关处理。 func (c *Cookies) metadataWithoutCookieSnapshotValue(cookieID, raw string) (string, error) { + // plain、err 保存plain、err,供当前处理流程使用 plain, err := c.codec.decrypt(cookieMetadataScope, cookieID, raw) if err != nil { return "", err @@ -289,17 +338,21 @@ func (c *Cookies) metadataWithoutCookieSnapshotValue(cookieID, raw string) (stri return c.codec.encrypt(cookieMetadataScope, cookieID, stripCookieSnapshotMetadata(plain)) } +// stripCookieSnapshotMetadata 负责strip登录凭证SnapshotMetadata相关处理。 func stripCookieSnapshotMetadata(metadata string) string { if strings.TrimSpace(metadata) == "" { return "" } + // values 保存values,供当前处理流程使用 var values map[string]any - if err := json.Unmarshal([]byte(metadata), &values); err != nil { + if // err 保存err,供当前处理流程使用 + err := json.Unmarshal([]byte(metadata), &values); err != nil { // 无法解析的历史 metadata 本来也不能被当作快照使用,原样保留。 return metadata } delete(values, "cookies_refresh_snapshot") delete(values, "cookie_refresh_snapshot") + // raw、err 保存raw、err,供当前处理流程使用 raw, err := json.Marshal(values) if err != nil { return metadata @@ -309,16 +362,19 @@ func stripCookieSnapshotMetadata(metadata string) string { // Save 保留给历史调用和测试夹具使用。新业务代码应选择 CreateOwned、 // UpdateValueOwned 或 UpdateValueExisting,避免把创建和后台写回混为一谈。 +// Save 保存当前值。 func (c *Cookies) Save(ctx context.Context, cookieID, cookieValue string, userID int64) error { if userID == 0 { return c.UpdateValueExisting(ctx, cookieID, cookieValue) } - if err := c.UpdateValueOwned(ctx, cookieID, cookieValue, userID); err == nil { + if // err 保存err,供当前处理流程使用 + err := c.UpdateValueOwned(ctx, cookieID, cookieValue, userID); err == nil { return nil } else if !errors.Is(err, ErrNotFound) { return err } - if err := c.CreateOwned(ctx, cookieID, cookieValue, userID); errors.Is(err, ErrAlreadyExists) { + if // err 保存err,供当前处理流程使用 + err := c.CreateOwned(ctx, cookieID, cookieValue, userID); errors.Is(err, ErrAlreadyExists) { // 同一 owner 并发创建时,让最后一次写入拥有和历史 Save 相同的更新语义。 return c.UpdateValueOwned(ctx, cookieID, cookieValue, userID) } else { @@ -328,12 +384,14 @@ func (c *Cookies) Save(ctx context.Context, cookieID, cookieValue string, userID // Delete 删除 cookie 及无法通过外键级联清理的关联数据。 func (c *Cookies) Delete(ctx context.Context, cookieID string) error { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := c.DB.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() - if err := deleteCookieTx(ctx, tx, cookieID); err != nil { + if // err 保存err,供当前处理流程使用 + err := deleteCookieTx(ctx, tx, cookieID); err != nil { return err } return tx.Commit() @@ -341,10 +399,13 @@ func (c *Cookies) Delete(ctx context.Context, cookieID string) error { // deleteCookieTx 清理一个账号的全部按 cookie_id 关联数据。这里同时处理历史上 // 没有外键的表,确保账号 ID 被复用时不会继承前一个 owner 的数据。 +// deleteCookieTx 负责delete登录凭证Tx相关处理。 func deleteCookieTx(ctx context.Context, tx *sql.Tx, cookieID string) error { - if _, err := tx.ExecContext(ctx, `DELETE FROM keywords WHERE cookie_id=?`, cookieID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `DELETE FROM keywords WHERE cookie_id=?`, cookieID); err != nil { return err } + // table 表示当前遍历过程中的table for _, table := range []string{ "item_replay", "scheduled_cookies_refresh_log", @@ -352,11 +413,13 @@ func deleteCookieTx(ctx context.Context, tx *sql.Tx, cookieID string) error { "scheduled_api_cookie_renew_log", "account_login_logs", } { - if _, err := tx.ExecContext(ctx, `DELETE FROM `+table+` WHERE cookie_id=?`, cookieID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `DELETE FROM `+table+` WHERE cookie_id=?`, cookieID); err != nil { return err } } - if _, err := tx.ExecContext(ctx, `DELETE FROM cookies WHERE id=?`, cookieID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `DELETE FROM cookies WHERE id=?`, cookieID); err != nil { return err } return nil @@ -364,7 +427,9 @@ func deleteCookieTx(ctx context.Context, tx *sql.Tx, cookieID string) error { // GetValue 取 cookie 明文值。不存在返回 ErrNotFound。 func (c *Cookies) GetValue(ctx context.Context, cookieID string) (string, error) { + // v 保存v,供当前处理流程使用 var v string + // err 保存err,供当前处理流程使用 err := c.DB.QueryRowContext(ctx, `SELECT value FROM cookies WHERE id=?`, cookieID).Scan(&v) if err != nil { if errors.Is(err, sql.ErrNoRows) { @@ -377,7 +442,9 @@ func (c *Cookies) GetValue(ctx context.Context, cookieID string) (string, error) // AllForUser 取某用户的所有 cookie(id→value)。userID 为 0 时取全部(管理员视图)。 func (c *Cookies) AllForUser(ctx context.Context, userID int64) (map[string]string, error) { + // rows 保存rows,供当前处理流程使用 var rows *sql.Rows + // err 保存err,供当前处理流程使用 var err error if userID == 0 { rows, err = c.DB.QueryContext(ctx, `SELECT id, value FROM cookies`) @@ -388,12 +455,16 @@ func (c *Cookies) AllForUser(ctx context.Context, userID int64) (map[string]stri return nil, err } defer rows.Close() + // m 保存m,供当前处理流程使用 m := make(map[string]string) for rows.Next() { + // id、v 保存id、v,供当前处理流程使用 var id, v string - if err := rows.Scan(&id, &v); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&id, &v); err != nil { return nil, err } + // plain、err 保存plain、err,供当前处理流程使用 plain, err := c.codec.decrypt("cookie", id, v) if err != nil { return nil, err @@ -405,9 +476,13 @@ func (c *Cookies) AllForUser(ctx context.Context, userID int64) (map[string]stri // GetDetails 取账号完整详情。不存在返回 ErrNotFound。 func (c *Cookies) GetDetails(ctx context.Context, cookieID string) (*CookieDetail, error) { + // d 保存d,供当前处理流程使用 var d CookieDetail + // autoConfirm、showBrowser 保存autoConfirm、show浏览器,供当前处理流程使用 var autoConfirm, showBrowser int + // pauseDuration 保存pause时长,供当前处理流程使用 var pauseDuration sql.NullInt64 + // err 保存err,供当前处理流程使用 err := c.DB.QueryRowContext(ctx, `SELECT id, value, user_id, auto_confirm, COALESCE(remark,''), pause_duration, COALESCE(paused_until,0), COALESCE(username,''), COALESCE(password,''), @@ -448,10 +523,12 @@ func (c *Cookies) GetDetails(ctx context.Context, cookieID string) (*CookieDetai // UpdateLoginInfo 保存账号密码登录资料。 func (c *Cookies) UpdateLoginInfo(ctx context.Context, cookieID, username, password string, showBrowser bool) error { + // v 保存v,供当前处理流程使用 v := 0 if showBrowser { v = 1 } + // encrypted、err 保存encrypted、err,供当前处理流程使用 encrypted, err := c.codec.encrypt("login-password", cookieID, password) if err != nil { return err @@ -466,6 +543,7 @@ func (c *Cookies) UpdateLoginInfo(ctx context.Context, cookieID, username, passw // MarkLogin 记录账号最近一次成功登录方式。 func (c *Cookies) MarkLogin(ctx context.Context, cookieID, method string, loginAt int64) error { + // err 保存err,供当前处理流程使用 _, err := c.DB.ExecContext(ctx, `UPDATE cookies SET login_method=?, last_login_at=?, updated_at=CURRENT_TIMESTAMP @@ -476,6 +554,7 @@ func (c *Cookies) MarkLogin(ctx context.Context, cookieID, method string, loginA // UpdateProfile 保存账号展示资料。 func (c *Cookies) UpdateProfile(ctx context.Context, cookieID, nickname, avatarURL string) error { + // err 保存err,供当前处理流程使用 _, err := c.DB.ExecContext(ctx, `UPDATE cookies SET nickname=?, avatar_url=?, updated_at=CURRENT_TIMESTAMP @@ -486,7 +565,9 @@ func (c *Cookies) UpdateProfile(ctx context.Context, cookieID, nickname, avatarU // GetPauseDuration 取自动回复暂停时长(分钟)。未找到或 NULL 返回 10。 func (c *Cookies) GetPauseDuration(ctx context.Context, cookieID string) int { + // pd 保存pd,供当前处理流程使用 var pd sql.NullInt64 + // err 保存err,供当前处理流程使用 err := c.DB.QueryRowContext(ctx, `SELECT pause_duration FROM cookies WHERE id=?`, cookieID).Scan(&pd) if err != nil || !pd.Valid { return 10 @@ -499,10 +580,12 @@ func (c *Cookies) SetPause(ctx context.Context, cookieID string, minutes int) (i if minutes < 0 || minutes > 1440 { return 0, fmt.Errorf("暂停时长必须在 0 到 1440 分钟之间") } + // pausedUntil 保存pausedUntil,供当前处理流程使用 pausedUntil := int64(0) if minutes > 0 { pausedUntil = time.Now().UTC().Add(time.Duration(minutes) * time.Minute).Unix() } + // err 保存err,供当前处理流程使用 _, err := c.DB.ExecContext(ctx, `UPDATE cookies SET pause_duration=?,paused_until=?,updated_at=CURRENT_TIMESTAMP WHERE id=?`, minutes, pausedUntil, cookieID) @@ -515,7 +598,9 @@ func (c *Cookies) SetPause(ctx context.Context, cookieID string, minutes int) (i // IsPaused 返回账号当前是否暂停以及暂停截止 Unix 秒。 func (c *Cookies) IsPaused(ctx context.Context, cookieID string) (bool, int64, error) { + // pausedUntil 保存pausedUntil,供当前处理流程使用 var pausedUntil int64 + // err 保存err,供当前处理流程使用 err := c.DB.QueryRowContext(ctx, `SELECT COALESCE(paused_until,0) FROM cookies WHERE id=?`, cookieID).Scan(&pausedUntil) if err != nil { if errors.Is(err, sql.ErrNoRows) { @@ -528,7 +613,9 @@ func (c *Cookies) IsPaused(ctx context.Context, cookieID string) (bool, int64, e // GetAutoConfirm 读取账号是否自动将订单确认成已发货状态。 func (c *Cookies) GetAutoConfirm(ctx context.Context, cookieID string) (bool, error) { + // enabled 保存启用状态,供当前处理流程使用 var enabled int + // err 保存err,供当前处理流程使用 err := c.DB.QueryRowContext(ctx, `SELECT auto_confirm FROM cookies WHERE id=?`, cookieID).Scan(&enabled) if err != nil { if errors.Is(err, sql.ErrNoRows) { @@ -546,10 +633,12 @@ func (c *Cookies) SetStatus(ctx context.Context, cookieID string, enabled bool) // SetStatusWithReason 启用/禁用账号并记录禁用原因。 func (c *Cookies) SetStatusWithReason(ctx context.Context, cookieID string, enabled bool, reason string) error { + // v 保存v,供当前处理流程使用 v := 0 if enabled { v = 1 } + // err 保存err,供当前处理流程使用 _, err := c.DB.ExecContext(ctx, `INSERT INTO cookie_status (cookie_id, enabled, disable_reason, updated_at) VALUES (?, ?, ?, CURRENT_TIMESTAMP)`+ dialectUpsert(c.Dialect, []string{"cookie_id"}, map[string]string{ @@ -563,6 +652,7 @@ func (c *Cookies) SetStatusWithReason(ctx context.Context, cookieID string, enab // GetStatus 取启用状态。无状态记录仍按启用处理;数据库错误则安全地按停用处理。 func (c *Cookies) GetStatus(ctx context.Context, cookieID string) bool { + // enabled、err 保存enabled、err,供当前处理流程使用 enabled, err := c.Status(ctx, cookieID) if err != nil { return false @@ -572,22 +662,29 @@ func (c *Cookies) GetStatus(ctx context.Context, cookieID string) bool { // Status 返回账号启用状态;没有 cookie_status 记录时按启用处理,数据库错误不再静默放行。 func (c *Cookies) Status(ctx context.Context, cookieID string) (bool, error) { + // enabled、err 保存enabled、err,供当前处理流程使用 enabled, _, err := c.StatusWithReason(ctx, cookieID) return enabled, err } // StatusWithReason 原子语义地读取账号当前启用状态和禁用原因;调用方应在 // Store.LockAccountCredentials 保护下使用,以复核列表查询后的最新状态。 +// StatusWithReason 负责状态With原因相关处理。 func (c *Cookies) StatusWithReason(ctx context.Context, cookieID string) (bool, string, error) { + // exists 保存exists,供当前处理流程使用 var exists bool - if err := c.DB.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM cookies WHERE id=?)`, cookieID).Scan(&exists); err != nil { + if // err 保存err,供当前处理流程使用 + err := c.DB.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM cookies WHERE id=?)`, cookieID).Scan(&exists); err != nil { return false, "", err } if !exists { return false, "", ErrNotFound } + // enabled 保存启用状态,供当前处理流程使用 var enabled int + // reason 保存原因,供当前处理流程使用 var reason string + // err 保存err,供当前处理流程使用 err := c.DB.QueryRowContext(ctx, `SELECT enabled,COALESCE(disable_reason,'') FROM cookie_status WHERE cookie_id=?`, cookieID).Scan(&enabled, &reason) if errors.Is(err, sql.ErrNoRows) { return true, "", nil diff --git a/internal/db/cookies_concurrency_test.go b/internal/db/cookies_concurrency_test.go index 7a4c3b1..69c36f2 100644 --- a/internal/db/cookies_concurrency_test.go +++ b/internal/db/cookies_concurrency_test.go @@ -7,26 +7,38 @@ import ( "testing" ) +// TestCreateOwnedConcurrentUsersNeverTransfersOwner 负责TestCreateOwnedConcurrent用户列表NeverTransfers所有者相关处理。 func TestCreateOwnedConcurrentUsersNeverTransfersOwner(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if _, err := store.Users.Create(ctx, "owner-a", "owner-a@example.com", "pw"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.Users.Create(ctx, "owner-a", "owner-a@example.com", "pw"); err != nil { t.Fatal(err) } - if _, err := store.Users.Create(ctx, "owner-b", "owner-b@example.com", "pw"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.Users.Create(ctx, "owner-b", "owner-b@example.com", "pw"); err != nil { t.Fatal(err) } + // a 保存a,供当前处理流程使用 a, _ := store.Users.GetByUsername(ctx, "owner-a") + // b 保存b,供当前处理流程使用 b, _ := store.Users.GetByUsername(ctx, "owner-b") + // start 保存开始,供当前处理流程使用 start := make(chan struct{}) + // results 保存results,供当前处理流程使用 results := make(chan error, 2) + // wg 保存wg,供当前处理流程使用 var wg sync.WaitGroup + // input 表示当前遍历过程中的input for _, input := range []struct { userID int64 value string }{{a.ID, "cookie-a"}, {b.ID, "cookie-b"}} { + // input 保存input,供当前处理流程使用 input := input wg.Add(1) go func() { @@ -39,7 +51,9 @@ func TestCreateOwnedConcurrentUsersNeverTransfersOwner(t *testing.T) { wg.Wait() close(results) + // successes 保存successes,供当前处理流程使用 successes := 0 + // err 表示当前遍历过程中的err for err := range results { if err == nil { successes++ @@ -52,9 +66,12 @@ func TestCreateOwnedConcurrentUsersNeverTransfersOwner(t *testing.T) { if successes != 1 { t.Fatalf("successful creates=%d want 1", successes) } + // owner 保存所有者,供当前处理流程使用 var owner int64 + // value 保存值,供当前处理流程使用 var value string - if err := store.DB.QueryRowContext(ctx, `SELECT user_id,value FROM cookies WHERE id=?`, "shared-account").Scan(&owner, &value); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT user_id,value FROM cookies WHERE id=?`, "shared-account").Scan(&owner, &value); err != nil { t.Fatal(err) } if owner == a.ID && value != "cookie-a" { @@ -65,40 +82,57 @@ func TestCreateOwnedConcurrentUsersNeverTransfersOwner(t *testing.T) { } } +// TestUpdateValueExistingCannotResurrectDeletedAccount 负责TestUpdate值ExistingCannotResurrectDeleted账号相关处理。 func TestUpdateValueExistingCannotResurrectDeletedAccount(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if _, err := store.Users.Create(ctx, "delete-race-owner", "delete-race-owner@example.com", "pw"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.Users.Create(ctx, "delete-race-owner", "delete-race-owner@example.com", "pw"); err != nil { t.Fatal(err) } + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "delete-race-owner") - if err := store.Cookies.CreateOwned(ctx, "deleted-account", "old", admin.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.CreateOwned(ctx, "deleted-account", "old", admin.ID); err != nil { t.Fatal(err) } - if err := store.Cookies.Delete(ctx, "deleted-account"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.Delete(ctx, "deleted-account"); err != nil { t.Fatal(err) } - if err := store.Cookies.UpdateValueExisting(ctx, "deleted-account", "new"); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.UpdateValueExisting(ctx, "deleted-account", "new"); !errors.Is(err, ErrNotFound) { t.Fatalf("update deleted account err=%v want ErrNotFound", err) } + // count 保存数量,供当前处理流程使用 var count int - if err := store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM cookies WHERE id=?`, "deleted-account").Scan(&count); err != nil || count != 0 { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM cookies WHERE id=?`, "deleted-account").Scan(&count); err != nil || count != 0 { t.Fatalf("deleted account resurrected: count=%d err=%v", count, err) } } +// TestDeleteUserCleansNonForeignKeyAccountData 负责TestDelete用户CleansNonForeignKey账号数据相关处理。 func TestDeleteUserCleansNonForeignKeyAccountData(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if _, err := store.Users.Create(ctx, "delete-owner", "delete-owner@example.com", "pw"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.Users.Create(ctx, "delete-owner", "delete-owner@example.com", "pw"); err != nil { t.Fatal(err) } + // owner 保存所有者,供当前处理流程使用 owner, _ := store.Users.GetByUsername(ctx, "delete-owner") - if err := store.Cookies.CreateOwned(ctx, "delete-owned-account", "cookie", owner.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.CreateOwned(ctx, "delete-owned-account", "cookie", owner.ID); err != nil { t.Fatal(err) } + // query 表示当前遍历过程中的查询 for _, query := range []string{ `INSERT INTO item_replay (item_id,cookie_id,reply_content) VALUES ('item','delete-owned-account','secret reply')`, `INSERT INTO scheduled_cookies_refresh_log (cookie_id,status) VALUES ('delete-owned-account','failed')`, @@ -106,19 +140,24 @@ func TestDeleteUserCleansNonForeignKeyAccountData(t *testing.T) { `INSERT INTO scheduled_api_cookie_renew_log (cookie_id,status) VALUES ('delete-owned-account','failed')`, `INSERT INTO account_login_logs (cookie_id,user_id,method,status,created_at) VALUES ('delete-owned-account',0,'password','failed',1)`, } { - if _, err := store.DB.ExecContext(ctx, query); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, query); err != nil { t.Fatalf("seed orphan candidate: %v", err) } } - if err := store.Users.Delete(ctx, owner.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Users.Delete(ctx, owner.ID); err != nil { t.Fatal(err) } + // table 表示当前遍历过程中的table for _, table := range []string{ "cookies", "item_replay", "scheduled_cookies_refresh_log", "scheduled_login_renew_log", "scheduled_api_cookie_renew_log", "account_login_logs", } { + // count 保存数量,供当前处理流程使用 var count int - if err := store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM `+table+` WHERE cookie_id=?`, "delete-owned-account").Scan(&count); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM `+table+` WHERE cookie_id=?`, "delete-owned-account").Scan(&count); err != nil { if table == "cookies" { err = store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM cookies WHERE id=?`, "delete-owned-account").Scan(&count) } diff --git a/internal/db/cookies_settings_test.go b/internal/db/cookies_settings_test.go index 426b08a..e50cdcd 100644 --- a/internal/db/cookies_settings_test.go +++ b/internal/db/cookies_settings_test.go @@ -6,27 +6,40 @@ import ( "testing" ) +// TestUpdateAccountSettingsIsAtomic 负责TestUpdate账号设置IsAtomic相关处理。 func TestUpdateAccountSettingsIsAtomic(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // user 表示当前遍历过程中的用户 for _, user := range []struct{ name, email string }{{"settings-owner", "settings-owner@example.com"}, {"settings-other", "settings-other@example.com"}} { - if ok, err := store.Users.Create(ctx, user.name, user.email, "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := store.Users.Create(ctx, user.name, user.email, "pw"); err != nil || !ok { t.Fatalf("create %s: ok=%v err=%v", user.name, ok, err) } } + // owner 保存所有者,供当前处理流程使用 owner, _ := store.Users.GetByUsername(ctx, "settings-owner") + // other 保存other,供当前处理流程使用 other, _ := store.Users.GetByUsername(ctx, "settings-other") - if err := store.Cookies.CreateOwned(ctx, "settings-cookie", "old-cookie", owner.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.CreateOwned(ctx, "settings-cookie", "old-cookie", owner.ID); err != nil { t.Fatal(err) } + // channelResult、err 保存渠道Result、err,供当前处理流程使用 channelResult, err := store.DB.ExecContext(ctx, `INSERT INTO notification_channels (name,type,config,enabled,user_id) VALUES (?,?,?,1,?)`, "other", "webhook", `{}`, other.ID) if err != nil { t.Fatal(err) } + // otherChannelID 保存other渠道ID,供当前处理流程使用 otherChannelID, _ := channelResult.LastInsertId() + // newCookie、remark 保存newCookie、remark,供当前处理流程使用 newCookie, remark := "new-cookie", "new remark" + // autoConfirm 保存autoConfirm,供当前处理流程使用 autoConfirm := false + // badChannels 保存bad渠道列表,供当前处理流程使用 badChannels := []int64{otherChannelID} _, err = store.Cookies.UpdateSettings(ctx, "settings-cookie", AccountSettingsUpdate{ UserID: owner.ID, Value: &newCookie, Remark: &remark, AutoConfirm: &autoConfirm, ChannelIDs: &badChannels, @@ -34,6 +47,7 @@ func TestUpdateAccountSettingsIsAtomic(t *testing.T) { if !errors.Is(err, ErrForbidden) { t.Fatalf("expected forbidden channel, got %v", err) } + // detail 保存detail,供当前处理流程使用 detail, _ := store.Cookies.GetDetails(ctx, "settings-cookie") if detail.Value != "old-cookie" || detail.Remark != "" || !detail.AutoConfirm { t.Fatalf("failed aggregate update partially committed: %+v", detail) @@ -43,15 +57,20 @@ func TestUpdateAccountSettingsIsAtomic(t *testing.T) { if err != nil { t.Fatal(err) } + // ownedChannelID 保存owned渠道ID,供当前处理流程使用 ownedChannelID, _ := channelResult.LastInsertId() + // channels 保存渠道列表,供当前处理流程使用 channels := []int64{ownedChannelID, ownedChannelID} + // pause 保存pause,供当前处理流程使用 pause := 5 - if _, err := store.Cookies.UpdateSettings(ctx, "settings-cookie", AccountSettingsUpdate{ + if // err 保存err,供当前处理流程使用 + _, err := store.Cookies.UpdateSettings(ctx, "settings-cookie", AccountSettingsUpdate{ UserID: owner.ID, Value: &newCookie, Remark: &remark, AutoConfirm: &autoConfirm, PauseDuration: &pause, ChannelIDs: &channels, }); err != nil { t.Fatal(err) } detail, _ = store.Cookies.GetDetails(ctx, "settings-cookie") + // bindings 保存bindings,供当前处理流程使用 bindings, _ := store.Notifications.AccountBindings(ctx, "settings-cookie") if detail.Value != newCookie || detail.Remark != remark || detail.AutoConfirm || detail.PauseDuration != pause || detail.PausedUntil == 0 { t.Fatalf("aggregate settings not applied: %+v", detail) diff --git a/internal/db/db.go b/internal/db/db.go index 98edb36..51440c4 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -24,12 +24,15 @@ import ( _ "modernc.org/sqlite" ) +// migrationsFS 保存migrationsFS,供当前处理流程使用 +// //go:embed migrations/sqlite/*.sql migrations/mysql/*.sql migrations/postgres/*.sql var migrationsFS embed.FS // Dialect 标识数据库方言。 type Dialect string +// DialectSQLite 保存DialectSQLite,供当前处理流程使用 const ( DialectSQLite Dialect = "sqlite" DialectMySQL Dialect = "mysql" @@ -39,6 +42,7 @@ const ( // driverName 内部 driver 名(传给 sql.Open)。 type driverName string +// driverSQLite 保存driverSQLite,供当前处理流程使用 const ( driverSQLite driverName = "sqlite" driverMySQL driverName = "mysql" @@ -53,11 +57,14 @@ const ( // postgres://user:pass@host:5432/dbname?sslmode=disable // // 为向后兼容,传入的 dbURL 若不含 "://",则按 SQLite 文件路径处理。 +// Open 打开当前值。 func Open(ctx context.Context, dbURL string) (*sql.DB, Dialect, error) { + // driver、dialect、dsn、err 保存driver、dialect、dsn、err,供当前处理流程使用 driver, dialect, dsn, err := parseDBURL(dbURL) if err != nil { return nil, "", err } + // db、err 保存db、err,供当前处理流程使用 db, err := sql.Open(string(driver), dsn) if err != nil { return nil, "", fmt.Errorf("打开数据库: %w", err) @@ -74,12 +81,14 @@ func Open(ctx context.Context, dbURL string) (*sql.DB, Dialect, error) { } db.SetConnMaxLifetime(time.Hour) - if err := db.PingContext(ctx); err != nil { + if // err 保存err,供当前处理流程使用 + err := db.PingContext(ctx); err != nil { _ = db.Close() return nil, "", fmt.Errorf("ping 数据库: %w", err) } - if err := Migrate(ctx, db, dialect); err != nil { + if // err 保存err,供当前处理流程使用 + err := Migrate(ctx, db, dialect); err != nil { _ = db.Close() return nil, "", err } @@ -94,11 +103,15 @@ func parseDBURL(raw string) (driverName, Dialect, string, error) { } // 向后兼容:不含 scheme 视为 SQLite 文件路径。 if !strings.Contains(raw, "://") { + // dsn 保存dsn,供当前处理流程使用 dsn := sqliteDSN(raw) return driverSQLite, DialectSQLite, dsn, nil } + // idx 保存idx,供当前处理流程使用 idx := strings.Index(raw, "://") + // scheme 保存scheme,供当前处理流程使用 scheme := raw[:idx] + // rest 保存rest,供当前处理流程使用 rest := raw[idx+3:] switch scheme { case "sqlite", "sqlite3": @@ -129,20 +142,27 @@ func sqliteDSN(path string) string { // - clientFoundRows:RowsAffected 返回匹配行数,使“保存未变化内容”的语义与 SQLite/Postgres 一致。 // // 其余参数原样保留。不强制 parseTime——本仓库时间列按 string/int64 扫描。 +// mysqlDSN 负责mysqlDSN相关处理。 func mysqlDSN(dsn string) string { dsn = forceMySQLBoolParam(dsn, "multiStatements") return forceMySQLBoolParam(dsn, "clientFoundRows") } +// forceMySQLBoolParam 负责forceMySQLBoolParam相关处理。 func forceMySQLBoolParam(dsn, key string) string { + // base、rawQuery、hasQuery 保存base、rawQuery、has查询,供当前处理流程使用 base, rawQuery, hasQuery := strings.Cut(dsn, "?") + // parts 保存parts,供当前处理流程使用 parts := make([]string, 0, 4) + // found 保存found,供当前处理流程使用 found := false if hasQuery { + // part 表示当前遍历过程中的part for _, part := range strings.Split(rawQuery, "&") { if part == "" { continue } + // name 保存名称,供当前处理流程使用 name, _, _ := strings.Cut(part, "=") if name == key { if !found { @@ -162,7 +182,9 @@ func forceMySQLBoolParam(dsn, key string) string { // Migrate 执行嵌入式 goose 迁移,按方言选择子目录。 func Migrate(ctx context.Context, db *sql.DB, dialect Dialect) error { + // gooseDialect 保存gooseDialect,供当前处理流程使用 var gooseDialect string + // subdir 保存subdir,供当前处理流程使用 var subdir string switch dialect { case DialectSQLite: @@ -174,11 +196,13 @@ func Migrate(ctx context.Context, db *sql.DB, dialect Dialect) error { default: return fmt.Errorf("未知方言: %s", dialect) } - if err := goose.SetDialect(gooseDialect); err != nil { + if // err 保存err,供当前处理流程使用 + err := goose.SetDialect(gooseDialect); err != nil { return fmt.Errorf("设置 goose dialect: %w", err) } goose.SetBaseFS(migrationsFS) - if err := goose.Up(db, "migrations/"+subdir); err != nil { + if // err 保存err,供当前处理流程使用 + err := goose.Up(db, "migrations/"+subdir); err != nil { return fmt.Errorf("执行迁移: %w", err) } return nil diff --git a/internal/db/db_url_test.go b/internal/db/db_url_test.go index 6a92e14..5242f38 100644 --- a/internal/db/db_url_test.go +++ b/internal/db/db_url_test.go @@ -9,6 +9,7 @@ import ( // TestParseDBURL 覆盖各 scheme 与向后兼容路径。 func TestParseDBURL(t *testing.T) { + // cases 保存cases,供当前处理流程使用 cases := []struct { name string url string @@ -31,8 +32,10 @@ func TestParseDBURL(t *testing.T) { {name: "whitespace url", url: " ", wantErr: true, errMatch: "为空"}, {name: "unknown scheme", url: "redis://h:6379", wantErr: true, errMatch: "不支持"}, } + // c 表示当前遍历过程中的c for _, c := range cases { t.Run(c.name, func(t *testing.T) { + // driver、dialect、dsn、err 保存driver、dialect、dsn、err,供当前处理流程使用 driver, dialect, dsn, err := parseDBURL(c.url) if c.wantErr { if err == nil { @@ -83,6 +86,7 @@ func TestMysqlDSN(t *testing.T) { // TestRewriteQuestionPlaceholders ? → $N,跳过引号内字面量。 func TestRewriteQuestionPlaceholders(t *testing.T) { + // cases 保存cases,供当前处理流程使用 cases := []struct { name string in string @@ -96,8 +100,10 @@ func TestRewriteQuestionPlaceholders(t *testing.T) { {name: "double-quoted identifier with ?", in: `SELECT "col?" FROM t WHERE id=?`, want: `SELECT "col?" FROM t WHERE id=$1`}, {name: "empty", in: "", want: ""}, } + // c 表示当前遍历过程中的c for _, c := range cases { t.Run(c.name, func(t *testing.T) { + // got 保存got,供当前处理流程使用 got := rewriteQuestionPlaceholders(c.in) if got != c.want { t.Errorf("rewriteQuestionPlaceholders(%q)=%q want %q", c.in, got, c.want) diff --git a/internal/db/delivery.go b/internal/db/delivery.go index 1fb5c7f..59166bd 100644 --- a/internal/db/delivery.go +++ b/internal/db/delivery.go @@ -47,9 +47,13 @@ type Items struct { // Get 取某账号下某商品信息。不存在返回 ErrNotFound。 func (i *Items) Get(ctx context.Context, cookieID, itemID string) (*ItemInfo, error) { + // it 保存it,供当前处理流程使用 var it ItemInfo + // isMulti、multiQty 保存isMulti、multiQty,供当前处理流程使用 var isMulti, multiQty int + // title、desc、cat、price、detail 保存title、desc、cat、price、detail,供当前处理流程使用 var title, desc, cat, price, detail sql.NullString + // err 保存err,供当前处理流程使用 err := i.DB.QueryRowContext(ctx, `SELECT id, cookie_id, item_id, item_title, item_description, item_category, item_price, item_detail, is_multi_spec, multi_quantity_delivery @@ -74,7 +78,9 @@ func (i *Items) Get(ctx context.Context, cookieID, itemID string) (*ItemInfo, er // IsMultiSpec 是否多规格商品。 func (i *Items) IsMultiSpec(ctx context.Context, cookieID, itemID string) bool { + // v 保存v,供当前处理流程使用 var v int + // err 保存err,供当前处理流程使用 err := i.DB.QueryRowContext(ctx, `SELECT is_multi_spec FROM item_info WHERE cookie_id=? AND item_id=? AND deleted_at IS NULL`, cookieID, itemID).Scan(&v) if err != nil { return false @@ -84,7 +90,9 @@ func (i *Items) IsMultiSpec(ctx context.Context, cookieID, itemID string) bool { // MultiQuantityDelivery 是否开启多数量发货。 func (i *Items) MultiQuantityDelivery(ctx context.Context, cookieID, itemID string) bool { + // v 保存v,供当前处理流程使用 var v int + // err 保存err,供当前处理流程使用 err := i.DB.QueryRowContext(ctx, `SELECT multi_quantity_delivery FROM item_info WHERE cookie_id=? AND item_id=? AND deleted_at IS NULL`, cookieID, itemID).Scan(&v) if err != nil { return false @@ -100,9 +108,13 @@ type Cards struct { // ConsumeBatchData 原子预留一条批量数据卡券(data 类型),返回内容。 // 通过快照条件更新处理并发追加/消费;调用方发送失败时应调用 RestoreBatchData。 +// ConsumeBatchData 负责Consume批次数据相关处理。 func (c *Cards) ConsumeBatchData(ctx context.Context, cardID int64) (string, error) { - for attempts := 0; attempts < 20; attempts++ { + for // attempts 保存尝试次数,供当前处理流程使用 + attempts := 0; attempts < 20; attempts++ { + // dataContent 保存数据内容,供当前处理流程使用 var dataContent sql.NullString + // err 保存err,供当前处理流程使用 err := c.DB.QueryRowContext(ctx, `SELECT data_content FROM cards WHERE id=?`, cardID).Scan(&dataContent) if err != nil { if errors.Is(err, sql.ErrNoRows) { @@ -113,21 +125,25 @@ func (c *Cards) ConsumeBatchData(ctx context.Context, cardID int64) (string, err if !dataContent.Valid || dataContent.String == "" { return "", errors.New("卡券批量数据为空") } + // lines 保存lines,供当前处理流程使用 lines := splitLines(dataContent.String) if len(lines) == 0 { return "", errors.New("卡券批量数据无有效行") } + // remaining 保存remaining,供当前处理流程使用 remaining := "" if len(lines) > 1 { remaining = joinLines(lines[1:]) } + // res、err 保存res、err,供当前处理流程使用 res, err := c.DB.ExecContext(ctx, `UPDATE cards SET data_content=?,updated_at=CURRENT_TIMESTAMP WHERE id=? AND data_content=?`, remaining, cardID, dataContent.String) if err != nil { return "", err } - if affected, err := res.RowsAffected(); err == nil && affected == 1 { + if // affected、err 保存affected、err,供当前处理流程使用 + affected, err := res.RowsAffected(); err == nil && affected == 1 { return lines[0], nil } } @@ -136,30 +152,37 @@ func (c *Cards) ConsumeBatchData(ctx context.Context, cardID int64) (string, err // RestoreBatchData 把发送失败的预留卡密放回库存头部。恢复失败时宁可进入人工处理, // 也不能把一个已成功发送但响应不确定的卡密自动重复发给下一位买家。 +// RestoreBatchData 负责Restore批次数据相关处理。 func (c *Cards) RestoreBatchData(ctx context.Context, cardID int64, content string) error { content = strings.TrimSpace(content) if content == "" { return errors.New("恢复卡密内容为空") } - for attempts := 0; attempts < 20; attempts++ { + for // attempts 保存尝试次数,供当前处理流程使用 + attempts := 0; attempts < 20; attempts++ { + // current 保存current,供当前处理流程使用 var current sql.NullString - if err := c.DB.QueryRowContext(ctx, `SELECT data_content FROM cards WHERE id=?`, cardID).Scan(¤t); err != nil { + if // err 保存err,供当前处理流程使用 + err := c.DB.QueryRowContext(ctx, `SELECT data_content FROM cards WHERE id=?`, cardID).Scan(¤t); err != nil { if errors.Is(err, sql.ErrNoRows) { return ErrNotFound } return err } + // merged 保存merged,供当前处理流程使用 merged := content if current.Valid && strings.TrimSpace(current.String) != "" { merged += "\n" + current.String } + // res、err 保存res、err,供当前处理流程使用 res, err := c.DB.ExecContext(ctx, `UPDATE cards SET data_content=?,updated_at=CURRENT_TIMESTAMP WHERE id=? AND COALESCE(data_content,'')=?`, merged, cardID, current.String) if err != nil { return err } - if affected, err := res.RowsAffected(); err == nil && affected == 1 { + if // affected、err 保存affected、err,供当前处理流程使用 + affected, err := res.RowsAffected(); err == nil && affected == 1 { return nil } } @@ -168,7 +191,9 @@ func (c *Cards) RestoreBatchData(ctx context.Context, cardID int64, content stri // FirstBatchData 返回 data 类型卡券当前第一条有效内容和原始快照。 // 调用方发送成功后应调用 CommitFirstBatchData 删除同一快照中的第一条,避免发送失败丢卡。 +// FirstBatchData 负责First批次数据相关处理。 func (c *Cards) FirstBatchData(ctx context.Context, cardID int64) (content, snapshot string, err error) { + // dataContent 保存数据内容,供当前处理流程使用 var dataContent sql.NullString err = c.DB.QueryRowContext(ctx, `SELECT data_content FROM cards WHERE id=?`, cardID).Scan(&dataContent) if err != nil { @@ -180,6 +205,7 @@ func (c *Cards) FirstBatchData(ctx context.Context, cardID int64) (content, snap if !dataContent.Valid || dataContent.String == "" { return "", "", errors.New("卡券批量数据为空") } + // lines 保存lines,供当前处理流程使用 lines := splitLines(dataContent.String) if len(lines) == 0 { return "", "", errors.New("卡券批量数据无有效行") @@ -189,19 +215,24 @@ func (c *Cards) FirstBatchData(ctx context.Context, cardID int64) (content, snap // CommitFirstBatchData 在 data_content 仍等于 snapshot 时删除第一条有效内容。 // 条件更新失败表示库存被并发修改,调用方应停止本次发货,避免错删卡密。 +// CommitFirstBatchData 负责CommitFirst批次数据相关处理。 func (c *Cards) CommitFirstBatchData(ctx context.Context, cardID int64, snapshot string) error { + // lines 保存lines,供当前处理流程使用 lines := splitLines(snapshot) if len(lines) == 0 { return errors.New("卡券批量数据无有效行") } + // remaining 保存remaining,供当前处理流程使用 remaining := "" if len(lines) > 1 { remaining = joinLines(lines[1:]) } + // res、err 保存res、err,供当前处理流程使用 res, err := c.DB.ExecContext(ctx, `UPDATE cards SET data_content=? WHERE id=? AND data_content=?`, remaining, cardID, snapshot) if err != nil { return err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() if err == nil && n == 0 { return errors.New("卡券库存已被并发修改,请重试") @@ -211,9 +242,13 @@ func (c *Cards) CommitFirstBatchData(ctx context.Context, cardID int64, snapshot // AppendBatchData 往 data 类型卡密组追加卡密号(按行)。返回新增的有效(非空)行数。 // 已有 data_content 非空时在末尾换行追加,否则直接写入。 +// AppendBatchData 负责Append批次数据相关处理。 func (c *Cards) AppendBatchData(ctx context.Context, cardID int64, content string) (int, error) { + // lines 保存lines,供当前处理流程使用 lines := splitLines(content) + // valid 保存有效,供当前处理流程使用 valid := 0 + // l 表示当前遍历过程中的l for _, l := range lines { if strings.TrimSpace(l) != "" { valid++ @@ -222,8 +257,11 @@ func (c *Cards) AppendBatchData(ctx context.Context, cardID int64, content strin if valid == 0 { return 0, errors.New("无有效卡密行") } - for attempts := 0; attempts < 20; attempts++ { + for // attempts 保存尝试次数,供当前处理流程使用 + attempts := 0; attempts < 20; attempts++ { + // existing 保存existing,供当前处理流程使用 var existing sql.NullString + // err 保存err,供当前处理流程使用 err := c.DB.QueryRowContext(ctx, `SELECT data_content FROM cards WHERE id=?`, cardID).Scan(&existing) if err != nil { if errors.Is(err, sql.ErrNoRows) { @@ -231,17 +269,20 @@ func (c *Cards) AppendBatchData(ctx context.Context, cardID int64, content strin } return 0, err } + // merged 保存merged,供当前处理流程使用 merged := content if existing.Valid && existing.String != "" { merged = existing.String + "\n" + content } + // res、err 保存res、err,供当前处理流程使用 res, err := c.DB.ExecContext(ctx, `UPDATE cards SET data_content=?,updated_at=CURRENT_TIMESTAMP WHERE id=? AND COALESCE(data_content,'')=?`, merged, cardID, existing.String) if err != nil { return 0, err } - if affected, err := res.RowsAffected(); err == nil && affected == 1 { + if // affected、err 保存affected、err,供当前处理流程使用 + affected, err := res.RowsAffected(); err == nil && affected == 1 { return valid, nil } } @@ -250,8 +291,11 @@ func (c *Cards) AppendBatchData(ctx context.Context, cardID int64, content strin // splitLines / joinLines 统一处理多行库存内容。 func splitLines(s string) []string { + // out 保存out,供当前处理流程使用 var out []string + // cur 保存cur,供当前处理流程使用 cur := []rune{} + // r 表示当前遍历过程中的r for _, r := range s { switch r { case '\n': @@ -270,6 +314,7 @@ func splitLines(s string) []string { } // 过滤空行。 res := out[:0] + // l 表示当前遍历过程中的l for _, l := range out { if strings.TrimSpace(l) != "" { res = append(res, l) @@ -278,11 +323,14 @@ func splitLines(s string) []string { return res } +// joinLines 负责joinLines相关处理。 func joinLines(lines []string) string { if len(lines) == 0 { return "" } + // out 保存out,供当前处理流程使用 out := lines[0] + // l 表示当前遍历过程中的l for _, l := range lines[1:] { out += "\n" + l } diff --git a/internal/db/dialect.go b/internal/db/dialect.go index c27a1bd..f34d417 100644 --- a/internal/db/dialect.go +++ b/internal/db/dialect.go @@ -15,17 +15,23 @@ import ( // updateAssignments 是 列名 -> SQL表达式 的映射。表达式里用 "EXCLUDED.col" // 表示插入值(SQLite/Postgres 语法),MySQL 下自动转成 "VALUES(col)"。 // 其他表达式(如 "CURRENT_TIMESTAMP")原样保留。 +// DialectUpsert 负责DialectUpsert相关处理。 func DialectUpsert(d Dialect, conflictCols []string, updateAssignments map[string]string) string { if len(conflictCols) == 0 || len(updateAssignments) == 0 { return "" } + // keys 保存keys,供当前处理流程使用 keys := make([]string, 0, len(updateAssignments)) + // k 表示当前遍历过程中的k for k := range updateAssignments { keys = append(keys, k) } sortStrings(keys) + // sets 保存sets,供当前处理流程使用 sets := make([]string, 0, len(keys)) + // col 表示当前遍历过程中的col for _, col := range keys { + // expr 保存expr,供当前处理流程使用 expr := updateAssignments[col] if d == DialectMySQL { // EXCLUDED.col / excluded.col → VALUES(col)(大小写不敏感) @@ -54,6 +60,8 @@ func dialectUpsert(d Dialect, cols []string, m map[string]string) string { // // SQLite/Postgres: ON CONFLICT (cols) DO NOTHING // MySQL: 空(调用方应用 DialectInsertIgnorePrefix) +// +// DialectInsertIgnore 负责DialectInsertIgnore相关处理。 func DialectInsertIgnore(d Dialect, conflictCols []string) string { if d == DialectMySQL { return "" @@ -64,6 +72,7 @@ func DialectInsertIgnore(d Dialect, conflictCols []string) string { return " ON CONFLICT (" + strings.Join(conflictCols, ", ") + ") DO NOTHING" } +// dialectInsertIgnore 负责dialectInsertIgnore相关处理。 func dialectInsertIgnore(d Dialect, cols []string) string { return DialectInsertIgnore(d, cols) } // DialectInsertIgnorePrefix 返回 INSERT 前缀(MySQL 用 INSERT IGNORE)。 @@ -74,12 +83,15 @@ func DialectInsertIgnorePrefix(d Dialect) string { return "INSERT" } +// dialectInsertIgnorePrefix 负责dialectInsertIgnorePrefix相关处理。 func dialectInsertIgnorePrefix(d Dialect) string { return DialectInsertIgnorePrefix(d) } // DialectQuote 返回方言下的标识符引用。 // // SQLite/MySQL: `name`(反引号) // Postgres: "name"(双引号) +// +// DialectQuote 负责DialectQuote相关处理。 func DialectQuote(d Dialect, name string) string { if d == DialectPostgres { return "\"" + name + "\"" @@ -87,12 +99,15 @@ func DialectQuote(d Dialect, name string) string { return "`" + name + "`" } +// dialectQuote 负责dialectQuote相关处理。 func dialectQuote(d Dialect, name string) string { return DialectQuote(d, name) } // sortStrings 原地排序字符串切片。 func sortStrings(s []string) { - for i := 1; i < len(s); i++ { - for j := i; j > 0 && s[j-1] > s[j]; j-- { + for // i 保存i,供当前处理流程使用 + i := 1; i < len(s); i++ { + for // j 保存j,供当前处理流程使用 + j := i; j > 0 && s[j-1] > s[j]; j-- { s[j-1], s[j] = s[j], s[j-1] } } @@ -108,14 +123,18 @@ type DBTX interface { // Postgres 的 pgx driver 不支持 Result.LastInsertId(Postgres 无该概念), // 改用 `INSERT ... RETURNING id` + QueryRow.Scan;SQLite/MySQL 走 res.LastInsertId()。 // query 必须是可安全追加 ` RETURNING id` 的单条 INSERT(无尾随分号/ON CONFLICT 亦可)。 +// insertReturningID 负责insertReturningID相关处理。 func insertReturningID(ctx context.Context, exec DBTX, dialect Dialect, query string, args ...any) (int64, error) { if dialect == DialectPostgres { + // id 保存标识,供当前处理流程使用 var id int64 - if err := exec.QueryRowContext(ctx, query+" RETURNING id", args...).Scan(&id); err != nil { + if // err 保存err,供当前处理流程使用 + err := exec.QueryRowContext(ctx, query+" RETURNING id", args...).Scan(&id); err != nil { return 0, err } return id, nil } + // res、err 保存res、err,供当前处理流程使用 res, err := exec.ExecContext(ctx, query, args...) if err != nil { return 0, err diff --git a/internal/db/dialect_test.go b/internal/db/dialect_test.go index 8d1fff7..8699256 100644 --- a/internal/db/dialect_test.go +++ b/internal/db/dialect_test.go @@ -9,7 +9,9 @@ import ( // 关键不变量:SQLite/Postgres 用 ON CONFLICT...DO UPDATE SET,MySQL 用 ON DUPLICATE KEY UPDATE; // 列名按字典序输出(保证幂等可重现);MySQL 下 EXCLUDED.col 自动改写为 VALUES(col), // 大小写不敏感;CURRENT_TIMESTAMP 等非 EXCLUDED 表达式原样保留。 +// TestDialectUpsert 负责TestDialectUpsert相关处理。 func TestDialectUpsert(t *testing.T) { + // cases 保存cases,供当前处理流程使用 cases := []struct { name string d Dialect @@ -67,8 +69,10 @@ func TestDialectUpsert(t *testing.T) { want: "", }, } + // c 表示当前遍历过程中的c for _, c := range cases { t.Run(c.name, func(t *testing.T) { + // got 保存got,供当前处理流程使用 got := DialectUpsert(c.d, c.conflict, c.updates) if got != c.want { t.Errorf("DialectUpsert(%s) = %q; want %q", c.d, got, c.want) @@ -79,7 +83,9 @@ func TestDialectUpsert(t *testing.T) { // TestDialectInsertIgnore 断言“冲突即忽略”子句:MySQL 恒空(前缀模式负责), // SQLite/Postgres 生成 ON CONFLICT...DO NOTHING,空 conflictCols 时返回空。 +// TestDialectInsertIgnore 负责TestDialectInsertIgnore相关处理。 func TestDialectInsertIgnore(t *testing.T) { + // cases 保存cases,供当前处理流程使用 cases := []struct { d Dialect conflict []string @@ -91,7 +97,9 @@ func TestDialectInsertIgnore(t *testing.T) { {DialectMySQL, nil, ""}, {DialectSQLite, nil, ""}, } + // c 表示当前遍历过程中的c for _, c := range cases { + // got 保存got,供当前处理流程使用 got := DialectInsertIgnore(c.d, c.conflict) if got != c.want { t.Errorf("DialectInsertIgnore(%s, %v) = %q; want %q", c.d, c.conflict, got, c.want) @@ -101,19 +109,23 @@ func TestDialectInsertIgnore(t *testing.T) { // TestDialectInsertIgnorePrefix MySQL 走 INSERT IGNORE,其余走 INSERT。 func TestDialectInsertIgnorePrefix(t *testing.T) { - if got := DialectInsertIgnorePrefix(DialectMySQL); got != "INSERT IGNORE" { + if // got 保存got,供当前处理流程使用 + got := DialectInsertIgnorePrefix(DialectMySQL); got != "INSERT IGNORE" { t.Errorf("mysql prefix = %q; want INSERT IGNORE", got) } - if got := DialectInsertIgnorePrefix(DialectSQLite); got != "INSERT" { + if // got 保存got,供当前处理流程使用 + got := DialectInsertIgnorePrefix(DialectSQLite); got != "INSERT" { t.Errorf("sqlite prefix = %q; want INSERT", got) } - if got := DialectInsertIgnorePrefix(DialectPostgres); got != "INSERT" { + if // got 保存got,供当前处理流程使用 + got := DialectInsertIgnorePrefix(DialectPostgres); got != "INSERT" { t.Errorf("postgres prefix = %q; want INSERT", got) } } // TestDialectQuote Postgres 用双引号,SQLite/MySQL 用反引号。 func TestDialectQuote(t *testing.T) { + // cases 保存cases,供当前处理流程使用 cases := []struct { d Dialect name string @@ -124,8 +136,10 @@ func TestDialectQuote(t *testing.T) { {DialectPostgres, "users", `"users"`}, {DialectPostgres, "order_id", `"order_id"`}, } + // c 表示当前遍历过程中的c for _, c := range cases { - if got := DialectQuote(c.d, c.name); got != c.want { + if // got 保存got,供当前处理流程使用 + got := DialectQuote(c.d, c.name); got != c.want { t.Errorf("DialectQuote(%s, %q) = %q; want %q", c.d, c.name, got, c.want) } } @@ -133,10 +147,13 @@ func TestDialectQuote(t *testing.T) { // TestSortStrings 确认 sortStrings 原地升序排序(被 DialectUpsert 用于稳定输出顺序)。 func TestSortStrings(t *testing.T) { + // in 保存in,供当前处理流程使用 in := []string{"banana", "apple", "cherry", "apple"} sortStrings(in) + // want 保存want,供当前处理流程使用 want := "apple,apple,banana,cherry" - if got := strings.Join(in, ","); got != want { + if // got 保存got,供当前处理流程使用 + got := strings.Join(in, ","); got != want { t.Errorf("sortStrings = %q; want %q", got, want) } } diff --git a/internal/db/extras.go b/internal/db/extras.go index 7cf7461..236cb40 100644 --- a/internal/db/extras.go +++ b/internal/db/extras.go @@ -21,11 +21,14 @@ type KeywordRow struct { ImageURL string } +// UpdateByID 更新ByID。 func (k *Keywords) UpdateByID(ctx context.Context, row KeywordRow) error { + // kwType 保存kw类型,供当前处理流程使用 kwType := row.Type if kwType == "" { kwType = "text" } + // res、err 保存res、err,供当前处理流程使用 res, err := k.DB.ExecContext(ctx, `UPDATE keywords SET keyword=?,reply=?,item_id=?,type=?,image_url=? WHERE id=? AND cookie_id=?`, @@ -33,18 +36,22 @@ func (k *Keywords) UpdateByID(ctx context.Context, row KeywordRow) error { if err != nil { return err } - if affected, err := res.RowsAffected(); err == nil && affected == 0 { + if // affected、err 保存affected、err,供当前处理流程使用 + affected, err := res.RowsAffected(); err == nil && affected == 0 { return ErrNotFound } return nil } +// DeleteByID 删除ByID。 func (k *Keywords) DeleteByID(ctx context.Context, cookieID string, id int64) error { + // res、err 保存res、err,供当前处理流程使用 res, err := k.DB.ExecContext(ctx, `DELETE FROM keywords WHERE id=? AND cookie_id=?`, id, cookieID) if err != nil { return err } - if affected, err := res.RowsAffected(); err == nil && affected == 0 { + if // affected、err 保存affected、err,供当前处理流程使用 + affected, err := res.RowsAffected(); err == nil && affected == 0 { return ErrNotFound } return nil @@ -52,6 +59,7 @@ func (k *Keywords) DeleteByID(ctx context.Context, cookieID string, id int64) er // AllRows 取某账号所有关键字(含 id)。 func (k *Keywords) AllRows(ctx context.Context, cookieID string) ([]KeywordRow, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := k.DB.QueryContext(ctx, `SELECT id, keyword, reply, COALESCE(item_id,''), COALESCE(type,'text'), COALESCE(image_url,'') FROM keywords WHERE cookie_id=? ORDER BY id`, cookieID) @@ -59,10 +67,13 @@ func (k *Keywords) AllRows(ctx context.Context, cookieID string) ([]KeywordRow, return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []KeywordRow for rows.Next() { + // r 保存r,供当前处理流程使用 var r KeywordRow - if err := rows.Scan(&r.ID, &r.Keyword, &r.Reply, &r.ItemID, &r.Type, &r.ImageURL); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&r.ID, &r.Keyword, &r.Reply, &r.ItemID, &r.Type, &r.ImageURL); err != nil { return nil, err } r.CookieID = cookieID @@ -83,20 +94,25 @@ func (k *Keywords) Add(ctx context.Context, cookieID, keyword, reply, itemID, kw // ReplaceForCookie 覆盖某账号的全部关键词。 func (k *Keywords) ReplaceForCookie(ctx context.Context, cookieID string, rows []KeywordRow) error { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := k.DB.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() - if _, err := tx.ExecContext(ctx, `DELETE FROM keywords WHERE cookie_id=?`, cookieID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `DELETE FROM keywords WHERE cookie_id=?`, cookieID); err != nil { return err } + // row 表示当前遍历过程中的row for _, row := range rows { + // kwType 保存kw类型,供当前处理流程使用 kwType := row.Type if kwType == "" { kwType = "text" } - if _, err := tx.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `INSERT INTO keywords (cookie_id, keyword, reply, item_id, type, image_url) VALUES (?,?,?,?,?,?)`, cookieID, row.Keyword, row.Reply, nullable(row.ItemID), kwType, nullable(row.ImageURL)); err != nil { return err @@ -107,16 +123,20 @@ func (k *Keywords) ReplaceForCookie(ctx context.Context, cookieID string, rows [ // DeleteByIndex 按索引(0-based,按 id 顺序)删除某账号的一个关键字。 func (k *Keywords) DeleteByIndex(ctx context.Context, cookieID string, index int) error { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := k.DB.QueryContext(ctx, `SELECT id FROM keywords WHERE cookie_id=? ORDER BY id`, cookieID) if err != nil { return err } defer rows.Close() + // ids 保存ids,供当前处理流程使用 var ids []int64 for rows.Next() { + // id 保存标识,供当前处理流程使用 var id int64 - if err := rows.Scan(&id); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&id); err != nil { return err } ids = append(ids, id) @@ -134,6 +154,7 @@ func (k *Keywords) DeleteByIndex(ctx context.Context, cookieID string, index int // Set 设置指定商品回复。 func (i *ItemReplies) Set(ctx context.Context, cookieID, itemID, content string) error { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := i.DB.BeginTx(ctx, nil) if err != nil { return err @@ -143,7 +164,8 @@ func (i *ItemReplies) Set(ctx context.Context, cookieID, itemID, content string) if _, err := tx.ExecContext(ctx, `DELETE FROM item_replay WHERE cookie_id=? AND item_id=?`, cookieID, itemID); err != nil { return err } - if _, err := tx.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `INSERT INTO item_replay (item_id, cookie_id, reply_content, updated_at) VALUES (?,?,?,CURRENT_TIMESTAMP)`, itemID, cookieID, content); err != nil { return err @@ -153,6 +175,7 @@ func (i *ItemReplies) Set(ctx context.Context, cookieID, itemID, content string) // Delete 删除指定商品回复。 func (i *ItemReplies) Delete(ctx context.Context, cookieID, itemID string) error { + // err 保存err,供当前处理流程使用 _, err := i.DB.ExecContext(ctx, `DELETE FROM item_replay WHERE cookie_id=? AND item_id=?`, cookieID, itemID) return err @@ -160,16 +183,20 @@ func (i *ItemReplies) Delete(ctx context.Context, cookieID, itemID string) error // AllForUser 取某账号所有指定商品回复。 func (i *ItemReplies) AllForUser(ctx context.Context, cookieID string) ([]ItemReply, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := i.DB.QueryContext(ctx, `SELECT item_id, cookie_id, reply_content FROM item_replay WHERE cookie_id=?`, cookieID) if err != nil { return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []ItemReply for rows.Next() { + // r 保存r,供当前处理流程使用 var r ItemReply - if err := rows.Scan(&r.ItemID, &r.CookieID, &r.ReplyContent); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&r.ItemID, &r.CookieID, &r.ReplyContent); err != nil { return nil, err } out = append(out, r) @@ -192,6 +219,7 @@ type NotificationChannelRow struct { // AllChannelsForUser 取某用户全部通知渠道。 func (n *Notifications) AllChannelsForUser(ctx context.Context, userID int64) ([]NotificationChannelRow, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := n.DB.QueryContext(ctx, `SELECT id, name, type, config, COALESCE(event_types,''), enabled, COALESCE(user_id,1) FROM notification_channels WHERE user_id=? ORDER BY id DESC`, userID) @@ -199,11 +227,15 @@ func (n *Notifications) AllChannelsForUser(ctx context.Context, userID int64) ([ return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []NotificationChannelRow for rows.Next() { + // c 保存c,供当前处理流程使用 var c NotificationChannelRow + // enabled 保存启用状态,供当前处理流程使用 var enabled int - if err := rows.Scan(&c.ID, &c.Name, &c.Type, &c.Config, &c.EventTypes, &enabled, &c.UserID); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&c.ID, &c.Name, &c.Type, &c.Config, &c.EventTypes, &enabled, &c.UserID); err != nil { return nil, err } c.Config, err = n.codec.decrypt("notification-config", strconv.FormatInt(c.UserID, 10), c.Config) @@ -218,6 +250,7 @@ func (n *Notifications) AllChannelsForUser(ctx context.Context, userID int64) ([ // CreateChannel 创建通知渠道。 func (n *Notifications) CreateChannel(ctx context.Context, c *NotificationChannelRow) (int64, error) { + // config、err 保存config、err,供当前处理流程使用 config, err := n.codec.encrypt("notification-config", strconv.FormatInt(c.UserID, 10), c.Config) if err != nil { return 0, err @@ -230,10 +263,12 @@ func (n *Notifications) CreateChannel(ctx context.Context, c *NotificationChanne // UpdateChannel 更新通知渠道。 func (n *Notifications) UpdateChannel(ctx context.Context, c *NotificationChannelRow) error { if c.UserID == 0 { - if err := n.DB.QueryRowContext(ctx, `SELECT COALESCE(user_id,1) FROM notification_channels WHERE id=?`, c.ID).Scan(&c.UserID); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.DB.QueryRowContext(ctx, `SELECT COALESCE(user_id,1) FROM notification_channels WHERE id=?`, c.ID).Scan(&c.UserID); err != nil { return err } } + // config、err 保存config、err,供当前处理流程使用 config, err := n.codec.encrypt("notification-config", strconv.FormatInt(c.UserID, 10), c.Config) if err != nil { return err @@ -246,18 +281,23 @@ func (n *Notifications) UpdateChannel(ctx context.Context, c *NotificationChanne // GetChannelRowForUser 按用户取单个通知渠道。未找到返回 nil。 func (n *Notifications) GetChannelRowForUser(ctx context.Context, id, userID int64) (*NotificationChannelRow, error) { + // row 保存row,供当前处理流程使用 row := n.DB.QueryRowContext(ctx, `SELECT id, name, type, config, COALESCE(event_types,''), enabled, COALESCE(user_id,1) FROM notification_channels WHERE id=? AND user_id=?`, id, userID) + // c 保存c,供当前处理流程使用 var c NotificationChannelRow + // enabled 保存启用状态,供当前处理流程使用 var enabled int - if err := row.Scan(&c.ID, &c.Name, &c.Type, &c.Config, &c.EventTypes, &enabled, &c.UserID); err != nil { + if // err 保存err,供当前处理流程使用 + err := row.Scan(&c.ID, &c.Name, &c.Type, &c.Config, &c.EventTypes, &enabled, &c.UserID); err != nil { if errors.Is(err, sql.ErrNoRows) { return nil, nil } return nil, err } c.Enabled = enabled != 0 + // config、err 保存config、err,供当前处理流程使用 config, err := n.codec.decrypt("notification-config", strconv.FormatInt(c.UserID, 10), c.Config) if err != nil { return nil, err @@ -268,10 +308,12 @@ func (n *Notifications) GetChannelRowForUser(ctx context.Context, id, userID int // UpdateChannelForUser 更新指定用户拥有的通知渠道。 func (n *Notifications) UpdateChannelForUser(ctx context.Context, c *NotificationChannelRow, userID int64) error { + // config、err 保存config、err,供当前处理流程使用 config, err := n.codec.encrypt("notification-config", strconv.FormatInt(userID, 10), c.Config) if err != nil { return err } + // res、err 保存res、err,供当前处理流程使用 res, err := n.DB.ExecContext(ctx, `UPDATE notification_channels SET name=?, type=?, config=?, event_types=?, enabled=?, updated_at=CURRENT_TIMESTAMP @@ -280,6 +322,7 @@ func (n *Notifications) UpdateChannelForUser(ctx context.Context, c *Notificatio if err != nil { return err } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := res.RowsAffected() if err == nil && rows == 0 { return ErrNotFound @@ -289,16 +332,19 @@ func (n *Notifications) UpdateChannelForUser(ctx context.Context, c *Notificatio // DeleteChannel 删除通知渠道。 func (n *Notifications) DeleteChannel(ctx context.Context, id int64) error { + // err 保存err,供当前处理流程使用 _, err := n.DB.ExecContext(ctx, `DELETE FROM notification_channels WHERE id=?`, id) return err } // DeleteChannelForUser 删除指定用户拥有的通知渠道。 func (n *Notifications) DeleteChannelForUser(ctx context.Context, id, userID int64) error { + // res、err 保存res、err,供当前处理流程使用 res, err := n.DB.ExecContext(ctx, `DELETE FROM notification_channels WHERE id=? AND user_id=?`, id, userID) if err != nil { return err } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := res.RowsAffected() if err == nil && rows == 0 { return ErrNotFound @@ -308,16 +354,21 @@ func (n *Notifications) DeleteChannelForUser(ctx context.Context, id, userID int // GetChannel 按 ID 取单个通知渠道(含 config)。未找到返回 nil。 func (n *Notifications) GetChannel(ctx context.Context, id int64) (*NotificationChannel, error) { + // row 保存row,供当前处理流程使用 row := n.DB.QueryRowContext(ctx, `SELECT id, name, type, config, COALESCE(event_types,''), COALESCE(user_id,1) FROM notification_channels WHERE id=?`, id) + // c 保存c,供当前处理流程使用 var c NotificationChannel + // userID 保存用户ID,供当前处理流程使用 var userID int64 - if err := row.Scan(&c.ID, &c.Name, &c.Type, &c.Config, &c.EventTypes, &userID); err != nil { + if // err 保存err,供当前处理流程使用 + err := row.Scan(&c.ID, &c.Name, &c.Type, &c.Config, &c.EventTypes, &userID); err != nil { if errors.Is(err, sql.ErrNoRows) { return nil, nil } return nil, err } + // config、err 保存config、err,供当前处理流程使用 config, err := n.codec.decrypt("notification-config", strconv.FormatInt(userID, 10), c.Config) if err != nil { return nil, err @@ -328,6 +379,7 @@ func (n *Notifications) GetChannel(ctx context.Context, id int64) (*Notification // AccountBindings 取某账号已绑定的通知渠道 ID 列表。 func (n *Notifications) AccountBindings(ctx context.Context, cookieID string) ([]int64, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := n.DB.QueryContext(ctx, `SELECT mn.channel_id FROM message_notifications mn @@ -338,10 +390,13 @@ func (n *Notifications) AccountBindings(ctx context.Context, cookieID string) ([ return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []int64 for rows.Next() { + // id 保存标识,供当前处理流程使用 var id int64 - if err := rows.Scan(&id); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&id); err != nil { return nil, err } out = append(out, id) @@ -351,21 +406,27 @@ func (n *Notifications) AccountBindings(ctx context.Context, cookieID string) ([ // SetBindings 设置某账号的通知渠道绑定(覆盖式)。 func (n *Notifications) SetBindings(ctx context.Context, cookieID string, channelIDs []int64) error { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := n.DB.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() + // userID 保存用户ID,供当前处理流程使用 var userID int64 - if err := tx.QueryRowContext(ctx, `SELECT user_id FROM cookies WHERE id=?`, cookieID).Scan(&userID); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.QueryRowContext(ctx, `SELECT user_id FROM cookies WHERE id=?`, cookieID).Scan(&userID); err != nil { if errors.Is(err, sql.ErrNoRows) { return ErrNotFound } return err } + // channelID 表示当前遍历过程中的渠道ID for _, channelID := range channelIDs { + // exists 保存exists,供当前处理流程使用 var exists bool - if err := tx.QueryRowContext(ctx, + if // err 保存err,供当前处理流程使用 + err := tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM notification_channels WHERE id=? AND user_id=?)`, channelID, userID).Scan(&exists); err != nil { return err @@ -374,11 +435,14 @@ func (n *Notifications) SetBindings(ctx context.Context, cookieID string, channe return ErrForbidden } } - if _, err := tx.ExecContext(ctx, `DELETE FROM message_notifications WHERE cookie_id=?`, cookieID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `DELETE FROM message_notifications WHERE cookie_id=?`, cookieID); err != nil { return err } + // cid 表示当前遍历过程中的cid for _, cid := range channelIDs { - if _, err := tx.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `INSERT INTO message_notifications (cookie_id, channel_id, enabled) VALUES (?,?,1)`, cookieID, cid); err != nil { return err @@ -398,8 +462,11 @@ type SystemSettings struct { // Get 取单项设置。 func (s *SystemSettings) Get(ctx context.Context, key string) (string, error) { + // v 保存v,供当前处理流程使用 var v string + // keyCol 保存keyCol,供当前处理流程使用 keyCol := dialectQuote(s.Dialect, "key") + // err 保存err,供当前处理流程使用 err := s.DB.QueryRowContext(ctx, `SELECT value FROM system_settings WHERE `+keyCol+`=?`, key).Scan(&v) if err != nil { if errors.Is(err, sql.ErrNoRows) { @@ -415,16 +482,21 @@ func (s *SystemSettings) Get(ctx context.Context, key string) (string, error) { // All 取全部设置(key→value)。 func (s *SystemSettings) All(ctx context.Context) (map[string]string, error) { + // keyCol 保存keyCol,供当前处理流程使用 keyCol := dialectQuote(s.Dialect, "key") + // rows、err 保存rows、err,供当前处理流程使用 rows, err := s.DB.QueryContext(ctx, `SELECT `+keyCol+`, value FROM system_settings`) if err != nil { return nil, err } defer rows.Close() + // m 保存m,供当前处理流程使用 m := make(map[string]string) for rows.Next() { + // k、v 保存k、v,供当前处理流程使用 var k, v string - if err := rows.Scan(&k, &v); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&k, &v); err != nil { return nil, err } if isSensitiveSettingKey(k) { @@ -441,13 +513,16 @@ func (s *SystemSettings) All(ctx context.Context) (map[string]string, error) { // Set 设置单项。 func (s *SystemSettings) Set(ctx context.Context, key, value string) error { if isSensitiveSettingKey(key) { + // encrypted、err 保存encrypted、err,供当前处理流程使用 encrypted, err := s.codec.encrypt("system-setting", key, value) if err != nil { return err } value = encrypted } + // keyCol 保存keyCol,供当前处理流程使用 keyCol := dialectQuote(s.Dialect, "key") + // err 保存err,供当前处理流程使用 _, err := s.DB.ExecContext(ctx, `INSERT INTO system_settings (`+keyCol+`, value, updated_at) VALUES (?,?,CURRENT_TIMESTAMP)`+ dialectUpsert(s.Dialect, []string{keyCol}, map[string]string{ @@ -460,25 +535,31 @@ func (s *SystemSettings) Set(ctx context.Context, key, value string) error { // SetMany 在单个事务中原子保存多项设置。 func (s *SystemSettings) SetMany(ctx context.Context, values map[string]string) error { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := s.DB.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() + // keyCol 保存keyCol,供当前处理流程使用 keyCol := dialectQuote(s.Dialect, "key") + // query 保存查询,供当前处理流程使用 query := `INSERT INTO system_settings (` + keyCol + `, value, updated_at) VALUES (?,?,CURRENT_TIMESTAMP)` + dialectUpsert(s.Dialect, []string{keyCol}, map[string]string{ "value": "EXCLUDED.value", "updated_at": "CURRENT_TIMESTAMP", }) + // key、value 表示当前遍历过程中的key、value for key, value := range values { if isSensitiveSettingKey(key) { + // encrypted、err 保存encrypted、err,供当前处理流程使用 encrypted, err := s.codec.encrypt("system-setting", key, value) if err != nil { return err } value = encrypted } - if _, err := tx.ExecContext(ctx, query, key, value); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, query, key, value); err != nil { return err } } @@ -492,13 +573,17 @@ var PublicSystemKeys = map[string]bool{ // Public 取公开设置子集。 func (s *SystemSettings) Public(ctx context.Context) (map[string]string, error) { + // all、err 保存all、err,供当前处理流程使用 all, err := s.All(ctx) if err != nil { return nil, err } + // out 保存out,供当前处理流程使用 out := make(map[string]string) + // k 表示当前遍历过程中的k for k := range PublicSystemKeys { - if v, ok := all[k]; ok { + if // v、ok 保存v、ok,供当前处理流程使用 + v, ok := all[k]; ok { out[k] = v } } @@ -529,6 +614,7 @@ type ItemSyncResult struct { // AllForCookie 取某账号全部商品。 func (i *Items) AllForCookie(ctx context.Context, cookieID string) ([]ItemInfoRow, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := i.DB.QueryContext(ctx, `SELECT id, cookie_id, item_id, COALESCE(item_title,''), COALESCE(item_description,''), COALESCE(item_category,''), COALESCE(item_price,''), COALESCE(item_detail,''), @@ -538,11 +624,15 @@ func (i *Items) AllForCookie(ctx context.Context, cookieID string) ([]ItemInfoRo return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []ItemInfoRow for rows.Next() { + // r 保存r,供当前处理流程使用 var r ItemInfoRow + // isMulti、multiQty 保存isMulti、multiQty,供当前处理流程使用 var isMulti, multiQty int - if err := rows.Scan(&r.ID, &r.CookieID, &r.ItemID, &r.ItemTitle, &r.ItemDescription, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&r.ID, &r.CookieID, &r.ItemID, &r.ItemTitle, &r.ItemDescription, &r.ItemCategory, &r.ItemPrice, &r.ItemDetail, &isMulti, &multiQty); err != nil { return nil, err } @@ -555,6 +645,7 @@ func (i *Items) AllForCookie(ctx context.Context, cookieID string) ([]ItemInfoRo // Upsert 插入或更新商品信息。 func (i *Items) Upsert(ctx context.Context, r *ItemInfoRow) error { + // err 保存err,供当前处理流程使用 _, err := i.DB.ExecContext(ctx, `INSERT INTO item_info (cookie_id, item_id, item_title, item_description, item_category, item_price, item_detail, is_multi_spec, multi_quantity_delivery, updated_at) @@ -581,6 +672,7 @@ func (i *Items) UpsertBasic(ctx context.Context, r *ItemInfoRow) error { return i.upsertBasic(ctx, i.DB, r) } +// UpsertBasicTx 负责UpsertBasicTx相关处理。 func (i *Items) UpsertBasicTx(ctx context.Context, tx *sql.Tx, r *ItemInfoRow) error { return i.upsertBasic(ctx, tx, r) } @@ -590,41 +682,51 @@ func (i *Items) UpsertBasicTx(ctx context.Context, tx *sql.Tx, r *ItemInfoRow) e // 远端列表只提供商品基础信息,因此保留本地的描述和发货配置;基础字段 // (标题、分类、价格、详情)由远端非空值覆盖。整个 reconcile 在一个事务内 // 完成,只有在全部远端商品写入成功后,才会逻辑删除本次全集中不存在的本地商品及其商品级自动化规则。 +// SyncFromRemote 同步FromRemote。 func (i *Items) SyncFromRemote(ctx context.Context, cookieID string, rows []ItemInfoRow) (ItemSyncResult, error) { cookieID = strings.TrimSpace(cookieID) if cookieID == "" { return ItemSyncResult{}, errors.New("cookie_id 不能为空") } + // remoteIDs 保存remoteIDs,供当前处理流程使用 remoteIDs := make(map[string]struct{}, len(rows)) + // validRows 保存有效Rows,供当前处理流程使用 validRows := make([]ItemInfoRow, 0, len(rows)) + // row 表示当前遍历过程中的row for _, row := range rows { row.CookieID = cookieID row.ItemID = strings.TrimSpace(row.ItemID) if row.ItemID == "" { continue } - if _, exists := remoteIDs[row.ItemID]; exists { + if // exists 保存exists,供当前处理流程使用 + _, exists := remoteIDs[row.ItemID]; exists { continue } remoteIDs[row.ItemID] = struct{}{} validRows = append(validRows, row) } + // tx、err 保存tx、err,供当前处理流程使用 tx, err := i.DB.BeginTx(ctx, nil) if err != nil { return ItemSyncResult{}, err } + // rollback 保存rollback,供当前处理流程使用 rollback := func(err error) (ItemSyncResult, error) { _ = tx.Rollback() return ItemSyncResult{}, err } + // index 表示当前遍历过程中的index for index := range validRows { - if err := i.UpsertBasicTx(ctx, tx, &validRows[index]); err != nil { + if // err 保存err,供当前处理流程使用 + err := i.UpsertBasicTx(ctx, tx, &validRows[index]); err != nil { return rollback(err) } if validRows[index].IsMultiSpec { - if _, err := tx.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `UPDATE item_info SET is_multi_spec=? WHERE cookie_id=? AND item_id=?`, boolToInt(true), cookieID, validRows[index].ItemID); err != nil { return rollback(err) @@ -632,51 +734,65 @@ func (i *Items) SyncFromRemote(ctx context.Context, cookieID string, rows []Item } } + // args 保存args,供当前处理流程使用 args := make([]any, 0, len(remoteIDs)+1) args = append(args, cookieID) + // deleteQuery 保存delete查询,供当前处理流程使用 deleteQuery := `UPDATE item_info SET deleted_at=CURRENT_TIMESTAMP, updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND deleted_at IS NULL` if len(remoteIDs) > 0 { + // placeholders 保存placeholders,供当前处理流程使用 placeholders := make([]string, 0, len(remoteIDs)) + // itemID 表示当前遍历过程中的商品ID for itemID := range remoteIDs { placeholders = append(placeholders, "?") args = append(args, itemID) } deleteQuery += ` AND item_id NOT IN (` + strings.Join(placeholders, ",") + ")" } + // deletedResult、err 保存deletedResult、err,供当前处理流程使用 deletedResult, err := tx.ExecContext(ctx, deleteQuery, args...) if err != nil { return rollback(err) } + // deleted、err 保存deleted、err,供当前处理流程使用 deleted, err := deletedResult.RowsAffected() if err != nil { return rollback(err) } + // ruleArgs 保存规则Args,供当前处理流程使用 ruleArgs := make([]any, 0, len(remoteIDs)+1) ruleArgs = append(ruleArgs, cookieID) + // ruleQuery 保存规则查询,供当前处理流程使用 ruleQuery := `UPDATE automation_rules SET deleted_at=CURRENT_TIMESTAMP, enabled=0, updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND item_id<>'' AND deleted_at IS NULL` if len(remoteIDs) > 0 { + // placeholders 保存placeholders,供当前处理流程使用 placeholders := make([]string, 0, len(remoteIDs)) + // itemID 表示当前遍历过程中的商品ID for itemID := range remoteIDs { placeholders = append(placeholders, "?") ruleArgs = append(ruleArgs, itemID) } ruleQuery += ` AND item_id NOT IN (` + strings.Join(placeholders, ",") + ")" } - if _, err := tx.ExecContext(ctx, ruleQuery, ruleArgs...); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, ruleQuery, ruleArgs...); err != nil { return rollback(err) } - if err := tx.Commit(); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.Commit(); err != nil { return ItemSyncResult{}, err } return ItemSyncResult{Saved: len(validRows), Deleted: int(deleted)}, nil } +// upsertBasic 负责upsertBasic相关处理。 func (i *Items) upsertBasic(ctx context.Context, execer sqlExecer, r *ItemInfoRow) error { // 三种数据库的条件 upsert:非空才覆盖,空值保留旧值。 // SQLite/Postgres 用 EXCLUDED.col 引用插入值;MySQL 用 VALUES(col)。 + // conflictClause 保存conflictClause,供当前处理流程使用 var conflictClause string switch i.Dialect { case DialectMySQL: @@ -698,6 +814,7 @@ func (i *Items) upsertBasic(ctx context.Context, execer sqlExecer, r *ItemInfoRo deleted_at=NULL, updated_at=CURRENT_TIMESTAMP` } + // err 保存err,供当前处理流程使用 _, err := execer.ExecContext(ctx, `INSERT INTO item_info (cookie_id, item_id, item_title, item_description, item_category, item_price, item_detail, updated_at) @@ -709,17 +826,20 @@ func (i *Items) upsertBasic(ctx context.Context, execer sqlExecer, r *ItemInfoRo // Delete 逻辑删除商品及其商品级自动化规则,保留历史数据以便审计和恢复。 func (i *Items) Delete(ctx context.Context, cookieID, itemID string) error { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := i.DB.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() - if _, err := tx.ExecContext(ctx, `UPDATE item_info + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `UPDATE item_info SET deleted_at=CURRENT_TIMESTAMP, updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND item_id=? AND deleted_at IS NULL`, cookieID, itemID); err != nil { return err } - if _, err := tx.ExecContext(ctx, `UPDATE automation_rules + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `UPDATE automation_rules SET deleted_at=CURRENT_TIMESTAMP, enabled=0, updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND item_id=? AND deleted_at IS NULL`, cookieID, itemID); err != nil { return err @@ -729,6 +849,7 @@ func (i *Items) Delete(ctx context.Context, cookieID, itemID string) error { // SetMultiSpec 设置多规格开关。 func (i *Items) SetMultiSpec(ctx context.Context, cookieID, itemID string, on bool) error { + // err 保存err,供当前处理流程使用 _, err := i.DB.ExecContext(ctx, `UPDATE item_info SET is_multi_spec=?, updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND item_id=? AND deleted_at IS NULL`, boolToInt(on), cookieID, itemID) @@ -737,6 +858,7 @@ func (i *Items) SetMultiSpec(ctx context.Context, cookieID, itemID string, on bo // SetMultiQuantity 设置多数量发货开关。 func (i *Items) SetMultiQuantity(ctx context.Context, cookieID, itemID string, on bool) error { + // err 保存err,供当前处理流程使用 _, err := i.DB.ExecContext(ctx, `UPDATE item_info SET multi_quantity_delivery=?, updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND item_id=? AND deleted_at IS NULL`, boolToInt(on), cookieID, itemID) diff --git a/internal/db/extras_repository_test.go b/internal/db/extras_repository_test.go index e50b81f..8418601 100644 --- a/internal/db/extras_repository_test.go +++ b/internal/db/extras_repository_test.go @@ -6,59 +6,78 @@ import ( "testing" ) +// TestExtraRepositoriesCRUD 负责TestExtraRepositoriesCRUD相关处理。 func TestExtraRepositoriesCRUD(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if ok, err := store.Users.Create(ctx, "user1", "u1@example.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := store.Users.Create(ctx, "user1", "u1@example.com", "pw"); err != nil || !ok { t.Fatalf("create user: %v, %v", ok, err) } + // user 保存用户,供当前处理流程使用 user, _ := store.Users.GetByUsername(ctx, "user1") - if err := store.Cookies.Save(ctx, "acc1", "unb=1", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.Save(ctx, "acc1", "unb=1", user.ID); err != nil { t.Fatal(err) } + // id、err 保存id、err,供当前处理流程使用 id, err := store.Keywords.Add(ctx, "acc1", "hello", "world", "item1", "text", "") if err != nil || id == 0 { t.Fatalf("add keyword: %d, %v", id, err) } + // keywords 保存keywords,供当前处理流程使用 keywords, _ := store.Keywords.AllRows(ctx, "acc1") if len(keywords) != 1 || keywords[0].Reply != "world" { t.Fatalf("keywords = %#v", keywords) } - if err := store.Keywords.DeleteByIndex(ctx, "acc1", 0); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Keywords.DeleteByIndex(ctx, "acc1", 0); err != nil { t.Fatal(err) } - if err := store.Keywords.DeleteByIndex(ctx, "acc1", 0); err != ErrNotFound { + if // err 保存err,供当前处理流程使用 + err := store.Keywords.DeleteByIndex(ctx, "acc1", 0); err != ErrNotFound { t.Fatalf("delete missing keyword = %v", err) } - if err := store.ItemReps.Set(ctx, "acc1", "item1", "reply"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.ItemReps.Set(ctx, "acc1", "item1", "reply"); err != nil { t.Fatal(err) } + // replies 保存回复列表,供当前处理流程使用 replies, _ := store.ItemReps.AllForUser(ctx, "acc1") if len(replies) != 1 || replies[0].ReplyContent != "reply" { t.Fatalf("item replies = %#v", replies) } - if err := store.ItemReps.Delete(ctx, "acc1", "item1"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.ItemReps.Delete(ctx, "acc1", "item1"); err != nil { t.Fatal(err) } + // item 保存商品,供当前处理流程使用 item := &ItemInfoRow{CookieID: "acc1", ItemID: "item1", ItemTitle: "title", ItemPrice: "9.90"} - if err := store.Items.Upsert(ctx, item); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Items.Upsert(ctx, item); err != nil { t.Fatal(err) } - if err := store.Items.SetMultiSpec(ctx, "acc1", "item1", true); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Items.SetMultiSpec(ctx, "acc1", "item1", true); err != nil { t.Fatal(err) } - if err := store.Items.SetMultiQuantity(ctx, "acc1", "item1", true); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Items.SetMultiQuantity(ctx, "acc1", "item1", true); err != nil { t.Fatal(err) } + // items 保存商品列表,供当前处理流程使用 items, _ := store.Items.AllForCookie(ctx, "acc1") if len(items) != 1 || !items[0].IsMultiSpec || !items[0].MultiQuantityDelivery { t.Fatalf("items = %#v", items) } - if err := store.Items.UpsertBasic(ctx, &ItemInfoRow{CookieID: "acc1", ItemID: "item1", ItemTitle: "updated"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Items.UpsertBasic(ctx, &ItemInfoRow{CookieID: "acc1", ItemID: "item1", ItemTitle: "updated"}); err != nil { t.Fatal(err) } items, _ = store.Items.AllForCookie(ctx, "acc1") @@ -66,76 +85,97 @@ func TestExtraRepositoriesCRUD(t *testing.T) { t.Fatalf("upsert basic overwrote flags: %#v", items[0]) } + // channelID、err 保存渠道ID、err,供当前处理流程使用 channelID, err := store.Notifications.CreateChannel(ctx, &NotificationChannelRow{ Name: "webhook", Type: "webhook", Config: `{}`, Enabled: true, UserID: user.ID, }) if err != nil { t.Fatal(err) } - if err := store.Notifications.SetBindings(ctx, "acc1", []int64{channelID}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Notifications.SetBindings(ctx, "acc1", []int64{channelID}); err != nil { t.Fatal(err) } + // bindings 保存bindings,供当前处理流程使用 bindings, _ := store.Notifications.AccountBindings(ctx, "acc1") if len(bindings) != 1 || bindings[0] != channelID { t.Fatalf("bindings = %#v", bindings) } + // channels 保存渠道列表,供当前处理流程使用 channels, _ := store.Notifications.AllChannelsForUser(ctx, user.ID) if len(channels) != 1 || !channels[0].Enabled { t.Fatalf("channels = %#v", channels) } channels[0].Name = "updated" - if err := store.Notifications.UpdateChannel(ctx, &channels[0]); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Notifications.UpdateChannel(ctx, &channels[0]); err != nil { t.Fatal(err) } - if err := store.Notifications.DeleteChannel(ctx, channelID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Notifications.DeleteChannel(ctx, channelID); err != nil { t.Fatal(err) } - if err := store.Settings.Set(ctx, "theme_color", "blue"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, "theme_color", "blue"); err != nil { t.Fatal(err) } - if err := store.Settings.Set(ctx, "private_key", "secret"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, "private_key", "secret"); err != nil { t.Fatal(err) } + // public、err 保存public、err,供当前处理流程使用 public, err := store.Settings.Public(ctx) if err != nil || public["theme_color"] != "blue" || public["private_key"] != "" { t.Fatalf("public settings = %#v, %v", public, err) } - if err := store.Items.Delete(ctx, "acc1", "item1"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Items.Delete(ctx, "acc1", "item1"); err != nil { t.Fatal(err) } } +// TestItemsSyncFromRemoteReconcilesAndPreservesLocalSettings 负责Test商品列表SyncFromRemoteReconcilesAndPreservesLocal设置相关处理。 func TestItemsSyncFromRemoteReconcilesAndPreservesLocalSettings(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // ok、err 保存ok、err,供当前处理流程使用 ok, err := store.Users.Create(ctx, "sync-user", "sync@example.com", "password") if err != nil || !ok { t.Fatalf("create test user: ok=%v err=%v", ok, err) } + // user、err 保存user、err,供当前处理流程使用 user, err := store.Users.GetByUsername(ctx, "sync-user") if err != nil { t.Fatal(err) } - if err := store.Cookies.Save(ctx, "acc1", "unb=1", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.Save(ctx, "acc1", "unb=1", user.ID); err != nil { t.Fatal(err) } - if err := store.Items.Upsert(ctx, &ItemInfoRow{ + if // err 保存err,供当前处理流程使用 + err := store.Items.Upsert(ctx, &ItemInfoRow{ CookieID: "acc1", ItemID: "existing", ItemTitle: "旧标题", ItemDescription: "本地描述", ItemPrice: "¥9.90", }); err != nil { t.Fatal(err) } - if err := store.Items.SetMultiSpec(ctx, "acc1", "existing", true); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Items.SetMultiSpec(ctx, "acc1", "existing", true); err != nil { t.Fatal(err) } - if err := store.Items.SetMultiQuantity(ctx, "acc1", "existing", true); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Items.SetMultiQuantity(ctx, "acc1", "existing", true); err != nil { t.Fatal(err) } - if err := store.Items.Upsert(ctx, &ItemInfoRow{CookieID: "acc1", ItemID: "deleted"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Items.Upsert(ctx, &ItemInfoRow{CookieID: "acc1", ItemID: "deleted"}); err != nil { t.Fatal(err) } + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := store.Automation.Create(ctx, AutomationRuleInput{ UserID: user.ID, CookieID: "acc1", ItemID: "deleted", Name: "删除商品规则", TriggerType: "paid", Enabled: true, Priority: 100, @@ -145,6 +185,7 @@ func TestItemsSyncFromRemoteReconcilesAndPreservesLocalSettings(t *testing.T) { t.Fatal(err) } + // result、err 保存result、err,供当前处理流程使用 result, err := store.Items.SyncFromRemote(ctx, "acc1", []ItemInfoRow{ {CookieID: "wrong-cookie", ItemID: "existing", ItemTitle: "新标题", ItemPrice: "¥19.90", IsMultiSpec: true}, {ItemID: "new", ItemTitle: "新商品", ItemPrice: "¥3.00"}, @@ -156,6 +197,7 @@ func TestItemsSyncFromRemoteReconcilesAndPreservesLocalSettings(t *testing.T) { t.Fatalf("sync result=%+v, want saved=2 deleted=1", result) } + // items、err 保存items、err,供当前处理流程使用 items, err := store.Items.AllForCookie(ctx, "acc1") if err != nil { t.Fatal(err) @@ -163,6 +205,7 @@ func TestItemsSyncFromRemoteReconcilesAndPreservesLocalSettings(t *testing.T) { if len(items) != 2 { t.Fatalf("items=%+v, want 2 rows", items) } + // item、err 保存item、err,供当前处理流程使用 item, err := store.Items.Get(ctx, "acc1", "existing") if err != nil { t.Fatal(err) @@ -171,26 +214,33 @@ func TestItemsSyncFromRemoteReconcilesAndPreservesLocalSettings(t *testing.T) { !item.IsMultiSpec || !item.MultiQuantityDelivery { t.Fatalf("existing item was not updated/preserved: %+v", item) } - if _, err := store.Items.Get(ctx, "acc1", "deleted"); err != ErrNotFound { + if // err 保存err,供当前处理流程使用 + _, err := store.Items.Get(ctx, "acc1", "deleted"); err != ErrNotFound { t.Fatalf("deleted item should be hidden from active lookup: err=%v", err) } + // itemDeletedAt 保存商品DeletedAt,供当前处理流程使用 var itemDeletedAt sql.NullString - if err := store.DB.QueryRowContext(ctx, + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT deleted_at FROM item_info WHERE cookie_id=? AND item_id=?`, "acc1", "deleted").Scan(&itemDeletedAt); err != nil { t.Fatalf("商品逻辑删除后原始行不存在: %v", err) } if !itemDeletedAt.Valid || itemDeletedAt.String == "" { t.Fatalf("商品 deleted_at 未写入: %#v", itemDeletedAt) } + // ruleDeletedAt 保存规则DeletedAt,供当前处理流程使用 var ruleDeletedAt sql.NullString + // ruleEnabled 保存规则启用状态,供当前处理流程使用 var ruleEnabled int - if err := store.DB.QueryRowContext(ctx, + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT deleted_at, enabled FROM automation_rules WHERE id=?`, ruleID).Scan(&ruleDeletedAt, &ruleEnabled); err != nil { t.Fatalf("关联规则逻辑删除后原始行不存在: %v", err) } if !ruleDeletedAt.Valid || ruleDeletedAt.String == "" || ruleEnabled != 0 { t.Fatalf("关联规则未逻辑删除并禁用: deleted_at=%#v enabled=%d", ruleDeletedAt, ruleEnabled) } + // rules、err 保存rules、err,供当前处理流程使用 rules, err := store.Automation.ListForUser(ctx, user.ID) if err != nil { t.Fatal(err) @@ -198,6 +248,7 @@ func TestItemsSyncFromRemoteReconcilesAndPreservesLocalSettings(t *testing.T) { if len(rules) != 0 { t.Fatalf("已删除商品的规则不应出现在管理列表: %#v", rules) } + // matched、err 保存matched、err,供当前处理流程使用 matched, err := store.Automation.Match(ctx, "acc1", "deleted", "paid") if err != nil { t.Fatal(err) @@ -210,7 +261,8 @@ func TestItemsSyncFromRemoteReconcilesAndPreservesLocalSettings(t *testing.T) { if _, err := store.Items.SyncFromRemote(ctx, "acc1", []ItemInfoRow{{ItemID: "existing"}, {ItemID: "deleted"}}); err != nil { t.Fatal(err) } - if _, err := store.Items.Get(ctx, "acc1", "deleted"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.Items.Get(ctx, "acc1", "deleted"); err != nil { t.Fatalf("商品重新同步后应恢复商品记录: %v", err) } rules, err = store.Automation.ListForUser(ctx, user.ID) @@ -222,23 +274,31 @@ func TestItemsSyncFromRemoteReconcilesAndPreservesLocalSettings(t *testing.T) { } } +// TestItemsDeleteSoftDeletesRelatedAutomationRule 负责Test商品列表DeleteSoftDeletesRelated自动化规则相关处理。 func TestItemsDeleteSoftDeletesRelatedAutomationRule(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if ok, err := store.Users.Create(ctx, "item-delete-user", "item-delete@example.com", "password"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := store.Users.Create(ctx, "item-delete-user", "item-delete@example.com", "password"); err != nil || !ok { t.Fatalf("create test user: ok=%v err=%v", ok, err) } + // user、err 保存user、err,供当前处理流程使用 user, err := store.Users.GetByUsername(ctx, "item-delete-user") if err != nil { t.Fatal(err) } - if err := store.Cookies.Save(ctx, "item-delete-cookie", "unb=1", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.Save(ctx, "item-delete-cookie", "unb=1", user.ID); err != nil { t.Fatal(err) } - if err := store.Items.Upsert(ctx, &ItemInfoRow{CookieID: "item-delete-cookie", ItemID: "item-1", ItemTitle: "待删除商品"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Items.Upsert(ctx, &ItemInfoRow{CookieID: "item-delete-cookie", ItemID: "item-1", ItemTitle: "待删除商品"}); err != nil { t.Fatal(err) } + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := store.Automation.Create(ctx, AutomationRuleInput{ UserID: user.ID, CookieID: "item-delete-cookie", ItemID: "item-1", Name: "商品规则", TriggerType: "paid", Enabled: true, Priority: 100, @@ -247,15 +307,20 @@ func TestItemsDeleteSoftDeletesRelatedAutomationRule(t *testing.T) { if err != nil { t.Fatal(err) } - if err := store.Items.Delete(ctx, "item-delete-cookie", "item-1"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Items.Delete(ctx, "item-delete-cookie", "item-1"); err != nil { t.Fatal(err) } + // itemDeletedAt、ruleDeletedAt 保存商品DeletedAt、ruleDeletedAt,供当前处理流程使用 var itemDeletedAt, ruleDeletedAt string + // ruleEnabled 保存规则启用状态,供当前处理流程使用 var ruleEnabled int - if err := store.DB.QueryRowContext(ctx, `SELECT deleted_at FROM item_info WHERE cookie_id=? AND item_id=?`, "item-delete-cookie", "item-1").Scan(&itemDeletedAt); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT deleted_at FROM item_info WHERE cookie_id=? AND item_id=?`, "item-delete-cookie", "item-1").Scan(&itemDeletedAt); err != nil { t.Fatalf("商品行未保留: %v", err) } - if err := store.DB.QueryRowContext(ctx, `SELECT deleted_at, enabled FROM automation_rules WHERE id=?`, ruleID).Scan(&ruleDeletedAt, &ruleEnabled); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT deleted_at, enabled FROM automation_rules WHERE id=?`, ruleID).Scan(&ruleDeletedAt, &ruleEnabled); err != nil { t.Fatalf("规则行未保留: %v", err) } if itemDeletedAt == "" || ruleDeletedAt == "" || ruleEnabled != 0 { diff --git a/internal/db/extras_test.go b/internal/db/extras_test.go index bfcc8f0..6ecff45 100644 --- a/internal/db/extras_test.go +++ b/internal/db/extras_test.go @@ -11,9 +11,12 @@ import ( // TestKeywords_AllWithType AllWithType 路径 + Add 默认 type。 func TestKeywords_AllWithType(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) // Add 不指定 type → 默认 text。 @@ -25,9 +28,11 @@ func TestKeywords_AllWithType(t *testing.T) { if _, err := s.Keywords.Add(ctx, cid, "图", "[img]", "item1", "image", "http://img"); err != nil { t.Fatalf("Add image: %v", err) } - if _, err := s.Keywords.Add(ctx, cid, "你好呀", "更精确", "", "text", ""); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.Keywords.Add(ctx, cid, "你好呀", "更精确", "", "text", ""); err != nil { t.Fatal(err) } + // kws、err 保存kws、err,供当前处理流程使用 kws, err := s.Keywords.AllWithType(ctx, cid) if err != nil { t.Fatalf("AllWithType: %v", err) @@ -40,6 +45,7 @@ func TestKeywords_AllWithType(t *testing.T) { } // 验证默认 type=text 兜底(第一条)。 var foundText, foundImage bool + // k 表示当前遍历过程中的k for _, k := range kws { if k.Keyword == "你好" && k.Reply == "在的" && k.Type == "text" { foundText = true @@ -55,10 +61,13 @@ func TestKeywords_AllWithType(t *testing.T) { // TestKeywords_AllRowsEmptyCookie AllRows 对无关键字的账号返回 nil 不报错。 func TestKeywords_AllRowsEmptyCookie(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() seedAccount(t, s) + // rows、err 保存rows、err,供当前处理流程使用 rows, err := s.Keywords.AllRows(ctx, "no-such-cookie") if err != nil || len(rows) != 0 { t.Fatalf("AllRows 空: %#v err=%v", rows, err) @@ -66,10 +75,14 @@ func TestKeywords_AllRowsEmptyCookie(t *testing.T) { } // TestItemReplies_SetDelete ItemReplies.Set/Delete/AllForUser + Get。 +// TestItemReplies_SetDelete 负责Test商品回复列表SetDelete相关处理。 func TestItemReplies_SetDelete(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) // Get 不存在 → ErrNotFound。 @@ -80,6 +93,7 @@ func TestItemReplies_SetDelete(t *testing.T) { if err := s.ItemReps.Set(ctx, cid, "i1", "回复A"); err != nil { t.Fatalf("Set: %v", err) } + // got、err 保存got、err,供当前处理流程使用 got, err := s.ItemReps.Get(ctx, cid, "i1") if err != nil || got.ReplyContent != "回复A" { t.Fatalf("Get: %#v err=%v", got, err) @@ -93,24 +107,31 @@ func TestItemReplies_SetDelete(t *testing.T) { t.Fatalf("覆盖后=%q want 回复B", got.ReplyContent) } // AllForUser。 + // all、err 保存all、err,供当前处理流程使用 all, err := s.ItemReps.AllForUser(ctx, cid) if err != nil || len(all) != 1 { t.Fatalf("AllForUser: %#v err=%v", all, err) } // Delete。 - if err := s.ItemReps.Delete(ctx, cid, "i1"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.ItemReps.Delete(ctx, cid, "i1"); err != nil { t.Fatalf("Delete: %v", err) } - if _, err := s.ItemReps.Get(ctx, cid, "i1"); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.ItemReps.Get(ctx, cid, "i1"); !errors.Is(err, ErrNotFound) { t.Fatalf("Delete 后应 ErrNotFound, got %v", err) } } // TestDefaultReplies_GetAndRecord DefaultReplies.Get/HasRecord/AddRecord。 +// TestDefaultReplies_GetAndRecord 负责TestDefault回复列表GetAndRecord相关处理。 func TestDefaultReplies_GetAndRecord(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) // Get 不存在 → ErrNotFound。 @@ -121,6 +142,7 @@ func TestDefaultReplies_GetAndRecord(t *testing.T) { _, _ = s.DB.ExecContext(ctx, `INSERT INTO default_replies (cookie_id, enabled, reply_content, reply_image_url, reply_once) VALUES (?, 1, '你好', 'http://img', 1)`, cid) + // dr、err 保存dr、err,供当前处理流程使用 dr, err := s.DefaultReps.Get(ctx, cid) if err != nil { t.Fatalf("Get: %v", err) @@ -146,10 +168,14 @@ func TestDefaultReplies_GetAndRecord(t *testing.T) { } // TestNotifications_GetChannelAndAccountChannels GetChannel + AccountChannels。 +// TestNotifications_GetChannelAndAccountChannels 负责Test通知列表Get渠道And账号渠道列表相关处理。 func TestNotifications_GetChannelAndAccountChannels(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) // GetChannel 不存在 → nil, nil。 @@ -157,6 +183,7 @@ func TestNotifications_GetChannelAndAccountChannels(t *testing.T) { if err != nil || got != nil { t.Fatalf("GetChannel 不存在应 nil, got %#v err=%v", got, err) } + // chID 保存chID,供当前处理流程使用 chID, _ := s.Notifications.CreateChannel(ctx, &NotificationChannelRow{ Name: "wh", Type: "webhook", Config: `{"url":"x"}`, Enabled: true, UserID: uid, }) @@ -167,6 +194,7 @@ func TestNotifications_GetChannelAndAccountChannels(t *testing.T) { // AccountChannels:绑定渠道后查询。 s.Notifications.SetBindings(ctx, cid, []int64{chID}) + // channels、err 保存channels、err,供当前处理流程使用 channels, err := s.Notifications.AccountChannels(ctx, cid) if err != nil { t.Fatalf("AccountChannels: %v", err) @@ -184,30 +212,41 @@ func TestNotifications_GetChannelAndAccountChannels(t *testing.T) { } } +// TestNotificationsRejectCrossUserBindings 负责Test通知列表RejectCross用户Bindings相关处理。 func TestNotificationsRejectCrossUserBindings(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) - if ok, err := s.Users.Create(ctx, "u2", "u2@example.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Users.Create(ctx, "u2", "u2@example.com", "pw"); err != nil || !ok { t.Fatalf("create second user: ok=%v err=%v", ok, err) } + // u2 保存u2,供当前处理流程使用 u2, _ := s.Users.GetByUsername(ctx, "u2") + // ownCh 保存ownCh,供当前处理流程使用 ownCh, _ := s.Notifications.CreateChannel(ctx, &NotificationChannelRow{ Name: "own", Type: "webhook", Config: `{}`, Enabled: true, UserID: uid, }) + // otherCh 保存otherCh,供当前处理流程使用 otherCh, _ := s.Notifications.CreateChannel(ctx, &NotificationChannelRow{ Name: "other", Type: "webhook", Config: `{}`, Enabled: true, UserID: u2.ID, }) - if err := s.Notifications.SetBindings(ctx, cid, []int64{otherCh}); !errors.Is(err, ErrForbidden) { + if // err 保存err,供当前处理流程使用 + err := s.Notifications.SetBindings(ctx, cid, []int64{otherCh}); !errors.Is(err, ErrForbidden) { t.Fatalf("cross-user SetBindings should be forbidden, got %v", err) } - if err := s.Notifications.SetBindings(ctx, cid, []int64{ownCh}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Notifications.SetBindings(ctx, cid, []int64{ownCh}); err != nil { t.Fatalf("own SetBindings: %v", err) } // 模拟历史脏数据:当前账号绑定到了其他用户渠道,读取侧也必须过滤掉。 _, _ = s.DB.ExecContext(ctx, `INSERT INTO message_notifications (cookie_id, channel_id, enabled) VALUES (?, ?, 1)`, cid, otherCh) + // bindings、err 保存bindings、err,供当前处理流程使用 bindings, err := s.Notifications.AccountBindings(ctx, cid) if err != nil { t.Fatalf("AccountBindings: %v", err) @@ -215,6 +254,7 @@ func TestNotificationsRejectCrossUserBindings(t *testing.T) { if len(bindings) != 1 || bindings[0] != ownCh { t.Fatalf("bindings should only include own channel: %#v", bindings) } + // channels、err 保存channels、err,供当前处理流程使用 channels, err := s.Notifications.AccountChannels(ctx, cid) if err != nil { t.Fatalf("AccountChannels: %v", err) @@ -226,8 +266,10 @@ func TestNotificationsRejectCrossUserBindings(t *testing.T) { // TestSettings_GetAndAll Get 不存在返回空串 + All 全量。 func TestSettings_GetAndAll(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() // Get 不存在 → 空串不报错。 @@ -240,6 +282,7 @@ func TestSettings_GetAndAll(t *testing.T) { s.Settings.Set(ctx, "k2", "v2") // 二次 Set 同 key → 覆盖(UPSERT)。 s.Settings.Set(ctx, "k1", "v1-updated") + // all、err 保存all、err,供当前处理流程使用 all, err := s.Settings.All(ctx) if err != nil { t.Fatalf("All: %v", err) @@ -247,6 +290,7 @@ func TestSettings_GetAndAll(t *testing.T) { if all["k1"] != "v1-updated" || all["k2"] != "v2" { t.Fatalf("All = %#v", all) } + // got 保存got,供当前处理流程使用 got, _ := s.Settings.Get(ctx, "k1") if got != "v1-updated" { t.Fatalf("Get k1=%q want v1-updated", got) @@ -255,8 +299,10 @@ func TestSettings_GetAndAll(t *testing.T) { // TestSettings_Public Public 过滤:白名单 key 返回值,私有 key 不外露。 func TestSettings_Public(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() // 写入一个公开 key + 几个遗留/私有 key。 @@ -266,6 +312,7 @@ func TestSettings_Public(t *testing.T) { s.Settings.Set(ctx, "private_secret", "topsecret") s.Settings.Set(ctx, "qq_reply_secret_key", "should-not-leak") + // pub、err 保存pub、err,供当前处理流程使用 pub, err := s.Settings.Public(ctx) if err != nil { t.Fatalf("Public: %v", err) @@ -277,16 +324,20 @@ func TestSettings_Public(t *testing.T) { if _, ok := pub["private_secret"]; ok { t.Fatal("private_secret 不应外露") } - if _, ok := pub["qq_reply_secret_key"]; ok { + if // ok 保存ok,供当前处理流程使用 + _, ok := pub["qq_reply_secret_key"]; ok { t.Fatal("qq_reply_secret_key 不应外露") } - if _, ok := pub["login_captcha_enabled"]; ok { + if // ok 保存ok,供当前处理流程使用 + _, ok := pub["login_captcha_enabled"]; ok { t.Fatal("未实现的登录验证码开关不应公开") } - if _, ok := pub["registration_enabled"]; ok { + if // ok 保存ok,供当前处理流程使用 + _, ok := pub["registration_enabled"]; ok { t.Fatal("未实现的注册开关不应公开") } - if _, ok := pub["show_default_login_info"]; ok { + if // ok 保存ok,供当前处理流程使用 + _, ok := pub["show_default_login_info"]; ok { t.Fatal("未使用的默认登录提示开关不应公开") } } @@ -294,13 +345,18 @@ func TestSettings_Public(t *testing.T) { // --- cookies.go --- // TestCookies_DeleteAndStatuses Delete/GetValue/GetDetails/SetStatus/GetStatus/UpdateProfile。 +// TestCookies_DeleteAndStatuses 负责TestCookiesDeleteAndStatuses相关处理。 func TestCookies_DeleteAndStatuses(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) // GetValue。 + // v、err 保存v、err,供当前处理流程使用 v, err := s.Cookies.GetValue(ctx, cid) if err != nil || v != "cv=admin" { t.Fatalf("GetValue: v=%q err=%v", v, err) @@ -314,9 +370,11 @@ func TestCookies_DeleteAndStatuses(t *testing.T) { if _, err := s.Cookies.GetDetails(ctx, "nope"); !errors.Is(err, ErrNotFound) { t.Fatalf("want ErrNotFound, got %v", err) } - if _, err := s.DB.ExecContext(ctx, `UPDATE cookies SET remark=NULL, username=NULL, password=NULL WHERE id=?`, cid); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE cookies SET remark=NULL, username=NULL, password=NULL WHERE id=?`, cid); err != nil { t.Fatalf("set nullable text fields: %v", err) } + // details、err 保存details、err,供当前处理流程使用 details, err := s.Cookies.GetDetails(ctx, cid) if err != nil { t.Fatalf("GetDetails should tolerate NULL text fields: %v", err) @@ -335,7 +393,8 @@ func TestCookies_DeleteAndStatuses(t *testing.T) { } // SetStatus false → GetStatus false。 - if err := s.Cookies.SetStatus(ctx, cid, false); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.SetStatus(ctx, cid, false); err != nil { t.Fatalf("SetStatus false: %v", err) } if s.Cookies.GetStatus(ctx, cid) { @@ -352,9 +411,11 @@ func TestCookies_DeleteAndStatuses(t *testing.T) { } // UpdateProfile。 - if err := s.Cookies.UpdateProfile(ctx, cid, "昵称", "http://avatar"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.UpdateProfile(ctx, cid, "昵称", "http://avatar"); err != nil { t.Fatalf("UpdateProfile: %v", err) } + // d 保存d,供当前处理流程使用 d, _ := s.Cookies.GetDetails(ctx, cid) if d.Nickname != "昵称" || d.AvatarURL != "http://avatar" { t.Fatalf("UpdateProfile 后: %#v", d) @@ -366,33 +427,41 @@ func TestCookies_DeleteAndStatuses(t *testing.T) { t.Fatalf("AllForUser(0): %#v err=%v", all, err) } - if _, err := s.DB.ExecContext(ctx, `INSERT INTO item_replay (item_id,cookie_id,reply_content) VALUES ('item-stale',?,'不应残留')`, cid); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `INSERT INTO item_replay (item_id,cookie_id,reply_content) VALUES ('item-stale',?,'不应残留')`, cid); err != nil { t.Fatalf("seed item_replay: %v", err) } // Delete cookie → 无外键的 item_replay 也必须显式清理。 if err := s.Cookies.Delete(ctx, cid); err != nil { t.Fatalf("Delete: %v", err) } - if _, err := s.Cookies.GetValue(ctx, cid); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.Cookies.GetValue(ctx, cid); !errors.Is(err, ErrNotFound) { t.Fatalf("Delete 后 GetValue 应 ErrNotFound, got %v", err) } + // stale 保存stale,供当前处理流程使用 var stale int - if err := s.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM item_replay WHERE cookie_id=?`, cid).Scan(&stale); err != nil || stale != 0 { + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM item_replay WHERE cookie_id=?`, cid).Scan(&stale); err != nil || stale != 0 { t.Fatalf("Delete 后 item_replay count=%d err=%v", stale, err) } } // TestCookies_SaveReuseUserID Save 在 userID=0 且 cookie 已存在时复用 user_id。 func TestCookies_SaveReuseUserID(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) // cookie 已存在;用 userID=0 调 Save 应复用 existing user_id 并更新 value。 if err := s.Cookies.Save(ctx, cid, "new-value", 0); err != nil { t.Fatalf("Save reuse: %v", err) } + // v 保存v,供当前处理流程使用 v, _ := s.Cookies.GetValue(ctx, cid) if v != "new-value" { t.Fatalf("value=%q want new-value", v) @@ -411,13 +480,17 @@ func TestCookies_SaveReuseUserID(t *testing.T) { // TestCookies_GetPauseDurationExplicit 显式 pause_duration=0 应返回 0(有效值)。 func TestCookies_GetPauseDurationExplicit(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) // 显式置 0。 _, _ = s.DB.ExecContext(ctx, `UPDATE cookies SET pause_duration=0 WHERE id=?`, cid) - if pd := s.Cookies.GetPauseDuration(ctx, cid); pd != 0 { + if // pd 保存pd,供当前处理流程使用 + pd := s.Cookies.GetPauseDuration(ctx, cid); pd != 0 { t.Fatalf("GetPauseDuration=%d want 0", pd) } // 不存在的 cookie → 默认 10。 @@ -426,35 +499,46 @@ func TestCookies_GetPauseDurationExplicit(t *testing.T) { } } +// TestCookies_SetPauseAndAutomaticExpiry 负责TestCookiesSetPauseAndAutomaticExpiry相关处理。 func TestCookies_SetPauseAndAutomaticExpiry(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) + // pausedUntil、err 保存pausedUntil、err,供当前处理流程使用 pausedUntil, err := s.Cookies.SetPause(ctx, cid, 15) if err != nil { t.Fatal(err) } + // paused、storedUntil、err 保存paused、storedUntil、err,供当前处理流程使用 paused, storedUntil, err := s.Cookies.IsPaused(ctx, cid) if err != nil || !paused || storedUntil != pausedUntil || pausedUntil <= time.Now().UTC().Unix() { t.Fatalf("pause state: paused=%v until=%d stored=%d err=%v", paused, pausedUntil, storedUntil, err) } - if _, err := s.DB.ExecContext(ctx, `UPDATE cookies SET paused_until=? WHERE id=?`, time.Now().UTC().Add(-time.Second).Unix(), cid); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE cookies SET paused_until=? WHERE id=?`, time.Now().UTC().Add(-time.Second).Unix(), cid); err != nil { t.Fatal(err) } if paused, _, err = s.Cookies.IsPaused(ctx, cid); err != nil || paused { t.Fatalf("expired pause must be inactive: paused=%v err=%v", paused, err) } - if until, err := s.Cookies.SetPause(ctx, cid, 0); err != nil || until != 0 { + if // until、err 保存until、err,供当前处理流程使用 + until, err := s.Cookies.SetPause(ctx, cid, 0); err != nil || until != 0 { t.Fatalf("cancel pause: until=%d err=%v", until, err) } } +// TestCookiesGetStatusFailsClosedOnDatabaseError 负责TestCookiesGet状态FailsClosedOnDatabase错误相关处理。 func TestCookiesGetStatusFailsClosedOnDatabaseError(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() - if err := s.DB.Close(); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.DB.Close(); err != nil { t.Fatal(err) } if s.Cookies.GetStatus(context.Background(), "cid") { diff --git a/internal/db/item_publish_batches.go b/internal/db/item_publish_batches.go index 7fae8d7..be720a9 100644 --- a/internal/db/item_publish_batches.go +++ b/internal/db/item_publish_batches.go @@ -13,6 +13,7 @@ import ( // 一个批次对应一次 Excel/CSV 导入,包含若干明细行(每行一个待发布商品)。 // 发布 worker 按 row_no 顺序逐行发布,通过状态机(pending→running→success/failed) // 跟踪进度,支持失败重置(ResetFailed)和实时计数(Recount)。 +// ItemPublishBatches 保存商品发布批次列表,供当前处理流程使用 type ItemPublishBatches struct{ DB *sql.DB } // ErrPublishBatchChanged 表示批次在读取与状态切换之间被其他 worker 更新,调用方可安全重试。 @@ -66,16 +67,19 @@ type ItemPublishBatchRow struct { // Create 在单事务内创建批次及其全部明细行。 // 明细行的 quantity/postage_mode/status/images_json/raw_json/automation_json 缺省值在此补齐。 // total_count 取 len(rows),success/failed 初始为 0。 +// Create 创建当前值。 func (b *ItemPublishBatches) Create(ctx context.Context, batch *ItemPublishBatch, rows []ItemPublishBatchRow) error { if strings.TrimSpace(batch.LocationJSON) == "" { batch.LocationJSON = "{}" } + // tx、err 保存tx、err,供当前处理流程使用 tx, err := b.DB.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() - if _, err := tx.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `INSERT INTO item_publish_batches (id,user_id,default_cookie_id,filename,upload_dir,location_json,status,total_count,success_count,failed_count) VALUES (?,?,?,?,?,?,?,?,?,?)`, @@ -83,6 +87,7 @@ func (b *ItemPublishBatches) Create(ctx context.Context, batch *ItemPublishBatch batch.LocationJSON, batch.Status, len(rows), 0, 0); err != nil { return err } + // row 表示当前遍历过程中的row for _, row := range rows { if row.Quantity <= 0 { row.Quantity = 1 @@ -105,7 +110,8 @@ func (b *ItemPublishBatches) Create(ctx context.Context, batch *ItemPublishBatch if row.AutomationJSON == "" { row.AutomationJSON = "{}" } - if _, err := tx.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `INSERT INTO item_publish_batch_rows (batch_id,row_no,cookie_id,title,description,price,original_price,quantity,postage_mode,postage, images_json,category_json,automation_json,status,item_id,item_url,error_message,failure_kind,raw_json) @@ -121,7 +127,9 @@ func (b *ItemPublishBatches) Create(ctx context.Context, batch *ItemPublishBatch // Get 按 ID 取批次(含 user_id 隔离校验)。未找到返回 ErrNotFound。 func (b *ItemPublishBatches) Get(ctx context.Context, userID int64, id string) (*ItemPublishBatch, error) { + // out 保存out,供当前处理流程使用 var out ItemPublishBatch + // err 保存err,供当前处理流程使用 err := b.DB.QueryRowContext(ctx, `SELECT id,user_id,default_cookie_id,filename,upload_dir,COALESCE(location_json,'{}'),status,total_count,success_count,failed_count, COALESCE(worker_token,''),COALESCE(lease_expires_at,0), @@ -144,6 +152,7 @@ func (b *ItemPublishBatches) ListForUser(ctx context.Context, userID int64, limi if limit <= 0 || limit > 100 { limit = 20 } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := b.DB.QueryContext(ctx, `SELECT id,user_id,default_cookie_id,filename,upload_dir,COALESCE(location_json,'{}'),status, total_count,success_count,failed_count,COALESCE(worker_token,''),COALESCE(lease_expires_at,0),created_at,updated_at FROM item_publish_batches WHERE user_id=? ORDER BY created_at DESC,id DESC LIMIT ?`, userID, limit) @@ -151,10 +160,13 @@ func (b *ItemPublishBatches) ListForUser(ctx context.Context, userID int64, limi return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []ItemPublishBatch for rows.Next() { + // batch 保存批次,供当前处理流程使用 var batch ItemPublishBatch - if err := rows.Scan(&batch.ID, &batch.UserID, &batch.DefaultCookieID, &batch.Filename, &batch.UploadDir, &batch.LocationJSON, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&batch.ID, &batch.UserID, &batch.DefaultCookieID, &batch.Filename, &batch.UploadDir, &batch.LocationJSON, &batch.Status, &batch.TotalCount, &batch.SuccessCount, &batch.FailedCount, &batch.WorkerToken, &batch.LeaseExpiresAt, &batch.CreatedAt, &batch.UpdatedAt); err != nil { return nil, err @@ -169,6 +181,7 @@ func (b *ItemPublishBatches) Recoverable(ctx context.Context, now int64, limit i if limit <= 0 { limit = 20 } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := b.DB.QueryContext(ctx, `SELECT id,user_id,default_cookie_id,filename,upload_dir,COALESCE(location_json,'{}'),status, total_count,success_count,failed_count,COALESCE(worker_token,''),COALESCE(lease_expires_at,0),created_at,updated_at FROM item_publish_batches b @@ -180,10 +193,13 @@ func (b *ItemPublishBatches) Recoverable(ctx context.Context, now int64, limit i return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []ItemPublishBatch for rows.Next() { + // batch 保存批次,供当前处理流程使用 var batch ItemPublishBatch - if err := rows.Scan(&batch.ID, &batch.UserID, &batch.DefaultCookieID, &batch.Filename, &batch.UploadDir, &batch.LocationJSON, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&batch.ID, &batch.UserID, &batch.DefaultCookieID, &batch.Filename, &batch.UploadDir, &batch.LocationJSON, &batch.Status, &batch.TotalCount, &batch.SuccessCount, &batch.FailedCount, &batch.WorkerToken, &batch.LeaseExpiresAt, &batch.CreatedAt, &batch.UpdatedAt); err != nil { return nil, err @@ -195,6 +211,7 @@ func (b *ItemPublishBatches) Recoverable(ctx context.Context, now int64, limit i // Rows 取批次全部明细行,按 row_no 升序。 func (b *ItemPublishBatches) Rows(ctx context.Context, batchID string) ([]ItemPublishBatchRow, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := b.DB.QueryContext(ctx, `SELECT id,batch_id,row_no,cookie_id,title,description,price,original_price,quantity,postage_mode,postage, images_json,COALESCE(category_json,'{}'),COALESCE(automation_json,'{}'),status,item_id,item_url,error_message, @@ -205,10 +222,13 @@ func (b *ItemPublishBatches) Rows(ctx context.Context, batchID string) ([]ItemPu return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 out := []ItemPublishBatchRow{} for rows.Next() { + // r 保存r,供当前处理流程使用 var r ItemPublishBatchRow - if err := rows.Scan(&r.ID, &r.BatchID, &r.RowNo, &r.CookieID, &r.Title, &r.Description, &r.Price, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&r.ID, &r.BatchID, &r.RowNo, &r.CookieID, &r.Title, &r.Description, &r.Price, &r.OriginalPrice, &r.Quantity, &r.PostageMode, &r.Postage, &r.ImagesJSON, &r.CategoryJSON, &r.AutomationJSON, &r.Status, &r.ItemID, &r.ItemURL, &r.ErrorMessage, &r.FailureKind, &r.WorkerToken, &r.RawJSON, &r.CreatedAt, @@ -222,10 +242,12 @@ func (b *ItemPublishBatches) Rows(ctx context.Context, batchID string) ([]ItemPu // PendingRows 取待处理明细行。failedOnly=true 只取失败行(用于重试),否则取 pending 行。 func (b *ItemPublishBatches) PendingRows(ctx context.Context, batchID string, failedOnly bool) ([]ItemPublishBatchRow, error) { + // statuses 保存statuses,供当前处理流程使用 statuses := "('pending')" if failedOnly { statuses = "('failed')" } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := b.DB.QueryContext(ctx, `SELECT id,batch_id,row_no,cookie_id,title,description,price,original_price,quantity,postage_mode,postage, images_json,COALESCE(category_json,'{}'),COALESCE(automation_json,'{}'),status,item_id,item_url,error_message, @@ -236,10 +258,13 @@ func (b *ItemPublishBatches) PendingRows(ctx context.Context, batchID string, fa return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 out := []ItemPublishBatchRow{} for rows.Next() { + // r 保存r,供当前处理流程使用 var r ItemPublishBatchRow - if err := rows.Scan(&r.ID, &r.BatchID, &r.RowNo, &r.CookieID, &r.Title, &r.Description, &r.Price, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&r.ID, &r.BatchID, &r.RowNo, &r.CookieID, &r.Title, &r.Description, &r.Price, &r.OriginalPrice, &r.Quantity, &r.PostageMode, &r.Postage, &r.ImagesJSON, &r.CategoryJSON, &r.AutomationJSON, &r.Status, &r.ItemID, &r.ItemURL, &r.ErrorMessage, &r.FailureKind, &r.WorkerToken, &r.RawJSON, &r.CreatedAt, @@ -253,6 +278,7 @@ func (b *ItemPublishBatches) PendingRows(ctx context.Context, batchID string, fa // SetBatchStatus 更新批次状态(如 running/completed/failed)。 func (b *ItemPublishBatches) SetBatchStatus(ctx context.Context, batchID, status string) error { + // err 保存err,供当前处理流程使用 _, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batches SET status=?,worker_token='',lease_expires_at=0,updated_at=CURRENT_TIMESTAMP WHERE id=?`, status, batchID) return err @@ -260,27 +286,34 @@ func (b *ItemPublishBatches) SetBatchStatus(ctx context.Context, batchID, status // RequestCancel 进入两阶段取消。运行中的批次保留 worker token,允许 worker // 把已经获得的远端商品 ID 落库后再结束;未运行批次可直接取消。 +// RequestCancel 负责请求取消相关处理。 func (b *ItemPublishBatches) RequestCancel(ctx context.Context, batchID string) (string, bool, error) { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := b.DB.BeginTx(ctx, nil) if err != nil { return "", false, err } defer tx.Rollback() + // status、token 保存status、token,供当前处理流程使用 var status, token string - if err := tx.QueryRowContext(ctx, `SELECT status,worker_token FROM item_publish_batches WHERE id=?`, batchID).Scan(&status, &token); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.QueryRowContext(ctx, `SELECT status,worker_token FROM item_publish_batches WHERE id=?`, batchID).Scan(&status, &token); err != nil { if errors.Is(err, sql.ErrNoRows) { return "", false, ErrNotFound } return "", false, err } + // running 保存running,供当前处理流程使用 running := (status == "running" || status == "canceling") && token != "" if running { + // res、err 保存res、err,供当前处理流程使用 res, err := tx.ExecContext(ctx, `UPDATE item_publish_batches SET status='canceling',updated_at=CURRENT_TIMESTAMP WHERE id=? AND status=? AND worker_token=?`, batchID, status, token) if err != nil { return "", false, err } - if n, rowsErr := res.RowsAffected(); rowsErr != nil { + if // n、rowsErr 保存n、rowsErr,供当前处理流程使用 + n, rowsErr := res.RowsAffected(); rowsErr != nil { return "", false, rowsErr } else if n != 1 { return "", false, ErrPublishBatchChanged @@ -293,15 +326,18 @@ func (b *ItemPublishBatches) RequestCancel(ctx context.Context, batchID string) if err != nil { return "", false, err } - if n, rowsErr := res.RowsAffected(); rowsErr != nil { + if // n、rowsErr 保存n、rowsErr,供当前处理流程使用 + n, rowsErr := res.RowsAffected(); rowsErr != nil { return "", false, rowsErr } else if n != 1 { return "", false, ErrPublishBatchChanged } - if err := markUnfinishedFailedTx(ctx, tx, batchID, "任务已取消"); err != nil { + if // err 保存err,供当前处理流程使用 + err := markUnfinishedFailedTx(ctx, tx, batchID, "任务已取消"); err != nil { return "", false, err } - if err := recountBatchTx(ctx, tx, batchID); err != nil { + if // err 保存err,供当前处理流程使用 + err := recountBatchTx(ctx, tx, batchID); err != nil { return "", false, err } res, err = tx.ExecContext(ctx, `UPDATE item_publish_batches SET status='canceled',worker_token='',lease_expires_at=0,updated_at=CURRENT_TIMESTAMP @@ -309,19 +345,23 @@ func (b *ItemPublishBatches) RequestCancel(ctx context.Context, batchID string) if err != nil { return "", false, err } - if n, rowsErr := res.RowsAffected(); rowsErr != nil { + if // n、rowsErr 保存n、rowsErr,供当前处理流程使用 + n, rowsErr := res.RowsAffected(); rowsErr != nil { return "", false, rowsErr } else if n != 1 { return "", false, ErrPublishBatchChanged } } - if err := tx.Commit(); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.Commit(); err != nil { return "", false, err } return token, running, nil } +// FinalizeCanceled 负责FinalizeCanceled相关处理。 func (b *ItemPublishBatches) FinalizeCanceled(ctx context.Context, batchID, workerToken string) (bool, error) { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := b.DB.BeginTx(ctx, nil) if err != nil { return false, err @@ -334,14 +374,17 @@ func (b *ItemPublishBatches) FinalizeCanceled(ctx context.Context, batchID, work if err != nil { return false, err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() if err != nil || n != 1 { return false, err } - if err := markUnfinishedFailedTx(ctx, tx, batchID, "任务已取消"); err != nil { + if // err 保存err,供当前处理流程使用 + err := markUnfinishedFailedTx(ctx, tx, batchID, "任务已取消"); err != nil { return false, err } - if err := recountBatchTx(ctx, tx, batchID); err != nil { + if // err 保存err,供当前处理流程使用 + err := recountBatchTx(ctx, tx, batchID); err != nil { return false, err } res, err = tx.ExecContext(ctx, `UPDATE item_publish_batches @@ -359,27 +402,34 @@ func (b *ItemPublishBatches) FinalizeCanceled(ctx context.Context, batchID, work // FinalizeInterrupted 只允许当前 worker 在一个事务内把未完成行标记为中断并结束批次。 // 先切换到事务内的 finalizing_interrupted 状态,避免 token 检查与明细更新之间发生租约接管。 +// FinalizeInterrupted 负责FinalizeInterrupted相关处理。 func (b *ItemPublishBatches) FinalizeInterrupted(ctx context.Context, batchID, workerToken, message string) (string, bool, error) { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := b.DB.BeginTx(ctx, nil) if err != nil { return "", false, err } defer tx.Rollback() + // res、err 保存res、err,供当前处理流程使用 res, err := tx.ExecContext(ctx, `UPDATE item_publish_batches SET status='finalizing_interrupted',updated_at=CURRENT_TIMESTAMP WHERE id=? AND status='running' AND worker_token=?`, batchID, workerToken) if err != nil { return "", false, err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() if err != nil || n != 1 { return "", false, err } - if err := markUnfinishedFailedTx(ctx, tx, batchID, message); err != nil { + if // err 保存err,供当前处理流程使用 + err := markUnfinishedFailedTx(ctx, tx, batchID, message); err != nil { return "", false, err } + // total、success、failed、unfinished 保存total、success、failed、unfinished,供当前处理流程使用 var total, success, failed, unfinished int - if err := tx.QueryRowContext(ctx, `SELECT COUNT(*), + if // err 保存err,供当前处理流程使用 + err := tx.QueryRowContext(ctx, `SELECT COUNT(*), COALESCE(SUM(CASE WHEN status='success' THEN 1 ELSE 0 END),0), COALESCE(SUM(CASE WHEN status='failed' THEN 1 ELSE 0 END),0), COALESCE(SUM(CASE WHEN status NOT IN ('success','failed') THEN 1 ELSE 0 END),0) @@ -389,6 +439,7 @@ func (b *ItemPublishBatches) FinalizeInterrupted(ctx context.Context, batchID, w if unfinished != 0 || total != success+failed { return "", false, errors.New("中断批次仍有未完成行") } + // status 保存状态,供当前处理流程使用 status := finalBatchStatus(success, failed) res, err = tx.ExecContext(ctx, `UPDATE item_publish_batches SET status=?,total_count=?,success_count=?,failed_count=?,worker_token='',lease_expires_at=0,updated_at=CURRENT_TIMESTAMP @@ -400,12 +451,14 @@ func (b *ItemPublishBatches) FinalizeInterrupted(ctx context.Context, batchID, w if err != nil || n != 1 { return "", false, err } - if err := tx.Commit(); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.Commit(); err != nil { return "", false, err } return status, true, nil } +// finalBatchStatus 负责final批次状态相关处理。 func finalBatchStatus(success, failed int) string { if failed == 0 { return "completed" @@ -418,73 +471,91 @@ func finalBatchStatus(success, failed int) string { // FinalizeExpiredCancellation 接管租约已过期的两阶段取消任务。远端调用已经开始但 // 结果尚未落库的行必须保持为 uncertain_remote,其余未完成行统一标记为已取消。 +// FinalizeExpiredCancellation 负责FinalizeExpiredCancellation相关处理。 func (b *ItemPublishBatches) FinalizeExpiredCancellation(ctx context.Context, batchID string, now int64) (bool, error) { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := b.DB.BeginTx(ctx, nil) if err != nil { return false, err } defer tx.Rollback() + // res、err 保存res、err,供当前处理流程使用 res, err := tx.ExecContext(ctx, `UPDATE item_publish_batches SET status='canceled',worker_token='',lease_expires_at=0,updated_at=CURRENT_TIMESTAMP WHERE id=? AND status='canceling' AND (lease_expires_at=0 OR lease_expires_at?`, batchID, workerToken); err != nil { return false, err } - if err := tx.Commit(); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.Commit(); err != nil { return false, err } return true, nil @@ -559,50 +640,60 @@ func (b *ItemPublishBatches) ClaimBatch(ctx context.Context, batchID, workerToke // RenewBatchLease 仅允许当前 worker 延长租约,长批次不会因固定截止时间被并发接管。 func (b *ItemPublishBatches) RenewBatchLease(ctx context.Context, batchID, workerToken string, leaseExpiresAt int64) (bool, error) { + // res、err 保存res、err,供当前处理流程使用 res, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batches SET lease_expires_at=?,updated_at=CURRENT_TIMESTAMP WHERE id=? AND status='running' AND worker_token=?`, leaseExpiresAt, batchID, workerToken) if err != nil { return false, err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() return err == nil && n == 1, err } // FailClaimedBatch 释放初始化阶段失败的批次租约。worker token 防止旧 worker // 覆盖已经被新 worker 接管的状态。 +// FailClaimedBatch 负责FailClaimed批次相关处理。 func (b *ItemPublishBatches) FailClaimedBatch(ctx context.Context, batchID, workerToken string) (bool, error) { + // res、err 保存res、err,供当前处理流程使用 res, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batches SET status='failed',worker_token='',lease_expires_at=0,updated_at=CURRENT_TIMESTAMP WHERE id=? AND status='running' AND worker_token=?`, batchID, workerToken) if err != nil { return false, err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() return err == nil && n == 1, err } // FinishBatchStatus 只允许当前持有租约的 worker 结束批次。 func (b *ItemPublishBatches) FinishBatchStatus(ctx context.Context, batchID, workerToken, status string) (bool, error) { + // res、err 保存res、err,供当前处理流程使用 res, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batches SET status=?,worker_token='',lease_expires_at=0,updated_at=CURRENT_TIMESTAMP WHERE id=? AND status='running' AND worker_token=?`, status, batchID, workerToken) if err != nil { return false, err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() return err == nil && n == 1, err } // FinalizeBatch 在单个事务内重算计数,并且只在所有行都进入终态后结束批次。 func (b *ItemPublishBatches) FinalizeBatch(ctx context.Context, batchID, workerToken string) (string, bool, error) { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := b.DB.BeginTx(ctx, nil) if err != nil { return "", false, err } defer tx.Rollback() + // total、success、failed、unfinished 保存total、success、failed、unfinished,供当前处理流程使用 var total, success, failed, unfinished int - if err := tx.QueryRowContext(ctx, `SELECT COUNT(*), + if // err 保存err,供当前处理流程使用 + err := tx.QueryRowContext(ctx, `SELECT COUNT(*), COALESCE(SUM(CASE WHEN status='success' THEN 1 ELSE 0 END),0), COALESCE(SUM(CASE WHEN status='failed' THEN 1 ELSE 0 END),0), COALESCE(SUM(CASE WHEN status NOT IN ('success','failed') THEN 1 ELSE 0 END),0) @@ -613,18 +704,22 @@ func (b *ItemPublishBatches) FinalizeBatch(ctx context.Context, batchID, workerT if unfinished != 0 || total != success+failed { return "", false, errors.New("批次仍有未完成行,不能进入终态") } + // status 保存状态,供当前处理流程使用 status := finalBatchStatus(success, failed) + // res、err 保存res、err,供当前处理流程使用 res, err := tx.ExecContext(ctx, `UPDATE item_publish_batches SET status=?,total_count=?,success_count=?,failed_count=?,worker_token='',lease_expires_at=0,updated_at=CURRENT_TIMESTAMP WHERE id=? AND status='running' AND worker_token=?`, status, total, success, failed, batchID, workerToken) if err != nil { return "", false, err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() if err != nil || n != 1 { return "", false, err } - if err := tx.Commit(); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.Commit(); err != nil { return "", false, err } return status, true, nil @@ -632,7 +727,9 @@ func (b *ItemPublishBatches) FinalizeBatch(ctx context.Context, batchID, workerT // BatchStatus 取批次状态。未找到返回 ErrNotFound。 func (b *ItemPublishBatches) BatchStatus(ctx context.Context, batchID string) (string, error) { + // status 保存状态,供当前处理流程使用 var status string + // err 保存err,供当前处理流程使用 err := b.DB.QueryRowContext(ctx, `SELECT status FROM item_publish_batches WHERE id=?`, batchID).Scan(&status) if err != nil { if errors.Is(err, sql.ErrNoRows) { @@ -645,6 +742,7 @@ func (b *ItemPublishBatches) BatchStatus(ctx context.Context, batchID string) (s // MarkRowRunning 将明细行置为 running 并清空历史错误信息(发布 worker 开始处理时调用)。 func (b *ItemPublishBatches) MarkRowRunning(ctx context.Context, rowID int64) error { + // err 保存err,供当前处理流程使用 _, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows SET status='running',error_message='',failure_kind='',updated_at=CURRENT_TIMESTAMP WHERE id=? AND status='pending'`, rowID) return err @@ -652,6 +750,7 @@ func (b *ItemPublishBatches) MarkRowRunning(ctx context.Context, rowID int64) er // ClaimRow 原子领取单行,防止多个 worker 重复发布同一商品。 func (b *ItemPublishBatches) ClaimRow(ctx context.Context, rowID int64, workerToken string) (bool, error) { + // res、err 保存res、err,供当前处理流程使用 res, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows SET status='running',worker_token=?,error_message='',failure_kind='',updated_at=CURRENT_TIMESTAMP WHERE id=? AND status='pending' @@ -661,19 +760,23 @@ func (b *ItemPublishBatches) ClaimRow(ctx context.Context, rowID int64, workerTo if err != nil { return false, err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() return err == nil && n == 1, err } // MarkClaimedRemoteStarted 在调用闲鱼发布接口前落盘。进程若在远端返回前硬退出, // 租约接管方会把该行隔离为 uncertain_remote,而不是再次发布。 +// MarkClaimedRemoteStarted 负责MarkClaimedRemoteStarted相关处理。 func (b *ItemPublishBatches) MarkClaimedRemoteStarted(ctx context.Context, rowID int64, workerToken string) (bool, error) { + // res、err 保存res、err,供当前处理流程使用 res, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows SET failure_kind='remote_started',updated_at=CURRENT_TIMESTAMP WHERE id=? AND status='running' AND worker_token=? AND COALESCE(item_id,'')=''`, rowID, workerToken) if err != nil { return false, err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() return err == nil && n == 1, err } @@ -683,18 +786,21 @@ func (b *ItemPublishBatches) MarkClaimedRowSuccess(ctx context.Context, rowID in if rawJSON == "" { rawJSON = "{}" } + // res、err 保存res、err,供当前处理流程使用 res, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows SET status='success',item_id=?,item_url=?,error_message='',failure_kind='',worker_token='',raw_json=?,updated_at=CURRENT_TIMESTAMP WHERE id=? AND status='running' AND worker_token=?`, itemID, itemURL, rawJSON, rowID, workerToken) if err != nil { return false, err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() return err == nil && n == 1, err } // SaveClaimedRemoteResult 在闲鱼发布成功后第一时间保存远端商品标识。 // 后续本地商品/自动化规则写入失败时,重试会从该断点继续而不会再次调用发布接口。 +// SaveClaimedRemoteResult 保存ClaimedRemote结果。 func (b *ItemPublishBatches) SaveClaimedRemoteResult(ctx context.Context, rowID int64, workerToken, itemID, itemURL, rawJSON string) (bool, error) { if strings.TrimSpace(itemID) == "" { return false, errors.New("远端发布结果缺少商品ID") @@ -702,24 +808,28 @@ func (b *ItemPublishBatches) SaveClaimedRemoteResult(ctx context.Context, rowID if rawJSON == "" { rawJSON = "{}" } + // res、err 保存res、err,供当前处理流程使用 res, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows SET item_id=?,item_url=?,raw_json=?,failure_kind='post_publish',updated_at=CURRENT_TIMESTAMP WHERE id=? AND status='running' AND worker_token=?`, itemID, itemURL, rawJSON, rowID, workerToken) if err != nil { return false, err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() return err == nil && n == 1, err } // MarkClaimedRowFailed 只允许领取该行的 worker 写入失败结果。 func (b *ItemPublishBatches) MarkClaimedRowFailed(ctx context.Context, rowID int64, workerToken, message, kind string) (bool, error) { + // res、err 保存res、err,供当前处理流程使用 res, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows SET status='failed',error_message=?,failure_kind=?,worker_token='',updated_at=CURRENT_TIMESTAMP WHERE id=? AND status='running' AND worker_token=?`, message, kind, rowID, workerToken) if err != nil { return false, err } + // n、err 保存n、err,供当前处理流程使用 n, err := res.RowsAffected() return err == nil && n == 1, err } @@ -729,6 +839,7 @@ func (b *ItemPublishBatches) MarkRowSuccess(ctx context.Context, rowID int64, it if rawJSON == "" { rawJSON = "{}" } + // err 保存err,供当前处理流程使用 _, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows SET status='success',item_id=?,item_url=?,error_message='',failure_kind='',worker_token='',raw_json=?,updated_at=CURRENT_TIMESTAMP @@ -741,7 +852,9 @@ func (b *ItemPublishBatches) MarkRowFailed(ctx context.Context, rowID int64, mes return b.MarkRowFailedKind(ctx, rowID, message, "publish") } +// MarkRowFailedKind 负责MarkRow失败类型相关处理。 func (b *ItemPublishBatches) MarkRowFailedKind(ctx context.Context, rowID int64, message, kind string) error { + // err 保存err,供当前处理流程使用 _, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows SET status='failed',error_message=?,failure_kind=?,worker_token='',updated_at=CURRENT_TIMESTAMP WHERE id=?`, message, kind, rowID) @@ -750,11 +863,13 @@ func (b *ItemPublishBatches) MarkRowFailedKind(ctx context.Context, rowID int64, // MarkRunningFailed 将批次内仍在 running 的行标为失败。 func (b *ItemPublishBatches) MarkRunningFailed(ctx context.Context, batchID, message string) error { - if _, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows + if // err 保存err,供当前处理流程使用 + _, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows SET status='failed',error_message='远端发布结果未知,请人工核对闲鱼商品列表',failure_kind='uncertain_remote',worker_token='',updated_at=CURRENT_TIMESTAMP WHERE batch_id=? AND status='running' AND failure_kind='remote_started' AND COALESCE(item_id,'')=''`, batchID); err != nil { return err } + // err 保存err,供当前处理流程使用 _, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows SET status='failed',error_message=?,failure_kind='interrupted',worker_token='',updated_at=CURRENT_TIMESTAMP @@ -765,11 +880,13 @@ func (b *ItemPublishBatches) MarkRunningFailed(ctx context.Context, batchID, mes // MarkUnfinishedFailed 将批次内 pending/running 行标为失败。 func (b *ItemPublishBatches) MarkUnfinishedFailed(ctx context.Context, batchID, message string) error { - if _, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows + if // err 保存err,供当前处理流程使用 + _, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows SET status='failed',error_message='远端发布结果未知,请人工核对闲鱼商品列表',failure_kind='uncertain_remote',worker_token='',updated_at=CURRENT_TIMESTAMP WHERE batch_id=? AND status='running' AND failure_kind='remote_started' AND COALESCE(item_id,'')=''`, batchID); err != nil { return err } + // err 保存err,供当前处理流程使用 _, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows SET status='failed',error_message=?,failure_kind='interrupted',worker_token='',updated_at=CURRENT_TIMESTAMP @@ -780,6 +897,7 @@ func (b *ItemPublishBatches) MarkUnfinishedFailed(ctx context.Context, batchID, // ResetFailed 将批次内所有 failed 行重置为 pending,便于失败重试。 func (b *ItemPublishBatches) ResetFailed(ctx context.Context, batchID string) error { + // err 保存err,供当前处理流程使用 _, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batch_rows SET status='pending',error_message='',failure_kind='',worker_token='',updated_at=CURRENT_TIMESTAMP @@ -790,15 +908,19 @@ func (b *ItemPublishBatches) ResetFailed(ctx context.Context, batchID string) er // Recount 按明细行实际状态重算批次的 total/success/failed 计数。 // worker 每完成一行后调用,保证前端进度与 DB 一致。 +// Recount 负责Recount相关处理。 func (b *ItemPublishBatches) Recount(ctx context.Context, batchID string) error { + // total、success、failed 保存total、success、failed,供当前处理流程使用 var total, success, failed int - if err := b.DB.QueryRowContext(ctx, + if // err 保存err,供当前处理流程使用 + err := b.DB.QueryRowContext(ctx, `SELECT COUNT(*), COALESCE(SUM(CASE WHEN status='success' THEN 1 ELSE 0 END),0), COALESCE(SUM(CASE WHEN status='failed' THEN 1 ELSE 0 END),0) FROM item_publish_batch_rows WHERE batch_id=?`, batchID).Scan(&total, &success, &failed); err != nil { return err } + // err 保存err,供当前处理流程使用 _, err := b.DB.ExecContext(ctx, `UPDATE item_publish_batches SET total_count=?,success_count=?,failed_count=?,updated_at=CURRENT_TIMESTAMP diff --git a/internal/db/item_publish_batches_lease_test.go b/internal/db/item_publish_batches_lease_test.go index 2ac4514..9e66354 100644 --- a/internal/db/item_publish_batches_lease_test.go +++ b/internal/db/item_publish_batches_lease_test.go @@ -6,31 +6,41 @@ import ( "time" ) +// TestFailClaimedBatchRequiresCurrentWorker 负责TestFailClaimed批次RequiresCurrent工作器相关处理。 func TestFailClaimedBatchRequiresCurrentWorker(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if ok, err := store.Users.Create(ctx, "lease-owner", "lease-owner@example.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := store.Users.Create(ctx, "lease-owner", "lease-owner@example.com", "pw"); err != nil || !ok { t.Fatalf("create owner: ok=%v err=%v", ok, err) } + // owner、err 保存owner、err,供当前处理流程使用 owner, err := store.Users.GetByUsername(ctx, "lease-owner") if err != nil { t.Fatal(err) } - if err := store.PublishBatches.Create(ctx, &ItemPublishBatch{ + if // err 保存err,供当前处理流程使用 + err := store.PublishBatches.Create(ctx, &ItemPublishBatch{ ID: "lease-failure", UserID: owner.ID, Filename: "test.csv", Status: "pending", }, []ItemPublishBatchRow{{RowNo: 1, Title: "item", Price: "1"}}); err != nil { t.Fatal(err) } - if claimed, err := store.PublishBatches.ClaimBatch(ctx, "lease-failure", "current", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := store.PublishBatches.ClaimBatch(ctx, "lease-failure", "current", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { t.Fatalf("claim: claimed=%v err=%v", claimed, err) } - if released, err := store.PublishBatches.FailClaimedBatch(ctx, "lease-failure", "stale"); err != nil || released { + if // released、err 保存released、err,供当前处理流程使用 + released, err := store.PublishBatches.FailClaimedBatch(ctx, "lease-failure", "stale"); err != nil || released { t.Fatalf("stale release: released=%v err=%v", released, err) } - if released, err := store.PublishBatches.FailClaimedBatch(ctx, "lease-failure", "current"); err != nil || !released { + if // released、err 保存released、err,供当前处理流程使用 + released, err := store.PublishBatches.FailClaimedBatch(ctx, "lease-failure", "current"); err != nil || !released { t.Fatalf("current release: released=%v err=%v", released, err) } + // batch、err 保存batch、err,供当前处理流程使用 batch, err := store.PublishBatches.Get(ctx, owner.ID, "lease-failure") if err != nil { t.Fatal(err) diff --git a/internal/db/migrate_test.go b/internal/db/migrate_test.go index f487672..32650c3 100644 --- a/internal/db/migrate_test.go +++ b/internal/db/migrate_test.go @@ -11,17 +11,23 @@ import ( // TestMigrate_AppliesCleanSchema 在临时库上跑迁移,验证全量 schema 干净落地、 // 关键不一致列(orders.system_shipped 等)存在、默认设置就位。 +// TestMigrate_AppliesCleanSchema 负责TestMigrateAppliesCleanSchema相关处理。 func TestMigrate_AppliesCleanSchema(t *testing.T) { + // tmp 保存tmp,供当前处理流程使用 tmp := t.TempDir() + // dbPath 保存db路径,供当前处理流程使用 dbPath := filepath.Join(tmp, "test.db") + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // db、err 保存db、err,供当前处理流程使用 db, _, err := Open(ctx, dbPath) if err != nil { t.Fatalf("Open: %v", err) } defer db.Close() + // checks 保存checks,供当前处理流程使用 checks := []struct { table string col string @@ -59,6 +65,7 @@ func TestMigrate_AppliesCleanSchema(t *testing.T) { {"risk_control_logs", "duration_ms"}, {"notification_outbox", "worker_token"}, } + // c 表示当前遍历过程中的c for _, c := range checks { if !columnExists(t, db, c.table, c.col) { t.Errorf("列缺失: %s.%s(应为收敛后的最终 schema)", c.table, c.col) @@ -88,6 +95,7 @@ func TestMigrate_AppliesCleanSchema(t *testing.T) { if err := db.Close(); err != nil { t.Fatalf("close: %v", err) } + // db2、err 保存db2、err,供当前处理流程使用 db2, _, err := Open(ctx, dbPath) if err != nil { t.Fatalf("二次 Open 幂等失败: %v", err) @@ -95,16 +103,20 @@ func TestMigrate_AppliesCleanSchema(t *testing.T) { db2.Close() } +// columnExists 负责columnExists相关处理。 func columnExists(t *testing.T, db *sql.DB, table, col string) bool { t.Helper() + // rows、err 保存rows、err,供当前处理流程使用 rows, err := db.Query(`SELECT name FROM pragma_table_info(?)`, table) if err != nil { t.Fatalf("pragma_table_info(%s): %v", table, err) } defer rows.Close() for rows.Next() { + // name 保存名称,供当前处理流程使用 var name string - if err := rows.Scan(&name); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&name); err != nil { t.Fatalf("scan: %v", err) } if name == col { @@ -114,23 +126,30 @@ func columnExists(t *testing.T, db *sql.DB, table, col string) bool { return false } +// TestLatestMigrationsDownUpSQLite 负责TestLatestMigrationsDownUpSQLite相关处理。 func TestLatestMigrationsDownUpSQLite(t *testing.T) { + // tmp 保存tmp,供当前处理流程使用 tmp := t.TempDir() + // dbPath 保存db路径,供当前处理流程使用 dbPath := filepath.Join(tmp, "rollback.db") + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // d、err 保存d、err,供当前处理流程使用 d, _, err := Open(ctx, dbPath) if err != nil { t.Fatalf("Open: %v", err) } defer d.Close() - if err := goose.SetDialect("sqlite3"); err != nil { + if // err 保存err,供当前处理流程使用 + err := goose.SetDialect("sqlite3"); err != nil { t.Fatalf("goose dialect: %v", err) } goose.SetBaseFS(migrationsFS) // 依次回滚最新版本到 13,再整体升级。 for i := 0; i < 15; i++ { - if err := goose.Down(d, "migrations/sqlite"); err != nil { + if // err 保存err,供当前处理流程使用 + err := goose.Down(d, "migrations/sqlite"); err != nil { t.Fatalf("down migration #%d: %v", i+1, err) } } @@ -158,15 +177,18 @@ func TestLatestMigrationsDownUpSQLite(t *testing.T) { if columnExists(t, d, "item_publish_batches", "location_json") { t.Fatal("item_publish_batches.location_json should be removed after migration 28 down") } + // table 表示当前遍历过程中的table for _, table := range []string{"account_task_settings", "account_task_runs", "chat_sessions", "chat_messages"} { if tableExists(t, d, table) { t.Fatalf("table should be removed after migration 24 down: %s", table) } } - if err := goose.Up(d, "migrations/sqlite"); err != nil { + if // err 保存err,供当前处理流程使用 + err := goose.Up(d, "migrations/sqlite"); err != nil { t.Fatalf("up after down: %v", err) } + // c 表示当前遍历过程中的c for _, c := range []struct { table string col string @@ -191,15 +213,20 @@ func TestLatestMigrationsDownUpSQLite(t *testing.T) { t.Fatalf("column missing after re-up: %s.%s", c.table, c.col) } } + // val 保存val,供当前处理流程使用 var val string - if err := d.QueryRow(`SELECT value FROM system_settings WHERE key='renewal_log_retention_days'`).Scan(&val); err != nil || val != "10" { + if // err 保存err,供当前处理流程使用 + err := d.QueryRow(`SELECT value FROM system_settings WHERE key='renewal_log_retention_days'`).Scan(&val); err != nil || val != "10" { t.Fatalf("renewal_log_retention_days after re-up: val=%q err=%v", val, err) } } +// tableExists 负责tableExists相关处理。 func tableExists(t *testing.T, db *sql.DB, table string) bool { t.Helper() + // name 保存名称,供当前处理流程使用 var name string + // err 保存err,供当前处理流程使用 err := db.QueryRow(`SELECT name FROM sqlite_master WHERE type='table' AND name=?`, table).Scan(&name) if err != nil { return false diff --git a/internal/db/multidb_test.go b/internal/db/multidb_test.go index 510da1d..601998a 100644 --- a/internal/db/multidb_test.go +++ b/internal/db/multidb_test.go @@ -44,19 +44,25 @@ type testTarget struct { // allTestTargets 返回所有可用的测试目标。SQLite 永远包含;MySQL/Postgres 按环境变量追加。 func allTestTargets(t *testing.T) []testTarget { t.Helper() + // targets 保存targets,供当前处理流程使用 targets := []testTarget{sqliteTarget(t)} - if u := os.Getenv("TEST_MYSQL_URL"); u != "" { + if // u 保存u,供当前处理流程使用 + u := os.Getenv("TEST_MYSQL_URL"); u != "" { targets = append(targets, mysqlTarget(t, u)) } - if u := os.Getenv("TEST_POSTGRES_URL"); u != "" { + if // u 保存u,供当前处理流程使用 + u := os.Getenv("TEST_POSTGRES_URL"); u != "" { targets = append(targets, postgresTarget(t, u)) } return targets } +// sqliteTarget 负责sqliteTarget相关处理。 func sqliteTarget(t *testing.T) testTarget { t.Helper() + // dbPath 保存db路径,供当前处理流程使用 dbPath := filepath.Join(t.TempDir(), "multidb.db") + // db、err 保存db、err,供当前处理流程使用 db, _, err := Open(context.Background(), dbPath) if err != nil { t.Fatalf("open sqlite: %v", err) @@ -66,31 +72,41 @@ func sqliteTarget(t *testing.T) testTarget { // mysqlTarget 在 MySQL 服务器上创建一次性数据库,跑迁移后返回 store。 // 测试结束 DROP 该库,保证隔离。 +// mysqlTarget 负责mysqlTarget相关处理。 func mysqlTarget(t *testing.T, url string) testTarget { t.Helper() + // dsn 保存dsn,供当前处理流程使用 dsn := strings.TrimPrefix(url, "mysql://") + // slash 保存slash,供当前处理流程使用 slash := strings.LastIndex(dsn, "/") if slash < 0 { t.Fatalf("TEST_MYSQL_URL 缺少 /dbname: %s", url) } + // baseDSN 保存baseDSN,供当前处理流程使用 baseDSN := dsn[:slash] // user:pass@tcp(host:port) + // admin、err 保存admin、err,供当前处理流程使用 admin, err := sql.Open("mysql", baseDSN+"/") if err != nil { t.Fatalf("open mysql admin: %v", err) } + // dbName 保存db名称,供当前处理流程使用 dbName := fmt.Sprintf("xytest_%d", atomic.AddUint64(&multidbCounter, 1)) - if _, err := admin.Exec("DROP DATABASE IF EXISTS " + dbName); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := admin.Exec("DROP DATABASE IF EXISTS " + dbName); err != nil { t.Fatalf("drop stale mysql db: %v", err) } - if _, err := admin.Exec("CREATE DATABASE " + dbName); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := admin.Exec("CREATE DATABASE " + dbName); err != nil { t.Fatalf("create mysql db: %v", err) } + // db、err 保存db、err,供当前处理流程使用 db, _, err := Open(context.Background(), "mysql://"+baseDSN+"/"+dbName) if err != nil { _, _ = admin.Exec("DROP DATABASE " + dbName) t.Fatalf("open mysql test db: %v", err) } + // cleanup 保存cleanup,供当前处理流程使用 cleanup := func() { db.Close() _, _ = admin.Exec("DROP DATABASE " + dbName) @@ -101,32 +117,42 @@ func mysqlTarget(t *testing.T, url string) testTarget { // postgresTarget 在 Postgres 服务器上创建一次性数据库。 // 连接到 maintenance 库(postgres)执行 CREATE DATABASE,再连到新库跑迁移。 +// postgresTarget 负责postgresTarget相关处理。 func postgresTarget(t *testing.T, url string) testTarget { t.Helper() + // rest 保存rest,供当前处理流程使用 rest := strings.TrimPrefix(url, "postgres://") // rest = user:pass@host:port/xianyu + // slash 保存slash,供当前处理流程使用 slash := strings.LastIndex(rest, "/") if slash < 0 { t.Fatalf("TEST_POSTGRES_URL 缺少 /dbname: %s", url) } + // server 保存server,供当前处理流程使用 server := rest[:slash] // user:pass@host:port + // admin、err 保存admin、err,供当前处理流程使用 admin, err := sql.Open("pgx_compat", "postgres://"+server+"/postgres") if err != nil { t.Fatalf("open pg admin: %v", err) } + // dbName 保存db名称,供当前处理流程使用 dbName := fmt.Sprintf("xytest_%d", atomic.AddUint64(&multidbCounter, 1)) - if _, err := admin.Exec("DROP DATABASE IF EXISTS " + dbName); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := admin.Exec("DROP DATABASE IF EXISTS " + dbName); err != nil { t.Fatalf("drop stale pg db: %v", err) } - if _, err := admin.Exec("CREATE DATABASE " + dbName); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := admin.Exec("CREATE DATABASE " + dbName); err != nil { t.Fatalf("create pg db: %v", err) } + // db、err 保存db、err,供当前处理流程使用 db, _, err := Open(context.Background(), "postgres://"+server+"/"+dbName) if err != nil { _, _ = admin.Exec("DROP DATABASE " + dbName) t.Fatalf("open pg test db: %v", err) } + // cleanup 保存cleanup,供当前处理流程使用 cleanup := func() { db.Close() _, _ = admin.Exec("DROP DATABASE " + dbName) @@ -137,28 +163,36 @@ func postgresTarget(t *testing.T, url string) testTarget { // TestMultiDB_CookiesUpsertBool 验证 cookie UPSERT + auto_confirm 布尔读写跨三库一致。 func TestMultiDB_CookiesUpsertBool(t *testing.T) { + // tg 表示当前遍历过程中的tg for _, tg := range allTestTargets(t) { t.Run(tg.name, func(t *testing.T) { defer tg.cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := tg.store // 先建用户(cookies.user_id 外键)。 uid := tg.name + "_user_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) - if ok, err := s.Users.Create(ctx, uid, uid+"@e.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Users.Create(ctx, uid, uid+"@e.com", "pw"); err != nil || !ok { t.Fatalf("create user: ok=%v err=%v", ok, err) } + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, uid) + // cid 保存cid,供当前处理流程使用 cid := tg.name + "_cookie_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) - if err := s.Cookies.Save(ctx, cid, "cv", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.Save(ctx, cid, "cv", user.ID); err != nil { t.Fatalf("Save: %v", err) } // 二次 Save 走 UPSERT 分支(更新 value)。 if err := s.Cookies.Save(ctx, cid, "cv2", user.ID); err != nil { t.Fatalf("Save upsert: %v", err) } - if v, err := s.Cookies.GetValue(ctx, cid); err != nil || v != "cv2" { + if // v、err 保存v、err,供当前处理流程使用 + v, err := s.Cookies.GetValue(ctx, cid); err != nil || v != "cv2" { t.Fatalf("GetValue=%q err=%v want cv2", v, err) } @@ -166,11 +200,13 @@ func TestMultiDB_CookiesUpsertBool(t *testing.T) { if enabled, err := s.Cookies.GetAutoConfirm(ctx, cid); err != nil || !enabled { t.Fatalf("default auto_confirm=%v err=%v want true", enabled, err) } - if _, err := s.DB.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE cookies SET auto_confirm=0 WHERE id=?`, cid); err != nil { t.Fatalf("disable auto_confirm: %v", err) } - if enabled, err := s.Cookies.GetAutoConfirm(ctx, cid); err != nil || enabled { + if // enabled、err 保存enabled、err,供当前处理流程使用 + enabled, err := s.Cookies.GetAutoConfirm(ctx, cid); err != nil || enabled { t.Fatalf("after disable auto_confirm=%v err=%v want false", enabled, err) } @@ -182,89 +218,123 @@ func TestMultiDB_CookiesUpsertBool(t *testing.T) { } } +// TestMultiDB_ReliabilityStateAndSearch 负责TestMultiDBReliability状态And搜索相关处理。 func TestMultiDB_ReliabilityStateAndSearch(t *testing.T) { + // tg 表示当前遍历过程中的tg for _, tg := range allTestTargets(t) { t.Run(tg.name, func(t *testing.T) { defer tg.cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := tg.store + // suffix 保存suffix,供当前处理流程使用 suffix := fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) + // username 保存username,供当前处理流程使用 username := tg.name + "_reliability_" + suffix - if ok, err := s.Users.Create(ctx, username, username+"@e.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Users.Create(ctx, username, username+"@e.com", "pw"); err != nil || !ok { t.Fatalf("create user: ok=%v err=%v", ok, err) } + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, username) + // cookieID 保存登录凭证ID,供当前处理流程使用 cookieID := tg.name + "_reliability_cookie_" + suffix - if err := s.Cookies.Save(ctx, cookieID, "unb=test", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.Save(ctx, cookieID, "unb=test", user.ID); err != nil { t.Fatal(err) } + // keywordID、err 保存关键词ID、err,供当前处理流程使用 keywordID, err := s.Keywords.Add(ctx, cookieID, "same", "same reply", "", "text", "") if err != nil { t.Fatal(err) } + // unchangedKeyword 保存unchanged关键词,供当前处理流程使用 unchangedKeyword := KeywordRow{ID: keywordID, CookieID: cookieID, Keyword: "same", Reply: "same reply", Type: "text"} - if err := s.Keywords.UpdateByID(ctx, unchangedKeyword); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Keywords.UpdateByID(ctx, unchangedKeyword); err != nil { t.Fatalf("no-op keyword update must succeed on %s: %v", tg.name, err) } - if _, err := s.Cookies.SetPause(ctx, cookieID, 1); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.Cookies.SetPause(ctx, cookieID, 1); err != nil { t.Fatal(err) } - if paused, _, err := s.Cookies.IsPaused(ctx, cookieID); err != nil || !paused { + if // paused、err 保存paused、err,供当前处理流程使用 + paused, _, err := s.Cookies.IsPaused(ctx, cookieID); err != nil || !paused { t.Fatalf("pause state: paused=%v err=%v", paused, err) } + // batchID 保存批次ID,供当前处理流程使用 batchID := tg.name + "_batch_" + suffix - if err := s.PublishBatches.Create(ctx, &ItemPublishBatch{ + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.Create(ctx, &ItemPublishBatch{ ID: batchID, UserID: user.ID, DefaultCookieID: cookieID, Filename: "test.csv", Status: "pending", }, []ItemPublishBatchRow{{RowNo: 1, CookieID: cookieID, Title: "item", Price: "1"}}); err != nil { t.Fatal(err) } - if claimed, err := s.PublishBatches.ClaimBatch(ctx, batchID, "worker", time.Now().UTC().Add(time.Minute).Unix()); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, batchID, "worker", time.Now().UTC().Add(time.Minute).Unix()); err != nil || !claimed { t.Fatalf("claim batch: claimed=%v err=%v", claimed, err) } + // batchRows 保存批次Rows,供当前处理流程使用 batchRows, _ := s.PublishBatches.Rows(ctx, batchID) - if claimed, err := s.PublishBatches.ClaimRow(ctx, batchRows[0].ID, "worker"); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimRow(ctx, batchRows[0].ID, "worker"); err != nil || !claimed { t.Fatalf("claim row: claimed=%v err=%v", claimed, err) } - if marked, err := s.PublishBatches.MarkClaimedRowSuccess(ctx, batchRows[0].ID, "worker", "published", "", "{}"); err != nil || !marked { + if // marked、err 保存marked、err,供当前处理流程使用 + marked, err := s.PublishBatches.MarkClaimedRowSuccess(ctx, batchRows[0].ID, "worker", "published", "", "{}"); err != nil || !marked { t.Fatalf("mark row: marked=%v err=%v", marked, err) } - if finished, err := s.PublishBatches.FinishBatchStatus(ctx, batchID, "worker", "completed"); err != nil || !finished { + if // finished、err 保存finished、err,供当前处理流程使用 + finished, err := s.PublishBatches.FinishBatchStatus(ctx, batchID, "worker", "completed"); err != nil || !finished { t.Fatalf("finish batch: finished=%v err=%v", finished, err) } + // cancelBatchID 保存取消批次ID,供当前处理流程使用 cancelBatchID := tg.name + "_cancel_batch_" + suffix - if err := s.PublishBatches.Create(ctx, &ItemPublishBatch{ + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.Create(ctx, &ItemPublishBatch{ ID: cancelBatchID, UserID: user.ID, DefaultCookieID: cookieID, Filename: "test.csv", Status: "pending", }, []ItemPublishBatchRow{{RowNo: 1, CookieID: cookieID, Title: "cancel", Price: "1"}}); err != nil { t.Fatal(err) } - if claimed, err := s.PublishBatches.ClaimBatch(ctx, cancelBatchID, "cancel-worker", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, cancelBatchID, "cancel-worker", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { t.Fatalf("claim cancel batch=%v err=%v", claimed, err) } - if token, running, err := s.PublishBatches.RequestCancel(ctx, cancelBatchID); err != nil || !running || token != "cancel-worker" { + if // token、running、err 保存token、running、err,供当前处理流程使用 + token, running, err := s.PublishBatches.RequestCancel(ctx, cancelBatchID); err != nil || !running || token != "cancel-worker" { t.Fatalf("request cancel token=%q running=%v err=%v", token, running, err) } - if finalized, err := s.PublishBatches.FinalizeCanceled(ctx, cancelBatchID, "cancel-worker"); err != nil || !finalized { + if // finalized、err 保存finalized、err,供当前处理流程使用 + finalized, err := s.PublishBatches.FinalizeCanceled(ctx, cancelBatchID, "cancel-worker"); err != nil || !finalized { t.Fatalf("finalize cancel=%v err=%v", finalized, err) } + // uncertainBatchID 保存uncertain批次ID,供当前处理流程使用 uncertainBatchID := tg.name + "_uncertain_batch_" + suffix - if err := s.PublishBatches.Create(ctx, &ItemPublishBatch{ + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.Create(ctx, &ItemPublishBatch{ ID: uncertainBatchID, UserID: user.ID, DefaultCookieID: cookieID, Filename: "test.csv", Status: "pending", }, []ItemPublishBatchRow{{RowNo: 1, CookieID: cookieID, Title: "item", Price: "1"}}); err != nil { t.Fatal(err) } - if claimed, err := s.PublishBatches.ClaimBatch(ctx, uncertainBatchID, "old", 1); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, uncertainBatchID, "old", 1); err != nil || !claimed { t.Fatalf("claim uncertain batch=%v err=%v", claimed, err) } + // uncertainRows 保存uncertainRows,供当前处理流程使用 uncertainRows, _ := s.PublishBatches.Rows(ctx, uncertainBatchID) - if claimed, err := s.PublishBatches.ClaimRow(ctx, uncertainRows[0].ID, "old"); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimRow(ctx, uncertainRows[0].ID, "old"); err != nil || !claimed { t.Fatalf("claim uncertain row=%v err=%v", claimed, err) } - if marked, err := s.PublishBatches.MarkClaimedRemoteStarted(ctx, uncertainRows[0].ID, "old"); err != nil || !marked { + if // marked、err 保存marked、err,供当前处理流程使用 + marked, err := s.PublishBatches.MarkClaimedRemoteStarted(ctx, uncertainRows[0].ID, "old"); err != nil || !marked { t.Fatalf("mark remote started=%v err=%v", marked, err) } - if claimed, err := s.PublishBatches.ClaimBatch(ctx, uncertainBatchID, "new", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, uncertainBatchID, "new", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { t.Fatalf("take over uncertain batch=%v err=%v", claimed, err) } uncertainRows, _ = s.PublishBatches.Rows(ctx, uncertainBatchID) @@ -272,78 +342,102 @@ func TestMultiDB_ReliabilityStateAndSearch(t *testing.T) { t.Fatalf("uncertain row=%+v", uncertainRows[0]) } + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := s.Automation.Create(ctx, AutomationRuleInput{UserID: user.ID, CookieID: cookieID, Name: "issue", TriggerType: "buyer_reviewed", Enabled: true, Actions: []AutomationActionInput{{ActionType: "send_text", MessageTemplate: "x", Enabled: true}}}) if err != nil { t.Fatal(err) } + // runID、started、err 保存运行ID、started、err,供当前处理流程使用 runID, started, err := s.Automation.TryStartRun(ctx, AutomationRun{RuleID: ruleID, CookieID: cookieID, TriggerType: "buyer_reviewed", TriggerKey: "issue-" + suffix, RawEventJSON: `{}`, LeaseExpiresAt: 1}) if err != nil || !started { t.Fatalf("start issue run=%v err=%v", started, err) } - if ok, err := s.Automation.StartRunAction(ctx, runID, 1, 0, 1); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Automation.StartRunAction(ctx, runID, 1, 0, 1); err != nil || !ok { t.Fatalf("start issue action=%v err=%v", ok, err) } - if err := s.Automation.QuarantineRunResult(ctx, runID, 1, 1, "unknown"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.QuarantineRunResult(ctx, runID, 1, 1, "unknown"); err != nil { t.Fatal(err) } - if err := s.Automation.Delete(ctx, user.ID, ruleID); err != ErrAutomationRunActive { + if // err 保存err,供当前处理流程使用 + err := s.Automation.Delete(ctx, user.ID, ruleID); err != ErrAutomationRunActive { t.Fatalf("active rule delete err=%v", err) } + // runIssues、err 保存运行Issues、err,供当前处理流程使用 runIssues, _, err := s.Automation.ListIssues(ctx, user.ID) if err != nil || len(runIssues) != 1 { t.Fatalf("issues=%+v err=%v", runIssues, err) } - if err := s.Automation.ResolveRunIssue(ctx, user.ID, runID, "cancel"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.ResolveRunIssue(ctx, user.ID, runID, "cancel"); err != nil { t.Fatal(err) } + // fencedRunID、started、err 保存fenced运行ID、started、err,供当前处理流程使用 fencedRunID, started, err := s.Automation.TryStartRun(ctx, AutomationRun{RuleID: ruleID, CookieID: cookieID, TriggerType: "buyer_reviewed", TriggerKey: "fenced-" + suffix, RawEventJSON: `{}`}) if err != nil || !started { t.Fatalf("start fenced run=%v err=%v", started, err) } - if _, err := s.DB.ExecContext(ctx, `UPDATE automation_runs SET lease_expires_at=0 WHERE id=?`, fencedRunID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE automation_runs SET lease_expires_at=0 WHERE id=?`, fencedRunID); err != nil { t.Fatal(err) } - if claimed, err := s.Automation.ClaimRecoveryRun(ctx, fencedRunID, time.Now().Add(time.Minute).Unix()); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.Automation.ClaimRecoveryRun(ctx, fencedRunID, time.Now().Add(time.Minute).Unix()); err != nil || !claimed { t.Fatalf("claim fenced run=%v err=%v", claimed, err) } + // fencedRun、err 保存fencedRun、err,供当前处理流程使用 fencedRun, err := s.Automation.GetRun(ctx, fencedRunID) if err != nil || fencedRun.AttemptCount != 2 { t.Fatalf("fenced run=%+v err=%v", fencedRun, err) } - if err := s.Automation.FinishRun(ctx, fencedRunID, 1, "failed", 0, "stale"); !errors.Is(err, ErrAutomationRunLeaseLost) { + if // err 保存err,供当前处理流程使用 + err := s.Automation.FinishRun(ctx, fencedRunID, 1, "failed", 0, "stale"); !errors.Is(err, ErrAutomationRunLeaseLost) { t.Fatalf("stale finish err=%v", err) } - if err := s.Automation.FinishRun(ctx, fencedRunID, fencedRun.AttemptCount, "success", 0, ""); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.FinishRun(ctx, fencedRunID, fencedRun.AttemptCount, "success", 0, ""); err != nil { t.Fatal(err) } + // deferred 保存deferred,供当前处理流程使用 deferred := DeferredAutomationTask{TaskKey: "dead-" + suffix, CookieID: cookieID, TriggerType: "buyer_reviewed", TaskJSON: `{}`, DueAt: 0} - if err := s.Automation.DeferTask(ctx, deferred); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.DeferTask(ctx, deferred); err != nil { t.Fatal(err) } _, _ = s.DB.ExecContext(ctx, `UPDATE automation_pending_tasks SET status='dead_letter',attempt_count=5 WHERE task_key=?`, deferred.TaskKey) - if err := s.Automation.DeferTask(ctx, deferred); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.DeferTask(ctx, deferred); err != nil { t.Fatal(err) } - if claimed, err := s.Automation.ClaimDueDeferredTasks(ctx, 10); err != nil || len(claimed) != 1 { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.Automation.ClaimDueDeferredTasks(ctx, 10); err != nil || len(claimed) != 1 { t.Fatalf("revived deferred=%+v err=%v", claimed, err) } + // itemID 保存商品ID,供当前处理流程使用 itemID := "search-item-" + suffix + // orderID 保存订单ID,供当前处理流程使用 orderID := "search-order-" + suffix - if err := s.Items.Upsert(ctx, &ItemInfoRow{CookieID: cookieID, ItemID: itemID, ItemTitle: "Cross Database Search"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Items.Upsert(ctx, &ItemInfoRow{CookieID: cookieID, ItemID: itemID, ItemTitle: "Cross Database Search"}); err != nil { t.Fatal(err) } - if err := s.Orders.Upsert(ctx, orderID, OrderUpsertOpts{CookieID: cookieID, ItemID: itemID, Amount: "9.9"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, orderID, OrderUpsertOpts{CookieID: cookieID, ItemID: itemID, Amount: "9.9"}); err != nil { t.Fatal(err) } + // empty 保存empty,供当前处理流程使用 empty := "" - if err := s.Orders.Patch(ctx, orderID, OrderPatch{Amount: &empty}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Patch(ctx, orderID, OrderPatch{Amount: &empty}); err != nil { t.Fatal(err) } + // orders、total、err 保存orders、total、err,供当前处理流程使用 orders, total, err := s.Orders.ListForUser(ctx, OrderListFilter{UserID: user.ID, Search: "cross database", Limit: 10}) if err != nil || total != 1 || len(orders) != 1 || orders[0].Amount != "" { t.Fatalf("search/patch orders=%+v total=%d err=%v", orders, total, err) @@ -352,38 +446,52 @@ func TestMultiDB_ReliabilityStateAndSearch(t *testing.T) { } } +// TestMultiDB_SettingsQuoteKey 负责TestMultiDB设置QuoteKey相关处理。 func TestMultiDB_SettingsQuoteKey(t *testing.T) { + // tg 表示当前遍历过程中的tg for _, tg := range allTestTargets(t) { t.Run(tg.name, func(t *testing.T) { defer tg.cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := tg.store - if err := s.Settings.Set(ctx, "theme_color", "green"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Settings.Set(ctx, "theme_color", "green"); err != nil { t.Fatalf("Settings.Set: %v", err) } - if err := s.Settings.SetMany(ctx, map[string]string{"theme_color": "blue", "bulk_key": "bulk_value"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Settings.SetMany(ctx, map[string]string{"theme_color": "blue", "bulk_key": "bulk_value"}); err != nil { t.Fatalf("Settings.SetMany: %v", err) } - if got, _ := s.Settings.Get(ctx, "theme_color"); got != "blue" { + if // got 保存got,供当前处理流程使用 + got, _ := s.Settings.Get(ctx, "theme_color"); got != "blue" { t.Fatalf("SetMany theme_color=%q", got) } + // got、err 保存got、err,供当前处理流程使用 got, err := s.Settings.Get(ctx, "theme_color") if err != nil || got != "blue" { t.Fatalf("Settings.Get=%q err=%v want blue", got, err) } + // all、err 保存all、err,供当前处理流程使用 all, err := s.Settings.All(ctx) if err != nil || all["theme_color"] != "blue" || all["bulk_key"] != "bulk_value" { t.Fatalf("Settings.All=%v err=%v", all, err) } + // username 保存username,供当前处理流程使用 username := tg.name + "_settings_user_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) - if ok, err := s.Users.Create(ctx, username, username+"@e.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Users.Create(ctx, username, username+"@e.com", "pw"); err != nil || !ok { t.Fatalf("create user: ok=%v err=%v", ok, err) } + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, username) + // keyCol 保存keyCol,供当前处理流程使用 keyCol := dialectQuote(tg.dialect, "key") - if _, err := s.DB.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `INSERT INTO user_settings (user_id, `+keyCol+`, value, updated_at) VALUES (?,?,?,CURRENT_TIMESTAMP)`+ dialectUpsert(tg.dialect, []string{"user_id", keyCol}, map[string]string{ "value": "EXCLUDED.value", @@ -392,8 +500,10 @@ func TestMultiDB_SettingsQuoteKey(t *testing.T) { user.ID, "dashboard_range", "30"); err != nil { t.Fatalf("insert user_settings: %v", err) } + // value 保存值,供当前处理流程使用 var value string - if err := s.DB.QueryRowContext(ctx, + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRowContext(ctx, `SELECT value FROM user_settings WHERE user_id=? AND `+keyCol+`=?`, user.ID, "dashboard_range").Scan(&value); err != nil || value != "30" { t.Fatalf("select user_settings=%q err=%v want 30", value, err) @@ -404,19 +514,26 @@ func TestMultiDB_SettingsQuoteKey(t *testing.T) { // TestMultiDB_OrdersUpsertNullScan 验证订单部分字段 Upsert 后 Get 能正确扫描 NULL 列。 func TestMultiDB_OrdersUpsertNullScan(t *testing.T) { + // tg 表示当前遍历过程中的tg for _, tg := range allTestTargets(t) { t.Run(tg.name, func(t *testing.T) { defer tg.cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := tg.store + // oid 保存oid,供当前处理流程使用 oid := tg.name + "_order_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) // orders.cookie_id 外键 cookies.id,需先建账号。 uid := tg.name + "_order_user_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) s.Users.Create(ctx, uid, uid+"@e.com", "pw") + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, uid) + // cid 保存cid,供当前处理流程使用 cid := tg.name + "_order_cookie_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) - if err := s.Cookies.Save(ctx, cid, "cv", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.Save(ctx, cid, "cv", user.ID); err != nil { t.Fatalf("Save cookie: %v", err) } // 首次 Upsert 只给少量字段,其余列留 NULL/默认。 @@ -428,6 +545,7 @@ func TestMultiDB_OrdersUpsertNullScan(t *testing.T) { }); err != nil { t.Fatalf("Upsert insert: %v", err) } + // got、err 保存got、err,供当前处理流程使用 got, err := s.Orders.Get(ctx, oid) if err != nil { t.Fatalf("Get: %v", err) @@ -466,21 +584,28 @@ func TestMultiDB_OrdersUpsertNullScan(t *testing.T) { // TestMultiDB_ItemsUpsert 验证 item_info Upsert + 布尔开关跨三库一致。 func TestMultiDB_ItemsUpsert(t *testing.T) { + // tg 表示当前遍历过程中的tg for _, tg := range allTestTargets(t) { t.Run(tg.name, func(t *testing.T) { defer tg.cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := tg.store + // cid 保存cid,供当前处理流程使用 cid := tg.name + "_item_cookie_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) // item_info.cookie_id 外键 cookies.id,需先建账号。 uid := tg.name + "_item_user_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) s.Users.Create(ctx, uid, uid+"@e.com", "pw") + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, uid) - if err := s.Cookies.Save(ctx, cid, "cv", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.Save(ctx, cid, "cv", user.ID); err != nil { t.Fatalf("Save cookie: %v", err) } - if err := s.Items.Upsert(ctx, &ItemInfoRow{ + if // err 保存err,供当前处理流程使用 + err := s.Items.Upsert(ctx, &ItemInfoRow{ CookieID: cid, ItemID: "i1", ItemTitle: "标题", ItemPrice: "9.9", }); err != nil { t.Fatalf("Upsert: %v", err) @@ -491,6 +616,7 @@ func TestMultiDB_ItemsUpsert(t *testing.T) { }); err != nil { t.Fatalf("Upsert update: %v", err) } + // items、err 保存items、err,供当前处理流程使用 items, err := s.Items.AllForCookie(ctx, cid) if err != nil { t.Fatalf("AllForCookie: %v", err) @@ -512,21 +638,30 @@ func TestMultiDB_ItemsUpsert(t *testing.T) { // TestMultiDB_AutomationTryStartRunDedup 验证 TryStartRun 的 UNIQUE 防重: // 同 rule_id + trigger_key 第二次插入应返回 started=false。 +// TestMultiDB_AutomationTryStartRunDedup 负责TestMultiDB自动化Try开始运行Dedup相关处理。 func TestMultiDB_AutomationTryStartRunDedup(t *testing.T) { + // tg 表示当前遍历过程中的tg for _, tg := range allTestTargets(t) { t.Run(tg.name, func(t *testing.T) { defer tg.cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := tg.store + // uid 保存uid,供当前处理流程使用 uid := tg.name + "_auto_user_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) s.Users.Create(ctx, uid, uid+"@e.com", "pw") + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, uid) + // cid 保存cid,供当前处理流程使用 cid := tg.name + "_auto_cookie_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) - if err := s.Cookies.Save(ctx, cid, "cv", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.Save(ctx, cid, "cv", user.ID); err != nil { t.Fatalf("Save cookie: %v", err) } + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := s.Automation.Create(ctx, AutomationRuleInput{ UserID: user.ID, CookieID: cid, @@ -545,6 +680,7 @@ func TestMultiDB_AutomationTryStartRunDedup(t *testing.T) { t.Fatalf("Create rule: %v", err) } + // run 保存运行,供当前处理流程使用 run := AutomationRun{ RuleID: ruleID, CookieID: cid, @@ -553,6 +689,7 @@ func TestMultiDB_AutomationTryStartRunDedup(t *testing.T) { TriggerType: "paid", TriggerKey: "paid:o1", } + // id1、started、err 保存id1、started、err,供当前处理流程使用 id1, started, err := s.Automation.TryStartRun(ctx, run) if err != nil || !started || id1 == 0 { t.Fatalf("首次 TryStartRun: id=%d started=%v err=%v", id1, started, err) @@ -564,6 +701,7 @@ func TestMultiDB_AutomationTryStartRunDedup(t *testing.T) { } // 不同 trigger_key 可再次启动。 run.TriggerKey = "paid:o2" + // id3、started3、err 保存id3、started3、err,供当前处理流程使用 id3, started3, err := s.Automation.TryStartRun(ctx, run) if err != nil || !started3 || id3 == 0 { t.Fatalf("不同 trigger_key 应启动: id=%d started=%v err=%v", id3, started3, err) @@ -579,54 +717,74 @@ func TestMultiDB_AutomationTryStartRunDedup(t *testing.T) { // TestMultiDB_DeferredAutomationCredentialWake 验证延迟任务的失败退避和凭证恢复唤醒 // 在各数据库方言下行为一致,同时确保正常的业务延迟不会被提前唤醒。 +// TestMultiDB_DeferredAutomationCredentialWake 负责TestMultiDBDeferred自动化CredentialWake相关处理。 func TestMultiDB_DeferredAutomationCredentialWake(t *testing.T) { + // tg 表示当前遍历过程中的tg for _, tg := range allTestTargets(t) { t.Run(tg.name, func(t *testing.T) { defer tg.cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := tg.store + // suffix 保存suffix,供当前处理流程使用 suffix := fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) + // username 保存username,供当前处理流程使用 username := tg.name + "_deferred_user_" + suffix - if ok, err := s.Users.Create(ctx, username, username+"@e.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Users.Create(ctx, username, username+"@e.com", "pw"); err != nil || !ok { t.Fatalf("create user: ok=%v err=%v", ok, err) } + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, username) + // cookieID 保存登录凭证ID,供当前处理流程使用 cookieID := tg.name + "_deferred_cookie_" + suffix - if err := s.Cookies.Save(ctx, cookieID, "cv", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.Save(ctx, cookieID, "cv", user.ID); err != nil { t.Fatalf("save cookie: %v", err) } - if err := s.Automation.DeferTask(ctx, DeferredAutomationTask{ + if // err 保存err,供当前处理流程使用 + err := s.Automation.DeferTask(ctx, DeferredAutomationTask{ TaskKey: "credential-" + suffix, CookieID: cookieID, TriggerType: "order_paid", TaskJSON: `{}`, DueAt: 0, ErrorMessage: "FAIL_SYS_SESSION_EXPIRED", }); err != nil { t.Fatalf("defer credential task: %v", err) } + // claimed、err 保存claimed、err,供当前处理流程使用 claimed, err := s.Automation.ClaimDueDeferredTasks(ctx, 1) if err != nil || len(claimed) != 1 { t.Fatalf("claim credential task: tasks=%+v err=%v", claimed, err) } + // before 保存before,供当前处理流程使用 before := time.Now().UTC().Unix() - if err := s.Automation.FinishDeferredTask(ctx, claimed[0].ID, claimed[0].ClaimVersion, false, "session expired"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.FinishDeferredTask(ctx, claimed[0].ID, claimed[0].ClaimVersion, false, "session expired"); err != nil { t.Fatalf("finish failed task: %v", err) } + // intentionalDue 保存intentionalDue,供当前处理流程使用 intentionalDue := before + 3600 - if err := s.Automation.DeferTask(ctx, DeferredAutomationTask{ + if // err 保存err,供当前处理流程使用 + err := s.Automation.DeferTask(ctx, DeferredAutomationTask{ TaskKey: "intentional-" + suffix, CookieID: cookieID, TriggerType: "buyer_reviewed", TaskJSON: `{}`, DueAt: intentionalDue, }); err != nil { t.Fatalf("defer intentional task: %v", err) } - if err := s.Automation.WakeCredentialBlocked(ctx, cookieID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.WakeCredentialBlocked(ctx, cookieID); err != nil { t.Fatalf("wake credential tasks: %v", err) } + // credentialDue、normalDue 保存credentialDue、normalDue,供当前处理流程使用 var credentialDue, normalDue int64 - if err := s.DB.QueryRowContext(ctx, `SELECT due_at FROM automation_pending_tasks WHERE task_key=?`, "credential-"+suffix).Scan(&credentialDue); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRowContext(ctx, `SELECT due_at FROM automation_pending_tasks WHERE task_key=?`, "credential-"+suffix).Scan(&credentialDue); err != nil { t.Fatalf("read credential due_at: %v", err) } - if err := s.DB.QueryRowContext(ctx, `SELECT due_at FROM automation_pending_tasks WHERE task_key=?`, "intentional-"+suffix).Scan(&normalDue); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRowContext(ctx, `SELECT due_at FROM automation_pending_tasks WHERE task_key=?`, "intentional-"+suffix).Scan(&normalDue); err != nil { t.Fatalf("read intentional due_at: %v", err) } if credentialDue != 0 { @@ -639,22 +797,33 @@ func TestMultiDB_DeferredAutomationCredentialWake(t *testing.T) { } } +// TestMultiDB_AutomationSafeCheckpointRetry 负责TestMultiDB自动化SafeCheckpoint重试相关处理。 func TestMultiDB_AutomationSafeCheckpointRetry(t *testing.T) { + // tg 表示当前遍历过程中的tg for _, tg := range allTestTargets(t) { t.Run(tg.name, func(t *testing.T) { defer tg.cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := tg.store + // suffix 保存suffix,供当前处理流程使用 suffix := fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) + // username 保存username,供当前处理流程使用 username := tg.name + "_checkpoint_user_" + suffix - if ok, err := s.Users.Create(ctx, username, username+"@e.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Users.Create(ctx, username, username+"@e.com", "pw"); err != nil || !ok { t.Fatalf("create user: ok=%v err=%v", ok, err) } + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, username) + // cookieID 保存登录凭证ID,供当前处理流程使用 cookieID := tg.name + "_checkpoint_cookie_" + suffix - if err := s.Cookies.Save(ctx, cookieID, "cv", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.Save(ctx, cookieID, "cv", user.ID); err != nil { t.Fatal(err) } + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := s.Automation.Create(ctx, AutomationRuleInput{ UserID: user.ID, CookieID: cookieID, Name: "checkpoint", TriggerType: "order_paid", Enabled: true, Actions: []AutomationActionInput{{ActionType: "send_text", Enabled: true}}, @@ -662,6 +831,7 @@ func TestMultiDB_AutomationSafeCheckpointRetry(t *testing.T) { if err != nil { t.Fatal(err) } + // runID、started、err 保存运行ID、started、err,供当前处理流程使用 runID, started, err := s.Automation.TryStartRun(ctx, AutomationRun{ RuleID: ruleID, CookieID: cookieID, OrderID: "order-" + suffix, TriggerType: "order_paid", TriggerKey: "order_paid:order-" + suffix, RawEventJSON: `{}`, @@ -669,36 +839,47 @@ func TestMultiDB_AutomationSafeCheckpointRetry(t *testing.T) { if err != nil || !started { t.Fatalf("start run: started=%v err=%v", started, err) } - if ok, err := s.Automation.StartRunAction(ctx, runID, 1, 0, time.Now().Add(time.Minute).Unix()); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Automation.StartRunAction(ctx, runID, 1, 0, time.Now().Add(time.Minute).Unix()); err != nil || !ok { t.Fatalf("start first action: ok=%v err=%v", ok, err) } - if err := s.Automation.AdvanceRunAction(ctx, runID, 1, 0, 1); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.AdvanceRunAction(ctx, runID, 1, 0, 1); err != nil { t.Fatal(err) } - if ok, err := s.Automation.StartRunAction(ctx, runID, 1, 1, time.Now().Add(time.Minute).Unix()); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Automation.StartRunAction(ctx, runID, 1, 1, time.Now().Add(time.Minute).Unix()); err != nil || !ok { t.Fatalf("start second action: ok=%v err=%v", ok, err) } - if err := s.Automation.AbortRunAction(ctx, runID, 1, 1); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.AbortRunAction(ctx, runID, 1, 1); err != nil { t.Fatal(err) } - if err := s.Automation.FinishRun(ctx, runID, 1, "failed", 1, SafeRetryErrorPrefix+"session expired"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.FinishRun(ctx, runID, 1, "failed", 1, SafeRetryErrorPrefix+"session expired"); err != nil { t.Fatal(err) } - if _, err := s.DB.ExecContext(ctx, `UPDATE automation_runs SET next_retry_at=0 WHERE id=?`, runID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE automation_runs SET next_retry_at=0 WHERE id=?`, runID); err != nil { t.Fatal(err) } + // due、err 保存due、err,供当前处理流程使用 due, err := s.Automation.DueRecoveryRuns(ctx, 10) if err != nil || len(due) != 1 || due[0].ID != runID || due[0].ActionCursor != 1 || due[0].SentCount != 1 { t.Fatalf("due=%+v err=%v", due, err) } + // newLease 保存newLease,供当前处理流程使用 newLease := time.Now().Add(5 * time.Minute).Unix() + // claimed、err 保存claimed、err,供当前处理流程使用 claimed, err := s.Automation.ClaimRecoveryRun(ctx, runID, newLease) if err != nil || !claimed { t.Fatalf("claim safe checkpoint: claimed=%v err=%v", claimed, err) } - if err := s.Automation.PostponeRecoveryRun(ctx, runID, due[0].AttemptCount, time.Now().Add(time.Minute).Unix()); !errors.Is(err, ErrAutomationRunLeaseLost) { + if // err 保存err,供当前处理流程使用 + err := s.Automation.PostponeRecoveryRun(ctx, runID, due[0].AttemptCount, time.Now().Add(time.Minute).Unix()); !errors.Is(err, ErrAutomationRunLeaseLost) { t.Fatalf("stale postpone err=%v want lease lost", err) } + // current、err 保存current、err,供当前处理流程使用 current, err := s.Automation.GetRun(ctx, runID) if err != nil || current.LeaseExpiresAt != newLease { t.Fatalf("claimed lease overwritten: run=%+v err=%v", current, err) @@ -709,33 +890,44 @@ func TestMultiDB_AutomationSafeCheckpointRetry(t *testing.T) { // TestMultiDB_Notifications 验证通知渠道创建 + 账号绑定读写。 func TestMultiDB_Notifications(t *testing.T) { + // tg 表示当前遍历过程中的tg for _, tg := range allTestTargets(t) { t.Run(tg.name, func(t *testing.T) { defer tg.cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := tg.store + // uid 保存uid,供当前处理流程使用 uid := tg.name + "_notif_user_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) s.Users.Create(ctx, uid, uid+"@e.com", "pw") + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, uid) + // cid 保存cid,供当前处理流程使用 cid := tg.name + "_notif_cookie_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) - if err := s.Cookies.Save(ctx, cid, "cv", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.Save(ctx, cid, "cv", user.ID); err != nil { t.Fatalf("Save cookie: %v", err) } + // chID、err 保存chID、err,供当前处理流程使用 chID, err := s.Notifications.CreateChannel(ctx, &NotificationChannelRow{ Name: "wh", Type: "webhook", Config: `{"url":"x"}`, Enabled: true, UserID: user.ID, }) if err != nil || chID == 0 { t.Fatalf("CreateChannel: id=%d err=%v", chID, err) } + // channels 保存渠道列表,供当前处理流程使用 channels, _ := s.Notifications.AllChannelsForUser(ctx, user.ID) if len(channels) != 1 || !channels[0].Enabled || channels[0].Config != `{"url":"x"}` { t.Fatalf("channels = %#v", channels) } - if err := s.Notifications.SetBindings(ctx, cid, []int64{chID}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Notifications.SetBindings(ctx, cid, []int64{chID}); err != nil { t.Fatalf("SetBindings: %v", err) } + // bindings 保存bindings,供当前处理流程使用 bindings, _ := s.Notifications.AccountBindings(ctx, cid) if len(bindings) != 1 || bindings[0] != chID { t.Fatalf("bindings = %#v", bindings) @@ -748,31 +940,40 @@ func TestMultiDB_Notifications(t *testing.T) { if len(bindings) != 0 { t.Fatalf("清空后 bindings = %#v", bindings) } - if err := s.Notifications.EnqueueOutbox(ctx, []NotificationOutboxInput{{ChannelID: chID, EventType: "test", Body: "body"}}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Notifications.EnqueueOutbox(ctx, []NotificationOutboxInput{{ChannelID: chID, EventType: "test", Body: "body"}}); err != nil { t.Fatalf("EnqueueOutbox: %v", err) } + // messages、err 保存messages、err,供当前处理流程使用 messages, err := s.Notifications.ClaimOutbox(ctx, "worker", time.Now(), 10) if err != nil || len(messages) != 1 { t.Fatalf("ClaimOutbox: messages=%+v err=%v", messages, err) } - if completed, err := s.Notifications.CompleteOutbox(ctx, messages[0].ID, "worker"); err != nil || !completed { + if // completed、err 保存completed、err,供当前处理流程使用 + completed, err := s.Notifications.CompleteOutbox(ctx, messages[0].ID, "worker"); err != nil || !completed { t.Fatalf("CompleteOutbox: completed=%v err=%v", completed, err) } }) } } +// TestMultiDB_LatestMigrationsDownUp 负责TestMultiDBLatestMigrationsDownUp相关处理。 func TestMultiDB_LatestMigrationsDownUp(t *testing.T) { + // tg 表示当前遍历过程中的tg for _, tg := range allTestTargets(t) { t.Run(tg.name, func(t *testing.T) { defer tg.cleanup() + // subdir、gooseDialect 保存subdir、gooseDialect,供当前处理流程使用 subdir, gooseDialect := migrationTestSubdir(t, tg.dialect) - if err := goose.SetDialect(gooseDialect); err != nil { + if // err 保存err,供当前处理流程使用 + err := goose.SetDialect(gooseDialect); err != nil { t.Fatalf("set goose dialect: %v", err) } goose.SetBaseFS(migrationsFS) - for i := 0; i < 15; i++ { - if err := goose.Down(tg.store.DB, "migrations/"+subdir); err != nil { + for // i 保存i,供当前处理流程使用 + i := 0; i < 15; i++ { + if // err 保存err,供当前处理流程使用 + err := goose.Down(tg.store.DB, "migrations/"+subdir); err != nil { t.Fatalf("migration down #%d: %v", i+1, err) } } @@ -794,15 +995,18 @@ func TestMultiDB_LatestMigrationsDownUp(t *testing.T) { if columnExistsForDialect(t, tg.store.DB, tg.dialect, "item_publish_batches", "location_json") { t.Fatal("item_publish_batches.location_json should be removed after down") } + // table 表示当前遍历过程中的table for _, table := range []string{"account_task_settings", "account_task_runs", "chat_sessions", "chat_messages"} { if tableExistsForDialect(t, tg.store.DB, tg.dialect, table) { t.Fatalf("table should be removed after migration 24 down: %s", table) } } - if err := goose.Up(tg.store.DB, "migrations/"+subdir); err != nil { + if // err 保存err,供当前处理流程使用 + err := goose.Up(tg.store.DB, "migrations/"+subdir); err != nil { t.Fatalf("migration up after down: %v", err) } + // c 表示当前遍历过程中的c for _, c := range []struct { table string col string @@ -836,23 +1040,34 @@ func TestMultiDB_LatestMigrationsDownUp(t *testing.T) { } } +// TestMultiDB_ChatAndAccountTasks 负责TestMultiDB聊天And账号任务列表相关处理。 func TestMultiDB_ChatAndAccountTasks(t *testing.T) { + // tg 表示当前遍历过程中的tg for _, tg := range allTestTargets(t) { t.Run(tg.name, func(t *testing.T) { defer tg.cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := tg.store + // suffix 保存suffix,供当前处理流程使用 suffix := fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) + // username 保存username,供当前处理流程使用 username := tg.name + "_chat_" + suffix - if ok, err := s.Users.Create(ctx, username, username+"@e.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Users.Create(ctx, username, username+"@e.com", "pw"); err != nil || !ok { t.Fatalf("create user: ok=%v err=%v", ok, err) } + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, username) + // cookieID 保存登录凭证ID,供当前处理流程使用 cookieID := tg.name + "_chat_cookie_" + suffix - if err := s.Cookies.Save(ctx, cookieID, "unb=1; _m_h5_tk=token_1", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.Save(ctx, cookieID, "unb=1; _m_h5_tk=token_1", user.ID); err != nil { t.Fatal(err) } + // settings、err 保存settings、err,供当前处理流程使用 settings, err := s.AccountTasks.Get(ctx, cookieID) if err != nil || settings.RateContent == "" || settings.PolishTime != "03:00" { t.Fatalf("default settings=%+v err=%v", settings, err) @@ -861,62 +1076,82 @@ func TestMultiDB_ChatAndAccountTasks(t *testing.T) { settings.AutoPolishEnabled = true settings.RateContent = "交易愉快" settings.PolishTime = "04:30" - if err := s.AccountTasks.Upsert(ctx, settings); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.AccountTasks.Upsert(ctx, settings); err != nil { t.Fatalf("upsert settings: %v", err) } + // stored、err 保存stored、err,供当前处理流程使用 stored, err := s.AccountTasks.Get(ctx, cookieID) if err != nil || !stored.AutoRateEnabled || !stored.AutoPolishEnabled || stored.RateContent != "交易愉快" || stored.PolishTime != "04:30" { t.Fatalf("stored settings=%+v err=%v", stored, err) } + // enabled、err 保存enabled、err,供当前处理流程使用 enabled, err := s.AccountTasks.Enabled(ctx) if err != nil || len(enabled) != 1 { t.Fatalf("enabled=%+v err=%v", enabled, err) } + // run 保存运行,供当前处理流程使用 run := AccountTaskRun{RunKey: "rate:" + cookieID + ":order-1", CookieID: cookieID, TaskType: "auto_rate", TargetID: "order-1"} - if claimed, err := s.AccountTasks.ClaimRun(ctx, run, 100); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.AccountTasks.ClaimRun(ctx, run, 100); err != nil || !claimed { t.Fatalf("first claim=%v err=%v", claimed, err) } - if claimed, err := s.AccountTasks.ClaimRun(ctx, run, 100); err != nil || claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.AccountTasks.ClaimRun(ctx, run, 100); err != nil || claimed { t.Fatalf("duplicate claim=%v err=%v", claimed, err) } - if err := s.AccountTasks.FinishRun(ctx, run.RunKey, "failed", 0, 1, "retry", 200); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.AccountTasks.FinishRun(ctx, run.RunKey, "failed", 0, 1, "retry", 200); err != nil { t.Fatal(err) } - if claimed, err := s.AccountTasks.ClaimRun(ctx, run, 199); err != nil || claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.AccountTasks.ClaimRun(ctx, run, 199); err != nil || claimed { t.Fatalf("early retry claim=%v err=%v", claimed, err) } - if claimed, err := s.AccountTasks.ClaimRunImmediately(ctx, run, 199); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.AccountTasks.ClaimRunImmediately(ctx, run, 199); err != nil || !claimed { t.Fatalf("manual retry claim=%v err=%v", claimed, err) } - if err := s.AccountTasks.FinishRun(ctx, run.RunKey, "failed", 0, 1, "retry", 200); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.AccountTasks.FinishRun(ctx, run.RunKey, "failed", 0, 1, "retry", 200); err != nil { t.Fatal(err) } - if claimed, err := s.AccountTasks.ClaimRun(ctx, run, 200); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.AccountTasks.ClaimRun(ctx, run, 200); err != nil || !claimed { t.Fatalf("due retry claim=%v err=%v", claimed, err) } + // session 保存会话,供当前处理流程使用 session := ChatSession{CookieID: cookieID, ChatID: "chat-1", BuyerID: "buyer-1", BuyerName: "买家甲", ItemID: "item-1"} + // incoming 保存incoming,供当前处理流程使用 incoming := ChatMessage{MessageKey: "platform-1", Direction: "incoming", SenderID: "buyer-1", SenderName: "买家甲", MessageType: "text", Content: "你好", Status: "received", SentAt: 1000} - if _, inserted, err := s.Chats.SaveMessage(ctx, session, incoming, true); err != nil || !inserted { + if // inserted、err 保存inserted、err,供当前处理流程使用 + _, inserted, err := s.Chats.SaveMessage(ctx, session, incoming, true); err != nil || !inserted { t.Fatalf("save incoming inserted=%v err=%v", inserted, err) } - if _, inserted, err := s.Chats.SaveMessage(ctx, session, incoming, true); err != nil || inserted { + if // inserted、err 保存inserted、err,供当前处理流程使用 + _, inserted, err := s.Chats.SaveMessage(ctx, session, incoming, true); err != nil || inserted { t.Fatalf("duplicate incoming inserted=%v err=%v", inserted, err) } + // outgoing 保存outgoing,供当前处理流程使用 outgoing := ChatMessage{MessageKey: "local-1", Direction: "outgoing", SenderID: cookieID, SenderName: "我", MessageType: "text", Content: "您好", Status: "sent", SentAt: 2000} - if _, inserted, err := s.Chats.SaveMessage(ctx, session, outgoing, false); err != nil || !inserted { + if // inserted、err 保存inserted、err,供当前处理流程使用 + _, inserted, err := s.Chats.SaveMessage(ctx, session, outgoing, false); err != nil || !inserted { t.Fatalf("save outgoing inserted=%v err=%v", inserted, err) } + // sessions、err 保存sessions、err,供当前处理流程使用 sessions, err := s.Chats.ListSessions(ctx, user.ID, cookieID, 20) if err != nil || len(sessions) != 1 || sessions[0].UnreadCount != 1 || sessions[0].LastMessage != "您好" { t.Fatalf("sessions=%+v err=%v", sessions, err) } + // messages、err 保存messages、err,供当前处理流程使用 messages, err := s.Chats.ListMessages(ctx, user.ID, cookieID, "chat-1", 0, 20) if err != nil || len(messages) != 2 || messages[0].Content != "你好" || messages[1].Content != "您好" { t.Fatalf("messages=%+v err=%v", messages, err) } - if err := s.Chats.MarkRead(ctx, user.ID, cookieID, "chat-1"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Chats.MarkRead(ctx, user.ID, cookieID, "chat-1"); err != nil { t.Fatal(err) } sessions, _ = s.Chats.ListSessions(ctx, user.ID, cookieID, 20) @@ -929,16 +1164,22 @@ func TestMultiDB_ChatAndAccountTasks(t *testing.T) { // TestMultiDB_CardsCreateGet 验证 cards Create + Get 的 NULL 列扫描(含 nullable 字段)。 func TestMultiDB_CardsCreateGet(t *testing.T) { + // tg 表示当前遍历过程中的tg for _, tg := range allTestTargets(t) { t.Run(tg.name, func(t *testing.T) { defer tg.cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := tg.store + // uid 保存uid,供当前处理流程使用 uid := tg.name + "_card_user_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) s.Users.Create(ctx, uid, uid+"@e.com", "pw") + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, uid) + // cf 保存cf,供当前处理流程使用 cf := &CardFull{ Name: "测试卡密", Type: "text", @@ -946,10 +1187,12 @@ func TestMultiDB_CardsCreateGet(t *testing.T) { Enabled: true, UserID: user.ID, } + // id、err 保存id、err,供当前处理流程使用 id, err := s.Cards.Create(ctx, cf) if err != nil || id == 0 { t.Fatalf("Create: id=%d err=%v", id, err) } + // got、err 保存got、err,供当前处理流程使用 got, err := s.Cards.Get(ctx, id) if err != nil { t.Fatalf("Get: %v", err) @@ -969,31 +1212,43 @@ func TestMultiDB_CardsCreateGet(t *testing.T) { // Postgres 回归:CASE WHEN ... THEN CURRENT_TIMESTAMP ELSE field END 会因 // THEN(timestamptz) 与 ELSE(text) 分支类型不可匹配而报 SQLSTATE 42804。 // 语义:字段为空时写入当前时间,已有值时不得覆盖(幂等)。 +// TestMultiDB_MarkOrderEventTime 负责TestMultiDBMark订单Event时间相关处理。 func TestMultiDB_MarkOrderEventTime(t *testing.T) { + // tg 表示当前遍历过程中的tg for _, tg := range allTestTargets(t) { t.Run(tg.name, func(t *testing.T) { defer tg.cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := tg.store + // uid 保存uid,供当前处理流程使用 uid := tg.name + "_evt_user_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) s.Users.Create(ctx, uid, uid+"@e.com", "pw") + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, uid) + // cid 保存cid,供当前处理流程使用 cid := tg.name + "_evt_cookie_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) - if err := s.Cookies.Save(ctx, cid, "cv", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.Save(ctx, cid, "cv", user.ID); err != nil { t.Fatalf("Save cookie: %v", err) } + // oid 保存oid,供当前处理流程使用 oid := tg.name + "_evt_order_" + fmt.Sprintf("%d", atomic.AddUint64(&multidbCounter, 1)) - if err := s.Orders.Upsert(ctx, oid, OrderUpsertOpts{ItemID: "i1", BuyerID: "b1", CookieID: cid}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, oid, OrderUpsertOpts{ItemID: "i1", BuyerID: "b1", CookieID: cid}); err != nil { t.Fatalf("Upsert: %v", err) } // 白名单字段为空时全部写入当前时间。 for _, f := range []string{"paid_at", "shipped_at", "completed_at", "buyer_reviewed_at", "last_review_request_at"} { - if err := s.Automation.MarkOrderEventTime(ctx, oid, f); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.MarkOrderEventTime(ctx, oid, f); err != nil { t.Fatalf("MarkOrderEventTime(%s) on %s: %v", f, tg.name, err) } } + // got、err 保存got、err,供当前处理流程使用 got, err := s.Orders.Get(ctx, oid) if err != nil { t.Fatalf("Get: %v", err) @@ -1004,14 +1259,18 @@ func TestMultiDB_MarkOrderEventTime(t *testing.T) { // 已有值时不得覆盖。 const original = "2020-01-02 03:04:05" - if _, err := s.DB.ExecContext(ctx, `UPDATE orders SET shipped_at=? WHERE order_id=?`, original, oid); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE orders SET shipped_at=? WHERE order_id=?`, original, oid); err != nil { t.Fatal(err) } - if err := s.Automation.MarkOrderEventTime(ctx, oid, "shipped_at"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Automation.MarkOrderEventTime(ctx, oid, "shipped_at"); err != nil { t.Fatalf("MarkOrderEventTime(shipped_at) overwrite on %s: %v", tg.name, err) } + // shippedAt 保存shippedAt,供当前处理流程使用 var shippedAt string - if err := s.DB.QueryRowContext(ctx, `SELECT shipped_at FROM orders WHERE order_id=?`, oid).Scan(&shippedAt); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRowContext(ctx, `SELECT shipped_at FROM orders WHERE order_id=?`, oid).Scan(&shippedAt); err != nil { t.Fatal(err) } if shippedAt != original { @@ -1026,6 +1285,7 @@ func TestMultiDB_MarkOrderEventTime(t *testing.T) { } } +// migrationTestSubdir 负责migrationTestSubdir相关处理。 func migrationTestSubdir(t *testing.T, dialect Dialect) (string, string) { t.Helper() switch dialect { @@ -1041,27 +1301,34 @@ func migrationTestSubdir(t *testing.T, dialect Dialect) (string, string) { } } +// columnExistsForDialect 负责columnExistsForDialect相关处理。 func columnExistsForDialect(t *testing.T, db *sql.DB, dialect Dialect, table, col string) bool { t.Helper() + // query 保存查询,供当前处理流程使用 var query string + // args 保存args,供当前处理流程使用 var args []any switch dialect { case DialectSQLite: + // rows、err 保存rows、err,供当前处理流程使用 rows, err := db.Query(`SELECT name FROM pragma_table_info(?)`, table) if err != nil { t.Fatalf("pragma_table_info(%s): %v", table, err) } defer rows.Close() for rows.Next() { + // name 保存名称,供当前处理流程使用 var name string - if err := rows.Scan(&name); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&name); err != nil { t.Fatalf("scan column name: %v", err) } if name == col { return true } } - if err := rows.Err(); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Err(); err != nil { t.Fatalf("column rows: %v", err) } return false @@ -1074,16 +1341,21 @@ func columnExistsForDialect(t *testing.T, db *sql.DB, dialect Dialect, table, co default: t.Fatalf("unknown dialect: %s", dialect) } + // count 保存数量,供当前处理流程使用 var count int - if err := db.QueryRow(query, args...).Scan(&count); err != nil { + if // err 保存err,供当前处理流程使用 + err := db.QueryRow(query, args...).Scan(&count); err != nil { t.Fatalf("column exists query %s.%s: %v", table, col, err) } return count > 0 } +// tableExistsForDialect 负责tableExistsForDialect相关处理。 func tableExistsForDialect(t *testing.T, db *sql.DB, dialect Dialect, table string) bool { t.Helper() + // query 保存查询,供当前处理流程使用 var query string + // args 保存args,供当前处理流程使用 var args []any switch dialect { case DialectSQLite: @@ -1098,11 +1370,14 @@ func tableExistsForDialect(t *testing.T, db *sql.DB, dialect Dialect, table stri default: t.Fatalf("unknown dialect: %s", dialect) } + // count 保存数量,供当前处理流程使用 var count int - if err := db.QueryRow(query, args...).Scan(&count); err != nil { + if // err 保存err,供当前处理流程使用 + err := db.QueryRow(query, args...).Scan(&count); err != nil { t.Fatalf("table exists query %s: %v", table, err) } return count > 0 } +// boolPtr 负责boolPtr相关处理。 func boolPtr(b bool) *bool { return &b } diff --git a/internal/db/notification_outbox_test.go b/internal/db/notification_outbox_test.go index 061c5d7..7e339e8 100644 --- a/internal/db/notification_outbox_test.go +++ b/internal/db/notification_outbox_test.go @@ -6,26 +6,38 @@ import ( "time" ) +// TestNotificationOutboxLeaseFencesStaleWorker 负责Test通知OutboxLeaseFencesStale工作器相关处理。 func TestNotificationOutboxLeaseFencesStaleWorker(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if ok, err := store.Users.Create(ctx, "notify-owner", "notify-owner@example.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := store.Users.Create(ctx, "notify-owner", "notify-owner@example.com", "pw"); err != nil || !ok { t.Fatalf("create owner: ok=%v err=%v", ok, err) } + // owner 保存所有者,供当前处理流程使用 owner, _ := store.Users.GetByUsername(ctx, "notify-owner") + // result、err 保存result、err,供当前处理流程使用 result, err := store.DB.ExecContext(ctx, `INSERT INTO notification_channels (name,type,config,enabled,user_id) VALUES (?,?,?,1,?)`, "test", "webhook", `{}`, owner.ID) if err != nil { t.Fatal(err) } + // channelID 保存渠道ID,供当前处理流程使用 channelID, _ := result.LastInsertId() - if err := store.Notifications.EnqueueOutbox(ctx, []NotificationOutboxInput{{ChannelID: channelID, EventType: "test", Body: "body"}}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Notifications.EnqueueOutbox(ctx, []NotificationOutboxInput{{ChannelID: channelID, EventType: "test", Body: "body"}}); err != nil { t.Fatal(err) } + // status、workerToken、lastError 保存status、workerToken、last错误,供当前处理流程使用 var status, workerToken, lastError string + // attempts 保存尝试次数,供当前处理流程使用 var attempts int + // nextAttemptAt、leaseExpiresAt 保存next尝试次数At、leaseExpiresAt,供当前处理流程使用 var nextAttemptAt, leaseExpiresAt int64 - if err := store.DB.QueryRowContext(ctx, `SELECT status,attempt_count,next_attempt_at,lease_expires_at,worker_token,last_error + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT status,attempt_count,next_attempt_at,lease_expires_at,worker_token,last_error FROM notification_outbox WHERE channel_id=?`, channelID). Scan(&status, &attempts, &nextAttemptAt, &leaseExpiresAt, &workerToken, &lastError); err != nil { t.Fatal(err) @@ -34,29 +46,37 @@ func TestNotificationOutboxLeaseFencesStaleWorker(t *testing.T) { t.Fatalf("unexpected initial outbox state: status=%q attempts=%d next=%d lease=%d worker=%q error=%q", status, attempts, nextAttemptAt, leaseExpiresAt, workerToken, lastError) } + // now 保存now,供当前处理流程使用 now := time.Unix(100, 0) + // first、err 保存first、err,供当前处理流程使用 first, err := store.Notifications.ClaimOutbox(ctx, "worker-1", now, 10) if err != nil || len(first) != 1 || first[0].AttemptCount != 1 { t.Fatalf("first claim: messages=%+v err=%v", first, err) } + // second、err 保存second、err,供当前处理流程使用 second, err := store.Notifications.ClaimOutbox(ctx, "worker-2", now.Add(time.Minute), 10) if err != nil || len(second) != 1 || second[0].AttemptCount != 2 { t.Fatalf("reclaim: messages=%+v err=%v", second, err) } - if completed, err := store.Notifications.CompleteOutbox(ctx, first[0].ID, "worker-1"); err != nil || completed { + if // completed、err 保存completed、err,供当前处理流程使用 + completed, err := store.Notifications.CompleteOutbox(ctx, first[0].ID, "worker-1"); err != nil || completed { t.Fatalf("stale completion: completed=%v err=%v", completed, err) } - if retried, err := store.Notifications.RetryOutbox(ctx, second[0].ID, "worker-2", "temporary", now.Add(2*time.Minute).Unix(), false); err != nil || !retried { + if // retried、err 保存retried、err,供当前处理流程使用 + retried, err := store.Notifications.RetryOutbox(ctx, second[0].ID, "worker-2", "temporary", now.Add(2*time.Minute).Unix(), false); err != nil || !retried { t.Fatalf("retry: retried=%v err=%v", retried, err) } - if early, err := store.Notifications.ClaimOutbox(ctx, "worker-3", now.Add(90*time.Second), 10); err != nil || len(early) != 0 { + if // early、err 保存early、err,供当前处理流程使用 + early, err := store.Notifications.ClaimOutbox(ctx, "worker-3", now.Add(90*time.Second), 10); err != nil || len(early) != 0 { t.Fatalf("early retry claim: messages=%+v err=%v", early, err) } + // due、err 保存due、err,供当前处理流程使用 due, err := store.Notifications.ClaimOutbox(ctx, "worker-3", now.Add(3*time.Minute), 10) if err != nil || len(due) != 1 { t.Fatalf("due retry claim: messages=%+v err=%v", due, err) } - if completed, err := store.Notifications.CompleteOutbox(ctx, due[0].ID, "worker-3"); err != nil || !completed { + if // completed、err 保存completed、err,供当前处理流程使用 + completed, err := store.Notifications.CompleteOutbox(ctx, due[0].ID, "worker-3"); err != nil || !completed { t.Fatalf("complete: completed=%v err=%v", completed, err) } } diff --git a/internal/db/notifications.go b/internal/db/notifications.go index 645e132..322d9b4 100644 --- a/internal/db/notifications.go +++ b/internal/db/notifications.go @@ -25,19 +25,23 @@ type Notifications struct { // OwnsChannel 判断通知渠道是否归属于指定用户。 func (n *Notifications) OwnsChannel(ctx context.Context, channelID, userID int64) (bool, error) { + // exists 保存exists,供当前处理流程使用 var exists bool + // err 保存err,供当前处理流程使用 err := n.DB.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM notification_channels WHERE id=? AND user_id=?)`, channelID, userID).Scan(&exists) return exists, err } +// NotificationOutboxInput 保存通知OutboxInput,供当前处理流程使用 type NotificationOutboxInput struct { ChannelID int64 EventType string Body string } +// NotificationOutboxMessage 保存通知Outbox消息,供当前处理流程使用 type NotificationOutboxMessage struct { ID int64 ChannelID int64 @@ -62,6 +66,7 @@ type NotificationBindingRow struct { // ListBindingsForUser 查询用户所有账号的通知渠道绑定。 func (n *Notifications) ListBindingsForUser(ctx context.Context, userID int64) ([]NotificationBindingRow, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := n.DB.QueryContext(ctx, ` SELECT mn.id, mn.cookie_id, mn.channel_id, COALESCE(nc.name, ''), mn.enabled FROM message_notifications mn @@ -72,11 +77,15 @@ func (n *Notifications) ListBindingsForUser(ctx context.Context, userID int64) ( return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []NotificationBindingRow for rows.Next() { + // item 保存商品,供当前处理流程使用 var item NotificationBindingRow + // enabled 保存启用状态,供当前处理流程使用 var enabled int - if err := rows.Scan(&item.ID, &item.CookieID, &item.ChannelID, &item.ChannelName, &enabled); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&item.ID, &item.CookieID, &item.ChannelID, &item.ChannelName, &enabled); err != nil { return nil, err } item.Enabled = enabled != 0 @@ -88,9 +97,11 @@ func (n *Notifications) ListBindingsForUser(ctx context.Context, userID int64) ( // SetSingleBinding 更新单个账号通知渠道的启用状态。 func (n *Notifications) SetSingleBinding(ctx context.Context, cookieID string, channelID int64, enabled bool) error { if !enabled { + // err 保存err,供当前处理流程使用 _, err := n.DB.ExecContext(ctx, `DELETE FROM message_notifications WHERE cookie_id=? AND channel_id=?`, cookieID, channelID) return err } + // err 保存err,供当前处理流程使用 _, err := n.DB.ExecContext(ctx, `INSERT INTO message_notifications (cookie_id, channel_id, enabled) VALUES (?, ?, ?)`+ dialectUpsert(n.Dialect, []string{"cookie_id", "channel_id"}, map[string]string{"enabled": "EXCLUDED.enabled", "updated_at": "CURRENT_TIMESTAMP"}), @@ -100,6 +111,7 @@ func (n *Notifications) SetSingleBinding(ctx context.Context, cookieID string, c // DeleteBinding 删除用户账号下的一条通知绑定。 func (n *Notifications) DeleteBinding(ctx context.Context, userID, bindingID int64) error { + // err 保存err,供当前处理流程使用 _, err := n.DB.ExecContext(ctx, ` DELETE FROM message_notifications WHERE id=? AND cookie_id IN (SELECT id FROM cookies WHERE user_id=?)`, bindingID, userID) return err @@ -107,6 +119,7 @@ func (n *Notifications) DeleteBinding(ctx context.Context, userID, bindingID int // DeleteAccountBindings 删除用户账号下的全部通知绑定。 func (n *Notifications) DeleteAccountBindings(ctx context.Context, userID int64, cookieID string) error { + // err 保存err,供当前处理流程使用 _, err := n.DB.ExecContext(ctx, ` DELETE FROM message_notifications WHERE cookie_id=? AND cookie_id IN (SELECT id FROM cookies WHERE user_id=?)`, cookieID, userID) return err @@ -114,7 +127,9 @@ func (n *Notifications) DeleteAccountBindings(ctx context.Context, userID int64, // AccountChannels 取某账号已启用的通知渠道(message_notifications JOIN notification_channels)。 // 移植自 get_account_notifications。 +// AccountChannels 负责账号渠道列表相关处理。 func (n *Notifications) AccountChannels(ctx context.Context, cookieID string) ([]NotificationChannel, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := n.DB.QueryContext(ctx, `SELECT nc.id, nc.name, nc.type, nc.config, COALESCE(nc.user_id,1), COALESCE(NULLIF(mn.event_types,''), nc.event_types, '') @@ -127,11 +142,15 @@ func (n *Notifications) AccountChannels(ctx context.Context, cookieID string) ([ return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []NotificationChannel for rows.Next() { + // c 保存c,供当前处理流程使用 var c NotificationChannel + // userID 保存用户ID,供当前处理流程使用 var userID int64 - if err := rows.Scan(&c.ID, &c.Name, &c.Type, &c.Config, &userID, &c.EventTypes); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&c.ID, &c.Name, &c.Type, &c.Config, &userID, &c.EventTypes); err != nil { return nil, err } c.Config, err = n.codec.decrypt("notification-config", strconv.FormatInt(userID, 10), c.Config) @@ -148,13 +167,16 @@ func (n *Notifications) EnqueueOutbox(ctx context.Context, messages []Notificati if len(messages) == 0 { return nil } + // tx、err 保存tx、err,供当前处理流程使用 tx, err := n.DB.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() + // message 表示当前遍历过程中的消息 for _, message := range messages { - if _, err := tx.ExecContext(ctx, `INSERT INTO notification_outbox + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `INSERT INTO notification_outbox (channel_id,event_type,body,status,attempt_count,next_attempt_at,lease_expires_at,worker_token,last_error) VALUES (?,?,?,'pending',0,0,0,'','')`, message.ChannelID, message.EventType, message.Body); err != nil { @@ -166,11 +188,14 @@ func (n *Notifications) EnqueueOutbox(ctx context.Context, messages []Notificati // ClaimOutbox 原子领取到期投递。过期 running 任务可以被重新接管,worker token // 用于隔离迟到的旧 worker。 +// ClaimOutbox 负责ClaimOutbox相关处理。 func (n *Notifications) ClaimOutbox(ctx context.Context, workerToken string, now time.Time, limit int) ([]NotificationOutboxMessage, error) { if limit <= 0 || limit > 100 { limit = 20 } + // nowUnix 保存nowUnix,供当前处理流程使用 nowUnix := now.Unix() + // rows、err 保存rows、err,供当前处理流程使用 rows, err := n.DB.QueryContext(ctx, `SELECT id,channel_id,event_type,body,attempt_count FROM notification_outbox WHERE (status='pending' AND next_attempt_at<=?) OR (status='running' AND lease_expires_at 0, err } +// upsertOrder 负责upsert订单相关处理。 func upsertOrder(ctx context.Context, execer sqlQueryExecer, dialect Dialect, orderID string, opts OrderUpsertOpts) error { if orderID == "" { return errors.New("order_id 不能为空") } opts.ItemID = strings.TrimSpace(opts.ItemID) if opts.Amount != "" { + // normalized、ok 保存normalized、ok,供当前处理流程使用 normalized, ok := NormalizeOrderAmount(opts.Amount) if !ok { return errors.New("订单金额必须是普通格式的非负有限数字") @@ -163,10 +182,14 @@ func upsertOrder(ctx context.Context, execer sqlQueryExecer, dialect Dialect, or return err } - for attempt := 0; attempt < maxOrderUpsertRetries; attempt++ { + for // attempt 保存尝试次数,供当前处理流程使用 + attempt := 0; attempt < maxOrderUpsertRetries; attempt++ { + // existingCookie、existingStatus、deletedAt 保存existingCookie、existingStatus、deletedAt,供当前处理流程使用 var existingCookie, existingStatus, deletedAt sql.NullString + // version 保存version,供当前处理流程使用 var version int - if err := execer.QueryRowContext(ctx, + if // err 保存err,供当前处理流程使用 + err := execer.QueryRowContext(ctx, `SELECT cookie_id,order_status,version,deleted_at FROM orders WHERE order_id=?`, orderID). Scan(&existingCookie, &existingStatus, &version, &deletedAt); err != nil { return err @@ -175,10 +198,12 @@ func upsertOrder(ctx context.Context, execer sqlQueryExecer, dialect Dialect, or return ErrForbidden } + // current 保存current,供当前处理流程使用 current := opts if current.OrderStatus != "" && !shouldUpdateOrderStatus(existingStatus.String, current.OrderStatus) { current.OrderStatus = "" } + // set、args 保存set、args,供当前处理流程使用 set, args := orderUpsertAssignments(current) if deletedAt.Valid && deletedAt.String != "" { set = append(set, "deleted_at=NULL") @@ -188,11 +213,13 @@ func upsertOrder(ctx context.Context, execer sqlQueryExecer, dialect Dialect, or } set = append(set, "version=version+1", "updated_at=CURRENT_TIMESTAMP") args = append(args, orderID, version) + // res、err 保存res、err,供当前处理流程使用 res, err := execer.ExecContext(ctx, `UPDATE orders SET `+joinSet(set)+` WHERE order_id=? AND version=?`, args...) if err != nil { return err } + // n、rowsErr 保存n、rowsErr,供当前处理流程使用 n, rowsErr := res.RowsAffected() if rowsErr != nil { return rowsErr @@ -204,9 +231,13 @@ func upsertOrder(ctx context.Context, execer sqlQueryExecer, dialect Dialect, or return ErrOrderConflict } +// orderUpsertAssignments 负责订单UpsertAssignments相关处理。 func orderUpsertAssignments(opts OrderUpsertOpts) ([]string, []any) { + // set 保存set,供当前处理流程使用 set := []string{} + // args 保存args,供当前处理流程使用 args := []any{} + // add 保存add,供当前处理流程使用 add := func(column string, value any, present bool) { if present { set = append(set, column+"=?") @@ -254,6 +285,7 @@ func NormalizeOrderAmount(raw string) (string, bool) { } else if !orderAmountPattern.MatchString(raw) { return "", false } + // value、err 保存value、err,供当前处理流程使用 value, err := strconv.ParseFloat(raw, 64) if err != nil || math.IsInf(value, 0) || math.IsNaN(value) { return "", false @@ -263,13 +295,16 @@ func NormalizeOrderAmount(raw string) (string, bool) { // shouldUpdateOrderStatus 防止延迟或重复的“已付款”事件把已发货/已完成订单回退。 // 退款、取消等分支并非线性流程,因此这里只拦截明确的历史阶段倒退。 +// shouldUpdateOrderStatus 负责shouldUpdate订单状态相关处理。 func shouldUpdateOrderStatus(current, incoming string) bool { current = NormalizeOrderStatus(current) incoming = NormalizeOrderStatus(incoming) if current == incoming || current == "unknown" { return true } + // early 保存early,供当前处理流程使用 early := incoming == "processing" || incoming == "paid" || incoming == "pending_ship" + // advanced 保存advanced,供当前处理流程使用 advanced := current == "shipped" || current == "completed" || current == "refunding" || current == "cancelled" if early && advanced { return false @@ -301,9 +336,13 @@ type OrderUpsertOpts struct { // Get 按 order_id 查询。 func (o *Orders) Get(ctx context.Context, orderID string) (*Order, error) { + // ord 保存ord,供当前处理流程使用 var ord Order + // isBargain、version、sysShipped 保存isBargain、version、sysShipped,供当前处理流程使用 var isBargain, version, sysShipped int + // itemID、buyerID、specName、specValue、qty、amount、status、cookieID、receiverName、receiverPhone、receiverAddr、receiverCity、chatID、paidAt、shippedAt、completedAt、buyerReviewedAt、lastReviewRequestAt、createdAt、updatedAt 保存商品ID、buyerID、specName、specValue、qty、amount、status、cookieID、receiverName、receiverPhone、receiverAddr、receiverCity、chatID、paidAt、shippedAt、completedAt、buyerReviewedAt、lastReview请求At、createdAt、updatedAt,供当前处理流程使用 var itemID, buyerID, specName, specValue, qty, amount, status, cookieID, receiverName, receiverPhone, receiverAddr, receiverCity, chatID, paidAt, shippedAt, completedAt, buyerReviewedAt, lastReviewRequestAt, createdAt, updatedAt sql.NullString + // err 保存err,供当前处理流程使用 err := o.DB.QueryRowContext(ctx, `SELECT order_id, item_id, buyer_id, spec_name, spec_value, quantity, amount, order_status, cookie_id, is_bargain, receiver_name, receiver_phone, receiver_address, @@ -348,6 +387,7 @@ func (o *Orders) Get(ctx context.Context, orderID string) (*Order, error) { return &ord, nil } +// boolToInt 负责boolToInt相关处理。 func boolToInt(b bool) int { if b { return 1 @@ -355,8 +395,11 @@ func boolToInt(b bool) int { return 0 } +// joinSet 负责joinSet相关处理。 func joinSet(parts []string) string { + // out 保存out,供当前处理流程使用 out := "" + // i、p 表示当前遍历过程中的i、p for i, p := range parts { if i > 0 { out += ", " diff --git a/internal/db/orders_concurrency_test.go b/internal/db/orders_concurrency_test.go index 76a00f3..66e335d 100644 --- a/internal/db/orders_concurrency_test.go +++ b/internal/db/orders_concurrency_test.go @@ -6,31 +6,44 @@ import ( "testing" ) +// TestOrderUpsertConcurrentStatusNeverRegresses 负责Test订单UpsertConcurrent状态NeverRegresses相关处理。 func TestOrderUpsertConcurrentStatusNeverRegresses(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if _, err := store.Users.Create(ctx, "order-owner", "order-owner@example.com", "pw"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.Users.Create(ctx, "order-owner", "order-owner@example.com", "pw"); err != nil { t.Fatal(err) } + // owner 保存所有者,供当前处理流程使用 owner, _ := store.Users.GetByUsername(ctx, "order-owner") - if err := store.Cookies.CreateOwned(ctx, "order-account", "cookie", owner.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.CreateOwned(ctx, "order-account", "cookie", owner.ID); err != nil { t.Fatal(err) } - if err := store.Orders.Upsert(ctx, "concurrent-order", OrderUpsertOpts{CookieID: "order-account", OrderStatus: "paid"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Orders.Upsert(ctx, "concurrent-order", OrderUpsertOpts{CookieID: "order-account", OrderStatus: "paid"}); err != nil { t.Fatal(err) } + // start 保存开始,供当前处理流程使用 start := make(chan struct{}) + // errCh 保存errCh,供当前处理流程使用 errCh := make(chan error, 200) + // wg 保存wg,供当前处理流程使用 var wg sync.WaitGroup + // status 表示当前遍历过程中的状态 for _, status := range []string{"paid", "shipped"} { + // status 保存状态,供当前处理流程使用 status := status wg.Add(1) go func() { defer wg.Done() <-start - for i := 0; i < 100; i++ { + for // i 保存i,供当前处理流程使用 + i := 0; i < 100; i++ { errCh <- store.Orders.Upsert(ctx, "concurrent-order", OrderUpsertOpts{ CookieID: "order-account", OrderStatus: status, }) @@ -40,30 +53,36 @@ func TestOrderUpsertConcurrentStatusNeverRegresses(t *testing.T) { close(start) wg.Wait() close(errCh) + // err 表示当前遍历过程中的err for err := range errCh { if err != nil { t.Fatalf("concurrent upsert: %v", err) } } + // order、err 保存order、err,供当前处理流程使用 order, err := store.Orders.Get(ctx, "concurrent-order") if err != nil { t.Fatal(err) } - if got := NormalizeOrderStatus(order.OrderStatus); got != "shipped" { + if // got 保存got,供当前处理流程使用 + got := NormalizeOrderStatus(order.OrderStatus); got != "shipped" { t.Fatalf("final status=%q want shipped", got) } if order.Version <= 1 { t.Fatalf("version=%d was not advanced", order.Version) } - if err := store.Orders.Upsert(ctx, "concurrent-order", OrderUpsertOpts{CookieID: "order-account", OrderStatus: "completed"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Orders.Upsert(ctx, "concurrent-order", OrderUpsertOpts{CookieID: "order-account", OrderStatus: "completed"}); err != nil { t.Fatal(err) } - if err := store.Orders.Upsert(ctx, "concurrent-order", OrderUpsertOpts{CookieID: "order-account", OrderStatus: "shipped"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Orders.Upsert(ctx, "concurrent-order", OrderUpsertOpts{CookieID: "order-account", OrderStatus: "shipped"}); err != nil { t.Fatal(err) } order, _ = store.Orders.Get(ctx, "concurrent-order") - if got := NormalizeOrderStatus(order.OrderStatus); got != "completed" { + if // got 保存got,供当前处理流程使用 + got := NormalizeOrderStatus(order.OrderStatus); got != "completed" { t.Fatalf("completed order regressed to %q", got) } } diff --git a/internal/db/orders_delivery_test.go b/internal/db/orders_delivery_test.go index 4440f8d..1f2055f 100644 --- a/internal/db/orders_delivery_test.go +++ b/internal/db/orders_delivery_test.go @@ -9,65 +9,89 @@ import ( "time" ) +// TestOrdersByCookiePageScansBeyondLegacyLimit 负责Test订单列表By登录凭证页码ScansBeyondLegacy上限相关处理。 func TestOrdersByCookiePageScansBeyondLegacyLimit(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cookieID 保存登录凭证ID,供当前处理流程使用 _, cookieID := seedAccount(t, s) - for i := 0; i < 1001; i++ { - if _, err := s.DB.ExecContext(ctx, `INSERT INTO orders (order_id,cookie_id,order_status,created_at) VALUES (?,?,?,?)`, + for // i 保存i,供当前处理流程使用 + i := 0; i < 1001; i++ { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `INSERT INTO orders (order_id,cookie_id,order_status,created_at) VALUES (?,?,?,?)`, fmt.Sprintf("page-order-%04d", i), cookieID, "2", fmt.Sprintf("2026-01-%02d 00:00:00", i%28+1)); err != nil { t.Fatal(err) } } + // first、err 保存first、err,供当前处理流程使用 first, err := s.Orders.ByCookiePage(ctx, cookieID, 500, 0) if err != nil || len(first) != 500 { t.Fatalf("first len=%d err=%v", len(first), err) } + // third、err 保存third、err,供当前处理流程使用 third, err := s.Orders.ByCookiePage(ctx, cookieID, 500, 1000) if err != nil || len(third) != 1 { t.Fatalf("third len=%d err=%v", len(third), err) } } +// TestOrdersSoftDeleteMissingForCookie 负责Test订单列表SoftDeleteMissingFor登录凭证相关处理。 func TestOrdersSoftDeleteMissingForCookie(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) + // orderID 表示当前遍历过程中的订单ID for _, orderID := range []string{"seller-order", "buyer-order"} { - if err := s.Orders.Upsert(ctx, orderID, OrderUpsertOpts{CookieID: cid, OrderStatus: "pending_ship"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, orderID, OrderUpsertOpts{CookieID: cid, OrderStatus: "pending_ship"}); err != nil { t.Fatal(err) } } + // deleted、err 保存deleted、err,供当前处理流程使用 deleted, err := s.Orders.SoftDeleteMissingForCookie(ctx, cid, map[string]struct{}{"seller-order": {}}) if err != nil || deleted != 1 { t.Fatalf("deleted=%d err=%v", deleted, err) } - if _, err := s.Orders.Get(ctx, "buyer-order"); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.Orders.Get(ctx, "buyer-order"); !errors.Is(err, ErrNotFound) { t.Fatalf("missing order should be hidden, err=%v", err) } - if err := s.Orders.Upsert(ctx, "buyer-order", OrderUpsertOpts{CookieID: cid, OrderStatus: "pending_ship"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "buyer-order", OrderUpsertOpts{CookieID: cid, OrderStatus: "pending_ship"}); err != nil { t.Fatal(err) } - if _, err := s.Orders.Get(ctx, "buyer-order"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.Orders.Get(ctx, "buyer-order"); err != nil { t.Fatalf("reappeared order should be restored, err=%v", err) } } // seedAccount 在临时库里建好 admin 用户 + 一个账号(cookie),返回 (userID, cookieID)。 // 多数订单/自动化/卡券测试都需要这两层外键先就位。 +// seedAccount 负责seed账号相关处理。 func seedAccount(t *testing.T, s *Store) (int64, string) { t.Helper() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if ok, err := s.Users.Create(ctx, "admin", "admin@e.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Users.Create(ctx, "admin", "admin@e.com", "pw"); err != nil || !ok { t.Fatalf("create admin: ok=%v err=%v", ok, err) } - if err := s.Users.SetAdmin(ctx, "admin"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Users.SetAdmin(ctx, "admin"); err != nil { t.Fatalf("set admin: %v", err) } + // admin 保存admin,供当前处理流程使用 admin, _ := s.Users.GetByUsername(ctx, "admin") - if err := s.Cookies.Save(ctx, "acc1", "cv=admin", admin.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.Save(ctx, "acc1", "cv=admin", admin.ID); err != nil { t.Fatalf("save cookie: %v", err) } return admin.ID, "acc1" @@ -77,81 +101,109 @@ func seedAccount(t *testing.T, s *Store) (int64, string) { // TestOrders_UpsertEmptyOrderID 空 order_id 应被拒绝。 func TestOrders_UpsertEmptyOrderID(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if err := s.Orders.Upsert(ctx, "", OrderUpsertOpts{ItemID: "i1"}); err == nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "", OrderUpsertOpts{ItemID: "i1"}); err == nil { t.Fatal("空 order_id 应报错") } } // TestOrders_UpsertNoFields 二次 Upsert 不带任何更新字段应直接返回 nil(无 UPDATE)。 func TestOrders_UpsertNoFields(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) - if err := s.Orders.Upsert(ctx, "o1", OrderUpsertOpts{ItemID: "i1", BuyerID: "b1", CookieID: cid, Amount: "9.9"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "o1", OrderUpsertOpts{ItemID: "i1", BuyerID: "b1", CookieID: cid, Amount: "9.9"}); err != nil { t.Fatalf("insert: %v", err) } // 不带任何更新字段 → set 为空 → 直接返回。 if err := s.Orders.Upsert(ctx, "o1", OrderUpsertOpts{}); err != nil { t.Fatalf("no-field upsert: %v", err) } + // got 保存got,供当前处理流程使用 got, _ := s.Orders.Get(ctx, "o1") if got.ItemID != "i1" || got.Amount != "9.9" { t.Fatalf("字段被清空: %#v", got) } } +// TestOrdersUpsertNormalizesAndRejectsAmountsAtRepositoryBoundary 负责Test订单列表UpsertNormalizesAndRejectsAmountsAtRepositoryBoundary相关处理。 func TestOrdersUpsertNormalizesAndRejectsAmountsAtRepositoryBoundary(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) - if err := s.Orders.Upsert(ctx, "normalized-amount", OrderUpsertOpts{CookieID: cid, Amount: "¥1,200.50"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "normalized-amount", OrderUpsertOpts{CookieID: cid, Amount: "¥1,200.50"}); err != nil { t.Fatal(err) } + // order 保存订单,供当前处理流程使用 order, _ := s.Orders.Get(ctx, "normalized-amount") if order.Amount != "1200.50" { t.Fatalf("amount=%q", order.Amount) } - if err := s.Orders.Upsert(ctx, "full-width-yen", OrderUpsertOpts{CookieID: cid, Amount: "¥12.50"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "full-width-yen", OrderUpsertOpts{CookieID: cid, Amount: "¥12.50"}); err != nil { t.Fatal(err) } order, _ = s.Orders.Get(ctx, "full-width-yen") if order.Amount != "12.50" { t.Fatalf("full-width amount=%q", order.Amount) } - if err := s.Orders.Upsert(ctx, "invalid-amount", OrderUpsertOpts{CookieID: cid, Amount: "1e3"}); err == nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "invalid-amount", OrderUpsertOpts{CookieID: cid, Amount: "1e3"}); err == nil { t.Fatal("scientific notation must be rejected") } - if _, err := s.Orders.Get(ctx, "invalid-amount"); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.Orders.Get(ctx, "invalid-amount"); !errors.Is(err, ErrNotFound) { t.Fatalf("invalid amount left a partial order: %v", err) } + // invalid 表示当前遍历过程中的invalid for _, invalid := range []string{"1,2", "12,34", "1,,000", "¥¥1"} { - if _, ok := NormalizeOrderAmount(invalid); ok { + if // ok 保存ok,供当前处理流程使用 + _, ok := NormalizeOrderAmount(invalid); ok { t.Fatalf("malformed grouped amount %q must be rejected", invalid) } } } +// TestOrders_PatchCanExplicitlyClearFields 负责Test订单列表PatchCanExplicitlyClear字段列表相关处理。 func TestOrders_PatchCanExplicitlyClearFields(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) - if err := s.Orders.Upsert(ctx, "patch-order", OrderUpsertOpts{ + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "patch-order", OrderUpsertOpts{ CookieID: cid, ItemID: "item-1", BuyerID: "buyer-1", Amount: "19.9", ReceiverPhone: "13800000000", }); err != nil { t.Fatal(err) } + // empty 保存empty,供当前处理流程使用 empty := "" + // shipped 保存shipped,供当前处理流程使用 shipped := true - if err := s.Orders.Patch(ctx, "patch-order", OrderPatch{Amount: &empty, ReceiverPhone: &empty, SystemShipped: &shipped}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Patch(ctx, "patch-order", OrderPatch{Amount: &empty, ReceiverPhone: &empty, SystemShipped: &shipped}); err != nil { t.Fatal(err) } + // got、err 保存got、err,供当前处理流程使用 got, err := s.Orders.Get(ctx, "patch-order") if err != nil { t.Fatal(err) @@ -161,18 +213,26 @@ func TestOrders_PatchCanExplicitlyClearFields(t *testing.T) { } } +// TestOrders_ListForUserSearchesAcrossJoinedFields 负责Test订单列表ListFor用户SearchesAcrossJoined字段列表相关处理。 func TestOrders_ListForUserSearchesAcrossJoinedFields(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid、cid 保存uid、cid,供当前处理流程使用 uid, cid := seedAccount(t, s) - if err := s.Orders.Upsert(ctx, "search-order", OrderUpsertOpts{CookieID: cid, ItemID: "item-1", BuyerID: "Buyer-ABC", ReceiverName: "张三"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "search-order", OrderUpsertOpts{CookieID: cid, ItemID: "item-1", BuyerID: "Buyer-ABC", ReceiverName: "张三"}); err != nil { t.Fatal(err) } - if err := s.Items.Upsert(ctx, &ItemInfoRow{CookieID: cid, ItemID: "item-1", ItemTitle: "Special Product"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Items.Upsert(ctx, &ItemInfoRow{CookieID: cid, ItemID: "item-1", ItemTitle: "Special Product"}); err != nil { t.Fatal(err) } + // search 表示当前遍历过程中的搜索 for _, search := range []string{"special", "buyer-abc", "张三", "search-order"} { + // rows、total、err 保存rows、total、err,供当前处理流程使用 rows, total, err := s.Orders.ListForUser(ctx, OrderListFilter{UserID: uid, Search: search, Limit: 20}) if err != nil || total != 1 || len(rows) != 1 || rows[0].OrderID != "search-order" { t.Fatalf("search %q: rows=%+v total=%d err=%v", search, rows, total, err) @@ -180,21 +240,29 @@ func TestOrders_ListForUserSearchesAcrossJoinedFields(t *testing.T) { } } +// TestOrders_UpsertRejectsCookieTakeover 负责Test订单列表UpsertRejects登录凭证Takeover相关处理。 func TestOrders_UpsertRejectsCookieTakeover(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // userID、cid 保存用户ID、cid,供当前处理流程使用 userID, cid := seedAccount(t, s) - if err := s.Cookies.Save(ctx, "acc2", "cv=other", userID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.Save(ctx, "acc2", "cv=other", userID); err != nil { t.Fatalf("save second cookie: %v", err) } - if err := s.Orders.Upsert(ctx, "o1", OrderUpsertOpts{ItemID: "i1", BuyerID: "b1", CookieID: cid}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "o1", OrderUpsertOpts{ItemID: "i1", BuyerID: "b1", CookieID: cid}); err != nil { t.Fatalf("insert: %v", err) } - if err := s.Orders.Upsert(ctx, "o1", OrderUpsertOpts{CookieID: "acc2", Amount: "99"}); !errors.Is(err, ErrForbidden) { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "o1", OrderUpsertOpts{CookieID: "acc2", Amount: "99"}); !errors.Is(err, ErrForbidden) { t.Fatalf("cookie takeover should be forbidden, got %v", err) } + // got、err 保存got、err,供当前处理流程使用 got, err := s.Orders.Get(ctx, "o1") if err != nil { t.Fatalf("get: %v", err) @@ -206,21 +274,27 @@ func TestOrders_UpsertRejectsCookieTakeover(t *testing.T) { // TestOrders_UpsertAllFields 覆盖 Upsert 全部可更新字段(spec/qty/receiver 等)。 func TestOrders_UpsertAllFields(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) - if err := s.Orders.Upsert(ctx, "o1", OrderUpsertOpts{ItemID: "i1", BuyerID: "b1", CookieID: cid}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "o1", OrderUpsertOpts{ItemID: "i1", BuyerID: "b1", CookieID: cid}); err != nil { t.Fatalf("insert: %v", err) } - if err := s.Orders.Upsert(ctx, "o1", OrderUpsertOpts{ + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "o1", OrderUpsertOpts{ SpecName: "红色", SpecValue: "L", Quantity: "2", Amount: "19.9", ReceiverName: "张三", ReceiverPhone: "13800000000", ReceiverAddr: "某地", ReceiverCity: "杭州", OrderStatus: "paid", ChatID: "chat1", }); err != nil { t.Fatalf("update: %v", err) } + // got 保存got,供当前处理流程使用 got, _ := s.Orders.Get(ctx, "o1") if got.SpecName != "红色" || got.SpecValue != "L" || got.Quantity != "2" || got.Amount != "19.9" || got.ReceiverName != "张三" || got.ReceiverPhone != "13800000000" || @@ -237,7 +311,8 @@ func TestOrders_UpsertAllFields(t *testing.T) { if !got.SystemShipped { t.Fatal("system_shipped 应为 true") } - if err := s.Orders.Upsert(ctx, "o1", OrderUpsertOpts{SystemShipped: boolPtr(false)}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "o1", OrderUpsertOpts{SystemShipped: boolPtr(false)}); err != nil { t.Fatalf("clear shipped: %v", err) } got, _ = s.Orders.Get(ctx, "o1") @@ -246,17 +321,24 @@ func TestOrders_UpsertAllFields(t *testing.T) { } } +// TestOrdersUpsertDoesNotRegressAdvancedStatus 负责Test订单列表UpsertDoesNotRegressAdvanced状态相关处理。 func TestOrdersUpsertDoesNotRegressAdvancedStatus(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) - if err := s.Orders.Upsert(ctx, "status-order", OrderUpsertOpts{CookieID: cid, OrderStatus: "completed"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "status-order", OrderUpsertOpts{CookieID: cid, OrderStatus: "completed"}); err != nil { t.Fatal(err) } - if err := s.Orders.Upsert(ctx, "status-order", OrderUpsertOpts{CookieID: cid, OrderStatus: "pending_ship", Amount: "10"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, "status-order", OrderUpsertOpts{CookieID: cid, OrderStatus: "pending_ship", Amount: "10"}); err != nil { t.Fatal(err) } + // got、err 保存got、err,供当前处理流程使用 got, err := s.Orders.Get(ctx, "status-order") if err != nil { t.Fatal(err) @@ -271,23 +353,30 @@ func TestOrdersUpsertDoesNotRegressAdvancedStatus(t *testing.T) { // TestOrders_GetNotFound 未找到返回 ErrNotFound。 func TestOrders_GetNotFound(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() - if _, err := s.Orders.Get(context.Background(), "nope"); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.Orders.Get(context.Background(), "nope"); !errors.Is(err, ErrNotFound) { t.Fatalf("want ErrNotFound, got %v", err) } } // TestOrders_ByCookie + NormalizeOrderStatus + AllTitles。 +// TestOrders_ByCookieAndTitles 负责Test订单列表By登录凭证AndTitles相关处理。 func TestOrders_ByCookieAndTitles(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) // 三条订单,按 created_at 倒序。 for i, oid := range []string{"o1", "o2", "o3"} { - if err := s.Orders.Upsert(ctx, oid, OrderUpsertOpts{ + if // err 保存err,供当前处理流程使用 + err := s.Orders.Upsert(ctx, oid, OrderUpsertOpts{ ItemID: "item_" + oid, BuyerID: "b1", CookieID: cid, Amount: "1.0", OrderStatus: NormalizeOrderStatus("2"), // pending_ship }); err != nil { @@ -339,6 +428,7 @@ func TestOrders_ByCookieAndTitles(t *testing.T) { // TestNormalizeOrderStatus 数字码与未知值。 func TestNormalizeOrderStatus(t *testing.T) { + // cases 保存cases,供当前处理流程使用 cases := map[string]string{ "1": "processing", "4": "completed", @@ -346,8 +436,10 @@ func TestNormalizeOrderStatus(t *testing.T) { "99": "99", // 未知数字码原样返回 "paid": "pending_ship", } + // in、want 表示当前遍历过程中的in、want for in, want := range cases { - if got := NormalizeOrderStatus(in); got != want { + if // got 保存got,供当前处理流程使用 + got := NormalizeOrderStatus(in); got != want { t.Errorf("NormalizeOrderStatus(%q)=%q want %q", in, got, want) } } @@ -355,16 +447,21 @@ func TestNormalizeOrderStatus(t *testing.T) { // TestCards_CRUD 卡券 Create/Update/Delete/AllForUser 全链路。 func TestCards_CRUD(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid 保存uid,供当前处理流程使用 uid, _ := seedAccount(t, s) + // cf 保存cf,供当前处理流程使用 cf := &CardFull{ Name: "卡密A", Type: "text", TextContent: "AAA", Enabled: true, UserID: uid, DelaySeconds: 5, IsMultiSpec: true, SpecName: "颜色", SpecValue: "红", APIConfig: `{"k":"v"}`, ImageURL: "http://img", Description: "desc", } + // id、err 保存id、err,供当前处理流程使用 id, err := s.Cards.Create(ctx, cf) if err != nil || id == 0 { t.Fatalf("Create: id=%d err=%v", id, err) @@ -386,9 +483,11 @@ func TestCards_CRUD(t *testing.T) { got.Enabled = false got.IsMultiSpec = false got.TextContent = "BBB" - if err := s.Cards.Update(ctx, got); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cards.Update(ctx, got); err != nil { t.Fatalf("Update: %v", err) } + // got2 保存got2,供当前处理流程使用 got2, _ := s.Cards.Get(ctx, id) if got2.Name != "卡密B" || got2.Enabled || got2.IsMultiSpec || got2.TextContent != "BBB" { t.Fatalf("Update 后字段不符: %#v", got2) @@ -396,6 +495,7 @@ func TestCards_CRUD(t *testing.T) { // AllForUser:先建第二张卡券。 id2, _ := s.Cards.Create(ctx, &CardFull{Name: "卡密C", Type: "data", DataContent: "x\ny", Enabled: true, UserID: uid}) + // all、err 保存all、err,供当前处理流程使用 all, err := s.Cards.AllForUser(ctx, uid) if err != nil { t.Fatalf("AllForUser: %v", err) @@ -409,19 +509,23 @@ func TestCards_CRUD(t *testing.T) { } // Delete。 - if err := s.Cards.Delete(ctx, id); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cards.Delete(ctx, id); err != nil { t.Fatalf("Delete: %v", err) } - if _, err := s.Cards.Get(ctx, id); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.Cards.Get(ctx, id); !errors.Is(err, ErrNotFound) { t.Fatalf("Delete 后应 ErrNotFound, got %v", err) } } // TestCards_GetNotFound 不存在的卡券 ID 返回 ErrNotFound。 func TestCards_GetNotFound(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() - if _, err := s.Cards.Get(context.Background(), 99999); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.Cards.Get(context.Background(), 99999); !errors.Is(err, ErrNotFound) { t.Fatalf("want ErrNotFound, got %v", err) } } @@ -429,10 +533,14 @@ func TestCards_GetNotFound(t *testing.T) { // --- delivery.go --- // TestItems_Get_IsMultiSpec_Items.Get / IsMultiSpec / MultiQuantityDelivery。 +// TestItems_GetAndFlags 负责Test商品列表GetAndFlags相关处理。 func TestItems_GetAndFlags(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) // 不存在 → ErrNotFound。 @@ -447,11 +555,13 @@ func TestItems_GetAndFlags(t *testing.T) { t.Fatal("不存在商品 MultiQuantityDelivery 应 false") } - if err := s.Items.Upsert(ctx, &ItemInfoRow{ + if // err 保存err,供当前处理流程使用 + err := s.Items.Upsert(ctx, &ItemInfoRow{ CookieID: cid, ItemID: "i1", ItemTitle: "T", IsMultiSpec: true, MultiQuantityDelivery: true, }); err != nil { t.Fatal(err) } + // got、err 保存got、err,供当前处理流程使用 got, err := s.Items.Get(ctx, cid, "i1") if err != nil { t.Fatalf("Get: %v", err) @@ -469,9 +579,12 @@ func TestItems_GetAndFlags(t *testing.T) { // TestCards_ConsumeBatchData data 类型卡券按行消费。 func TestCards_ConsumeBatchData(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid 保存uid,供当前处理流程使用 uid, _ := seedAccount(t, s) // 不存在的卡券 → ErrNotFound。 @@ -481,8 +594,10 @@ func TestCards_ConsumeBatchData(t *testing.T) { // data_content 为空 → 报错“批量数据为空”。 cf := &CardFull{Name: "data", Type: "data", UserID: uid, Enabled: true} + // id 保存标识,供当前处理流程使用 id, _ := s.Cards.Create(ctx, cf) - if _, err := s.Cards.ConsumeBatchData(ctx, id); err == nil || !strings.Contains(err.Error(), "为空") { + if // err 保存err,供当前处理流程使用 + _, err := s.Cards.ConsumeBatchData(ctx, id); err == nil || !strings.Contains(err.Error(), "为空") { t.Fatalf("空批量应报错, got %v", err) } @@ -498,10 +613,12 @@ func TestCards_ConsumeBatchData(t *testing.T) { if err != nil || first != "line1" { t.Fatalf("first=%q err=%v", first, err) } + // second 保存second,供当前处理流程使用 second, _ := s.Cards.ConsumeBatchData(ctx, id) if second != "line2" { t.Fatalf("second=%q want line2", second) } + // third 保存third,供当前处理流程使用 third, _ := s.Cards.ConsumeBatchData(ctx, id) if third != "line3" { t.Fatalf("third=%q want line3", third) @@ -512,24 +629,32 @@ func TestCards_ConsumeBatchData(t *testing.T) { } } +// TestCards_RestoreBatchDataReturnsReservedValueToFront 负责Test卡密列表Restore批次数据ReturnsReserved值ToFront相关处理。 func TestCards_RestoreBatchDataReturnsReservedValueToFront(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid 保存uid,供当前处理流程使用 uid, _ := seedAccount(t, s) + // id、err 保存id、err,供当前处理流程使用 id, err := s.Cards.Create(ctx, &CardFull{ Name: "restore", Type: "data", DataContent: "first\nsecond", Enabled: true, UserID: uid, }) if err != nil { t.Fatal(err) } + // reserved、err 保存reserved、err,供当前处理流程使用 reserved, err := s.Cards.ConsumeBatchData(ctx, id) if err != nil || reserved != "first" { t.Fatalf("reserve=%q err=%v", reserved, err) } - if err := s.Cards.RestoreBatchData(ctx, id, reserved); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cards.RestoreBatchData(ctx, id, reserved); err != nil { t.Fatal(err) } + // again、err 保存again、err,供当前处理流程使用 again, err := s.Cards.ConsumeBatchData(ctx, id) if err != nil || again != "first" { t.Fatalf("restored value must be consumed first: got=%q err=%v", again, err) @@ -538,9 +663,12 @@ func TestCards_RestoreBatchDataReturnsReservedValueToFront(t *testing.T) { // TestCards_AppendBatchData 追加卡密行 + 有效行计数。 func TestCards_AppendBatchData(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid 保存uid,供当前处理流程使用 uid, _ := seedAccount(t, s) // 不存在 → ErrNotFound。 @@ -548,7 +676,9 @@ func TestCards_AppendBatchData(t *testing.T) { t.Fatalf("want ErrNotFound, got %v", err) } + // cf 保存cf,供当前处理流程使用 cf := &CardFull{Name: "data", Type: "data", UserID: uid, Enabled: true, DataContent: ""} + // id 保存标识,供当前处理流程使用 id, _ := s.Cards.Create(ctx, cf) // 全是空行 → 报错“无有效卡密行”。 @@ -561,6 +691,7 @@ func TestCards_AppendBatchData(t *testing.T) { if err != nil || n != 2 { t.Fatalf("Append 首次: n=%d err=%v", n, err) } + // got 保存got,供当前处理流程使用 got, _ := s.Cards.Get(ctx, id) if got.DataContent != "a\nb" { t.Fatalf("data_content=%q want a\\nb", got.DataContent) @@ -578,6 +709,7 @@ func TestCards_AppendBatchData(t *testing.T) { // TestSplitJoinLines 覆盖 splitLines/joinLines 的 \r\n / 空行 / 末尾换行分支。 func TestSplitJoinLines(t *testing.T) { + // cases 保存cases,供当前处理流程使用 cases := []struct { in string want []string @@ -590,12 +722,15 @@ func TestSplitJoinLines(t *testing.T) { {"a\r", []string{"a"}}, // 末尾 \r {"\n\n", nil}, // 全空行 } + // c 表示当前遍历过程中的c for _, c := range cases { + // got 保存got,供当前处理流程使用 got := splitLines(c.in) if len(got) != len(c.want) { t.Errorf("splitLines(%q)=%v want %v", c.in, got, c.want) continue } + // i 表示当前遍历过程中的i for i := range got { if got[i] != c.want[i] { t.Errorf("splitLines(%q)[%d]=%q want %q", c.in, i, got[i], c.want[i]) @@ -616,31 +751,39 @@ func TestSplitJoinLines(t *testing.T) { // TestSession_GetEmpty 过期/空 sessionID 的处理。 func TestSession_GetEmpty(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if _, err := s.Sessions.Get(ctx, ""); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.Sessions.Get(ctx, ""); !errors.Is(err, ErrNotFound) { t.Fatalf("空 sessionID 应 ErrNotFound, got %v", err) } } // TestSession_Expired 过期会话被 Get 视为不存在并清理。 func TestSession_Expired(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() s.Users.Create(ctx, "u1", "u1@e.com", "pw") + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, "u1") // 直接写入一条已过期的会话。 sid := "expired-session-id" + // err 保存err,供当前处理流程使用 _, err := s.DB.ExecContext(ctx, `INSERT INTO sessions (session_id, user_id, username, is_admin, expires_at, created_at) VALUES (?,?,?,?,?,?)`, sid, user.ID, "u1", 0, time.Now().Unix()-1, time.Now().Unix()) if err != nil { t.Fatalf("insert expired session: %v", err) } - if _, err := s.Sessions.Get(ctx, sid); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.Sessions.Get(ctx, sid); !errors.Is(err, ErrNotFound) { t.Fatalf("过期会话应 ErrNotFound, got %v", err) } // Get 应已删除该过期记录。 @@ -653,15 +796,20 @@ func TestSession_Expired(t *testing.T) { // TestSession_DeleteExpired 批量清理过期会话。 func TestSession_DeleteExpired(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() s.Users.Create(ctx, "u1", "u1@e.com", "pw") + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, "u1") + // now 保存now,供当前处理流程使用 now := time.Now().Unix() // 两条过期 + 一条有效。 for i, sid := range []string{"exp1", "exp2", "valid1"} { + // exp 保存exp,供当前处理流程使用 exp := now - 1 if i == 2 { exp = now + 3600 @@ -671,6 +819,7 @@ func TestSession_DeleteExpired(t *testing.T) { sid, user.ID, "u1", 0, exp, now) } + // n、err 保存n、err,供当前处理流程使用 n, err := s.Sessions.DeleteExpired(ctx) if err != nil { t.Fatalf("DeleteExpired: %v", err) @@ -684,20 +833,27 @@ func TestSession_DeleteExpired(t *testing.T) { } } +// TestSession_GetRejectsInactiveUser 负责Test会话GetRejectsInactive用户相关处理。 func TestSession_GetRejectsInactiveUser(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() s.Users.Create(ctx, "u1", "u1@e.com", "pw") + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, "u1") + // sid、err 保存sid、err,供当前处理流程使用 sid, err := s.Sessions.Create(ctx, user) if err != nil { t.Fatalf("create session: %v", err) } - if _, err := s.DB.ExecContext(ctx, `UPDATE users SET is_active=0 WHERE id=?`, user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE users SET is_active=0 WHERE id=?`, user.ID); err != nil { t.Fatalf("deactivate user: %v", err) } - if _, err := s.Sessions.Get(ctx, sid); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.Sessions.Get(ctx, sid); !errors.Is(err, ErrNotFound) { t.Fatalf("inactive user session should be ErrNotFound, got %v", err) } } @@ -706,20 +862,25 @@ func TestSession_GetRejectsInactiveUser(t *testing.T) { // TestUsers_GetAdmin_GetByEmail_GetByID 各 Get 路径。 func TestUsers_Gets(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() s.Users.Create(ctx, "admin", "admin@e.com", "pw") s.Users.SetAdmin(ctx, "admin") + // admin、err 保存admin、err,供当前处理流程使用 admin, err := s.Users.GetAdmin(ctx) if err != nil || admin == nil || admin.Username != "admin" || !admin.IsAdmin { t.Fatalf("GetAdmin: %#v err=%v", admin, err) } + // byEmail、err 保存byEmail、err,供当前处理流程使用 byEmail, err := s.Users.GetByEmail(ctx, "admin@e.com") if err != nil || byEmail.ID != admin.ID { t.Fatalf("GetByEmail: %#v err=%v", byEmail, err) } + // byID、err 保存byID、err,供当前处理流程使用 byID, err := s.Users.GetByID(ctx, admin.ID) if err != nil || byID.Username != "admin" { t.Fatalf("GetByID: %#v err=%v", byID, err) @@ -728,29 +889,38 @@ func TestUsers_Gets(t *testing.T) { // TestUsers_GetMissing 各 Get 不存在返回 ErrNotFound。 func TestUsers_GetMissing(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if _, err := s.Users.GetAdmin(ctx); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.Users.GetAdmin(ctx); !errors.Is(err, ErrNotFound) { t.Fatalf("空库 GetAdmin 应 ErrNotFound, got %v", err) } - if _, err := s.Users.GetByUsername(ctx, "nobody"); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.Users.GetByUsername(ctx, "nobody"); !errors.Is(err, ErrNotFound) { t.Fatalf("GetByUsername 不存在应 ErrNotFound, got %v", err) } - if _, err := s.Users.GetByEmail(ctx, "nobody@e.com"); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.Users.GetByEmail(ctx, "nobody@e.com"); !errors.Is(err, ErrNotFound) { t.Fatalf("GetByEmail 不存在应 ErrNotFound, got %v", err) } - if _, err := s.Users.GetByID(ctx, 99999); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.Users.GetByID(ctx, 99999); !errors.Is(err, ErrNotFound) { t.Fatalf("GetByID 不存在应 ErrNotFound, got %v", err) } } // TestUsers_CreateDuplicateEmail 重复邮箱应返回 false(不报错)。 func TestUsers_CreateDuplicateEmail(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if ok, err := s.Users.Create(ctx, "u1", "dup@e.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Users.Create(ctx, "u1", "dup@e.com", "pw"); err != nil || !ok { t.Fatalf("首次 Create: ok=%v err=%v", ok, err) } // 同邮箱不同用户名。 @@ -759,21 +929,27 @@ func TestUsers_CreateDuplicateEmail(t *testing.T) { } } +// TestUsersCreatePropagatesDatabaseErrors 负责Test用户列表CreatePropagatesDatabase错误列表相关处理。 func TestUsersCreatePropagatesDatabaseErrors(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() - if err := s.DB.Close(); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.DB.Close(); err != nil { t.Fatal(err) } - if ok, err := s.Users.Create(context.Background(), "db-error", "db-error@example.com", "pw"); err == nil || ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := s.Users.Create(context.Background(), "db-error", "db-error@example.com", "pw"); err == nil || ok { t.Fatalf("database error was hidden: ok=%v err=%v", ok, err) } } // TestUsers_UpdatePasswordNotFound 不存在用户返回 false。 func TestUsers_UpdatePasswordNotFound(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ok、err 保存ok、err,供当前处理流程使用 ok, err := s.Users.UpdatePassword(context.Background(), "ghost", "pw") if err != nil || ok { t.Fatalf("不存在用户 UpdatePassword 应 ok=false, got ok=%v err=%v", ok, err) @@ -782,12 +958,15 @@ func TestUsers_UpdatePasswordNotFound(t *testing.T) { // TestUsers_VerifyAndUpgrade_Inactive 未激活用户验证失败。 func TestUsers_VerifyAndUpgrade_Inactive(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() s.Users.Create(ctx, "u1", "u1@e.com", "pw") // 手动置为未激活。 _, _ = s.DB.ExecContext(ctx, `UPDATE users SET is_active=0 WHERE username=?`, "u1") + // user、ok、err 保存user、ok、err,供当前处理流程使用 user, ok, err := s.Users.VerifyAndUpgrade(ctx, "u1", "pw") if err != nil || ok || user != nil { t.Fatalf("未激活用户应 ok=false, got ok=%v user=%v err=%v", ok, user, err) @@ -796,15 +975,19 @@ func TestUsers_VerifyAndUpgrade_Inactive(t *testing.T) { // TestUsers_VerifyAndUpgrade_LegacyUpgrade 命中老 SHA-256 哈希应静默升级到 bcrypt。 func TestUsers_VerifyAndUpgrade_LegacyUpgrade(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() s.Users.Create(ctx, "u1", "u1@e.com", "pw") + // user 保存用户,供当前处理流程使用 user, _ := s.Users.GetByUsername(ctx, "u1") // 篡改密码为老 SHA-256 哈希。 legacy := legacySHA256("oldpw") _, _ = s.DB.ExecContext(ctx, `UPDATE users SET password_hash=? WHERE id=?`, legacy, user.ID) + // got、ok、err 保存got、ok、err,供当前处理流程使用 got, ok, err := s.Users.VerifyAndUpgrade(ctx, "u1", "oldpw") if err != nil || !ok || got == nil { t.Fatalf("老哈希验证应成功: ok=%v err=%v", ok, err) @@ -818,16 +1001,20 @@ func TestUsers_VerifyAndUpgrade_LegacyUpgrade(t *testing.T) { // TestUsers_UpdateCredentials 改用户名 + 撤销会话 + 用户名冲突。 func TestUsers_UpdateCredentials(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() s.Users.Create(ctx, "u1", "u1@e.com", "pw") s.Users.Create(ctx, "u2", "u2@e.com", "pw") + // u1 保存u1,供当前处理流程使用 u1, _ := s.Users.GetByUsername(ctx, "u1") // 给 u1 建一个会话。 sid, _ := s.Sessions.Create(ctx, u1) - if _, err := s.Sessions.Get(ctx, sid); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.Sessions.Get(ctx, sid); err != nil { t.Fatalf("会话应存在: %v", err) } @@ -835,13 +1022,15 @@ func TestUsers_UpdateCredentials(t *testing.T) { if err := s.Users.UpdateCredentials(ctx, u1.ID, "u1renamed", ""); err != nil { t.Fatalf("UpdateCredentials: %v", err) } - if _, err := s.Sessions.Get(ctx, sid); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.Sessions.Get(ctx, sid); !errors.Is(err, ErrNotFound) { t.Fatalf("改凭据后会话应被撤销, got %v", err) } // 用户名已变更。 if _, err := s.Users.GetByUsername(ctx, "u1"); !errors.Is(err, ErrNotFound) { t.Fatalf("旧用户名应不存在: %v", err) } + // renamed 保存renamed,供当前处理流程使用 renamed, _ := s.Users.GetByUsername(ctx, "u1renamed") if renamed.ID != u1.ID { t.Fatalf("renamed id 不匹配: %d vs %d", renamed.ID, u1.ID) @@ -856,6 +1045,7 @@ func TestUsers_UpdateCredentials(t *testing.T) { if err := s.Users.UpdateCredentials(ctx, u1.ID, "u1renamed2", "newpw"); err != nil { t.Fatalf("UpdateCredentials with pw: %v", err) } + // ok2 保存ok2,供当前处理流程使用 _, ok2, _ := s.Users.VerifyAndUpgrade(ctx, "u1renamed2", "newpw") if !ok2 { t.Fatal("新密码应可用") @@ -871,18 +1061,23 @@ func TestUsers_UpdateCredentials(t *testing.T) { // TestAIReply_GetNotFound 不存在返回 ErrNotFound。 func TestAIReply_GetNotFound(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() - if _, err := s.AIReply.Get(context.Background(), "nope"); !errors.Is(err, ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := s.AIReply.Get(context.Background(), "nope"); !errors.Is(err, ErrNotFound) { t.Fatalf("want ErrNotFound, got %v", err) } } // TestAIReply_GetDefaults 缺省值兜底(model_name/base_url 为空时填默认)。 func TestAIReply_GetDefaults(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) // 直接插入一条 model_name/base_url 均为 NULL 的记录。 @@ -891,6 +1086,7 @@ func TestAIReply_GetDefaults(t *testing.T) { if err != nil { t.Fatalf("insert ai_reply: %v", err) } + // got、err 保存got、err,供当前处理流程使用 got, err := s.AIReply.Get(ctx, cid) if err != nil { t.Fatalf("Get: %v", err) @@ -910,9 +1106,12 @@ func TestAIReply_GetDefaults(t *testing.T) { // TestWSMessages_Add 默认 direction/parse_status 兜底 + 写入成功。 func TestWSMessages_Add(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) // 空字段走默认值。 @@ -923,6 +1122,7 @@ func TestWSMessages_Add(t *testing.T) { } // 验证默认值写入。 var dir, status string + // err 保存err,供当前处理流程使用 err := s.DB.QueryRowContext(ctx, `SELECT direction, parse_status FROM ws_messages WHERE cookie_id=? ORDER BY id DESC LIMIT 1`, cid).Scan(&dir, &status) if err != nil { @@ -939,6 +1139,7 @@ func TestWSMessages_Add(t *testing.T) { }); err != nil { t.Fatalf("Add explicit: %v", err) } + // n 保存n,供当前处理流程使用 var n int _ = s.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM ws_messages WHERE cookie_id=?`, cid).Scan(&n) if n != 2 { @@ -946,24 +1147,31 @@ func TestWSMessages_Add(t *testing.T) { } } +// TestWSMessages_AddBatchAndDeleteBefore 负责TestWS消息列表Add批次AndDeleteBefore相关处理。 func TestWSMessages_AddBatchAndDeleteBefore(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cid 保存cid,供当前处理流程使用 _, cid := seedAccount(t, s) - if err := s.WSMessages.AddBatch(ctx, []WSMessage{ + if // err 保存err,供当前处理流程使用 + err := s.WSMessages.AddBatch(ctx, []WSMessage{ {CookieID: cid, RawText: "first"}, {CookieID: cid, Direction: "out", ParseStatus: "parsed", RawText: "second"}, }); err != nil { t.Fatalf("AddBatch: %v", err) } - if _, err := s.DB.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE ws_messages SET created_at=? WHERE cookie_id=? AND raw_text=?`, time.Now().Add(-8*24*time.Hour), cid, "first"); err != nil { t.Fatalf("设置历史时间: %v", err) } + // deleted、err 保存deleted、err,供当前处理流程使用 deleted, err := s.WSMessages.DeleteBefore(ctx, cid, time.Now().Add(-7*24*time.Hour)) if err != nil { t.Fatalf("DeleteBefore: %v", err) @@ -971,8 +1179,10 @@ func TestWSMessages_AddBatchAndDeleteBefore(t *testing.T) { if deleted != 1 { t.Fatalf("删除行数=%d want 1", deleted) } + // rawText、direction、parseStatus 保存原始Text、direction、parse状态,供当前处理流程使用 var rawText, direction, parseStatus string - if err := s.DB.QueryRowContext(ctx, + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRowContext(ctx, `SELECT raw_text, direction, parse_status FROM ws_messages WHERE cookie_id=?`, cid, ).Scan(&rawText, &direction, &parseStatus); err != nil { t.Fatalf("查询保留记录: %v", err) diff --git a/internal/db/orders_ext.go b/internal/db/orders_ext.go index c0f4105..e788527 100644 --- a/internal/db/orders_ext.go +++ b/internal/db/orders_ext.go @@ -45,33 +45,44 @@ func (o *Orders) ListForUser(ctx context.Context, f OrderListFilter) ([]OrderRow if f.Limit <= 0 { f.Limit = 20 } + // where 保存where,供当前处理流程使用 where := []string{"c.user_id=?", "o.deleted_at IS NULL"} + // args 保存args,供当前处理流程使用 args := []any{f.UserID} if f.CookieID != "" { where = append(where, "o.cookie_id=?") args = append(args, f.CookieID) } - if statuses := normalizedStatusCandidates(f.Status); len(statuses) > 0 { + if // statuses 保存statuses,供当前处理流程使用 + statuses := normalizedStatusCandidates(f.Status); len(statuses) > 0 { + // placeholders 保存placeholders,供当前处理流程使用 placeholders := make([]string, 0, len(statuses)) + // st 表示当前遍历过程中的st for _, st := range statuses { placeholders = append(placeholders, "?") args = append(args, st) } where = append(where, "o.order_status IN ("+strings.Join(placeholders, ",")+")") } - if search := strings.ToLower(strings.TrimSpace(f.Search)); search != "" { + if // search 保存搜索,供当前处理流程使用 + search := strings.ToLower(strings.TrimSpace(f.Search)); search != "" { + // pattern 保存pattern,供当前处理流程使用 pattern := "%" + search + "%" where = append(where, `(LOWER(o.order_id) LIKE ? OR LOWER(COALESCE(o.item_id,'')) LIKE ? OR LOWER(COALESCE(o.buyer_id,'')) LIKE ? OR LOWER(COALESCE(i.item_title,'')) LIKE ? OR LOWER(COALESCE(o.receiver_name,'')) LIKE ? OR LOWER(COALESCE(o.receiver_phone,'')) LIKE ?)`) - for i := 0; i < 6; i++ { + for // i 保存i,供当前处理流程使用 + i := 0; i < 6; i++ { args = append(args, pattern) } } + // whereSQL 保存whereSQL,供当前处理流程使用 whereSQL := strings.Join(where, " AND ") + // total 保存总数,供当前处理流程使用 var total int - if err := o.DB.QueryRowContext(ctx, + if // err 保存err,供当前处理流程使用 + err := o.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM orders o JOIN cookies c ON c.id=o.cookie_id @@ -80,8 +91,10 @@ func (o *Orders) ListForUser(ctx context.Context, f OrderListFilter) ([]OrderRow return nil, 0, err } + // queryArgs 保存查询Args,供当前处理流程使用 queryArgs := append([]any{}, args...) queryArgs = append(queryArgs, f.Limit, f.Offset) + // rows、err 保存rows、err,供当前处理流程使用 rows, err := o.DB.QueryContext(ctx, `SELECT o.order_id, o.item_id, COALESCE(i.item_title,''), COALESCE(i.item_detail,''), o.buyer_id, o.spec_name, o.spec_value, o.quantity, o.amount, @@ -98,12 +111,17 @@ func (o *Orders) ListForUser(ctx context.Context, f OrderListFilter) ([]OrderRow return nil, 0, err } defer rows.Close() + // out 保存out,供当前处理流程使用 out := []OrderRow{} for rows.Next() { + // r 保存r,供当前处理流程使用 var r OrderRow + // itemID、itemTitle、itemDetail、buyerID、specName、specValue、qty、amount、receiverName、receiverPhone、receiverAddr、receiverCity 保存商品ID、itemTitle、itemDetail、buyerID、specName、specValue、qty、amount、receiverName、receiverPhone、receiverAddr、receiverCity,供当前处理流程使用 var itemID, itemTitle, itemDetail, buyerID, specName, specValue, qty, amount, receiverName, receiverPhone, receiverAddr, receiverCity sql.NullString + // isBargain、sysShipped 保存isBargain、sysShipped,供当前处理流程使用 var isBargain, sysShipped int - if err := rows.Scan(&r.OrderID, &itemID, &itemTitle, &itemDetail, &buyerID, &specName, &specValue, &qty, &amount, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&r.OrderID, &itemID, &itemTitle, &itemDetail, &buyerID, &specName, &specValue, &qty, &amount, &r.OrderStatus, &r.CookieID, &isBargain, &sysShipped, &receiverName, &receiverPhone, &receiverAddr, &receiverCity, &r.CreatedAt, &r.UpdatedAt); err != nil { return nil, 0, err @@ -127,6 +145,7 @@ func (o *Orders) ListForUser(ctx context.Context, f OrderListFilter) ([]OrderRow return out, total, rows.Err() } +// normalizedStatusCandidates 负责normalized状态Candidates相关处理。 func normalizedStatusCandidates(status string) []string { status = strings.TrimSpace(status) if status == "" || status == "all" { @@ -168,6 +187,7 @@ func (o *Orders) ByCookiePage(ctx context.Context, cookieID string, limit, offse if offset < 0 { offset = 0 } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := o.DB.QueryContext(ctx, `SELECT order_id, item_id, buyer_id, spec_name, spec_value, quantity, amount, order_status, is_bargain, system_shipped, receiver_name, receiver_phone, @@ -177,12 +197,17 @@ func (o *Orders) ByCookiePage(ctx context.Context, cookieID string, limit, offse return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []OrderRow for rows.Next() { + // r 保存r,供当前处理流程使用 var r OrderRow + // itemID、buyerID、specName、specValue、qty、amount、receiverName、receiverPhone、receiverAddr、receiverCity 保存商品ID、buyerID、specName、specValue、qty、amount、receiverName、receiverPhone、receiverAddr、receiverCity,供当前处理流程使用 var itemID, buyerID, specName, specValue, qty, amount, receiverName, receiverPhone, receiverAddr, receiverCity sql.NullString + // isBargain、sysShipped 保存isBargain、sysShipped,供当前处理流程使用 var isBargain, sysShipped int - if err := rows.Scan(&r.OrderID, &itemID, &buyerID, &specName, &specValue, &qty, &amount, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&r.OrderID, &itemID, &buyerID, &specName, &specValue, &qty, &amount, &r.OrderStatus, &isBargain, &sysShipped, &receiverName, &receiverPhone, &receiverAddr, &receiverCity, &r.CreatedAt, &r.UpdatedAt); err != nil { return nil, err @@ -207,43 +232,55 @@ func (o *Orders) ByCookiePage(ctx context.Context, cookieID string, limit, offse // SoftDeleteMissingForCookie 将本次完整卖家订单同步中未出现的本地订单逻辑删除。 // activeIDs 为空表示线上已确认没有任何卖家订单;调用方必须确保同步完整成功后再调用。 +// SoftDeleteMissingForCookie 负责SoftDeleteMissingFor登录凭证相关处理。 func (o *Orders) SoftDeleteMissingForCookie(ctx context.Context, cookieID string, activeIDs map[string]struct{}) (int, error) { if strings.TrimSpace(cookieID) == "" { return 0, errors.New("cookie_id 不能为空") } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := o.DB.QueryContext(ctx, `SELECT order_id FROM orders WHERE cookie_id=? AND deleted_at IS NULL`, cookieID) if err != nil { return 0, err } + // orderIDs 保存订单IDs,供当前处理流程使用 orderIDs := make([]string, 0) for rows.Next() { + // orderID 保存订单ID,供当前处理流程使用 var orderID string - if err := rows.Scan(&orderID); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&orderID); err != nil { _ = rows.Close() return 0, err } orderIDs = append(orderIDs, orderID) } - if err := rows.Err(); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Err(); err != nil { _ = rows.Close() return 0, err } - if err := rows.Close(); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Close(); err != nil { return 0, err } + // deleted 保存deleted,供当前处理流程使用 deleted := 0 + // orderID 表示当前遍历过程中的订单ID for _, orderID := range orderIDs { - if _, ok := activeIDs[orderID]; ok { + if // ok 保存ok,供当前处理流程使用 + _, ok := activeIDs[orderID]; ok { continue } + // result、err 保存result、err,供当前处理流程使用 result, err := o.DB.ExecContext(ctx, `UPDATE orders SET deleted_at=CURRENT_TIMESTAMP, updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND order_id=? AND deleted_at IS NULL`, cookieID, orderID) if err != nil { return deleted, err } + // changed、err 保存changed、err,供当前处理流程使用 changed, err := result.RowsAffected() if err != nil { return deleted, err @@ -263,7 +300,8 @@ var OrderStatusMap = map[string]string{ // NormalizeOrderStatus 数字码归一为文本。 func NormalizeOrderStatus(s string) string { - if t, ok := OrderStatusMap[s]; ok { + if // t、ok 保存t、ok,供当前处理流程使用 + t, ok := OrderStatusMap[s]; ok { return t } if s == "" { @@ -274,15 +312,19 @@ func NormalizeOrderStatus(s string) string { // AllTitles 取全部 item_id → item_title 映射(订单列表用)。 func (i *Items) AllTitles(ctx context.Context) (map[string]string, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := i.DB.QueryContext(ctx, `SELECT item_id, item_title FROM item_info`) if err != nil { return nil, err } defer rows.Close() + // m 保存m,供当前处理流程使用 m := make(map[string]string) for rows.Next() { + // id、title 保存id、title,供当前处理流程使用 var id, title sql.NullString - if err := rows.Scan(&id, &title); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&id, &title); err != nil { return nil, err } m[id.String] = title.String @@ -312,16 +354,22 @@ type CardFull struct { // ExistsOwned 判断卡密组是否属于指定用户。 func (c *Cards) ExistsOwned(ctx context.Context, cardID, userID int64) (bool, error) { + // exists 保存exists,供当前处理流程使用 var exists bool + // err 保存err,供当前处理流程使用 err := c.DB.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM cards WHERE id=? AND user_id=?)`, cardID, userID).Scan(&exists) return exists, err } // Get 取单个卡券。 func (c *Cards) Get(ctx context.Context, cardID int64) (*CardFull, error) { + // cf 保存cf,供当前处理流程使用 var cf CardFull + // enabled、isMultiSpec 保存enabled、isMultiSpec,供当前处理流程使用 var enabled, isMultiSpec int + // apiCfg、textContent、dataContent、imageURL、specName、specValue、desc 保存apiCfg、textContent、dataContent、imageURL、specName、specValue、desc,供当前处理流程使用 var apiCfg, textContent, dataContent, imageURL, specName, specValue, desc sql.NullString + // err 保存err,供当前处理流程使用 err := c.DB.QueryRowContext(ctx, `SELECT id, name, type, api_config, text_content, data_content, image_url, description, enabled, delay_seconds, is_multi_spec, spec_name, spec_value, user_id @@ -348,6 +396,7 @@ func (c *Cards) Get(ctx context.Context, cardID int64) (*CardFull, error) { // AllForUser 取某用户全部卡券。 func (c *Cards) AllForUser(ctx context.Context, userID int64) ([]CardFull, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := c.DB.QueryContext(ctx, `SELECT id, name, type, api_config, text_content, data_content, image_url, description, enabled, delay_seconds, is_multi_spec, spec_name, spec_value, user_id @@ -356,12 +405,17 @@ func (c *Cards) AllForUser(ctx context.Context, userID int64) ([]CardFull, error return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []CardFull for rows.Next() { + // cf 保存cf,供当前处理流程使用 var cf CardFull + // enabled、isMultiSpec 保存enabled、isMultiSpec,供当前处理流程使用 var enabled, isMultiSpec int + // apiCfg、textContent、dataContent、imageURL、specName、specValue、desc 保存apiCfg、textContent、dataContent、imageURL、specName、specValue、desc,供当前处理流程使用 var apiCfg, textContent, dataContent, imageURL, specName, specValue, desc sql.NullString - if err := rows.Scan(&cf.ID, &cf.Name, &cf.Type, &apiCfg, &textContent, &dataContent, &imageURL, &desc, + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&cf.ID, &cf.Name, &cf.Type, &apiCfg, &textContent, &dataContent, &imageURL, &desc, &enabled, &cf.DelaySeconds, &isMultiSpec, &specName, &specValue, &cf.UserID); err != nil { return nil, err } @@ -392,6 +446,7 @@ func (c *Cards) Create(ctx context.Context, cf *CardFull) (int64, error) { // Update 更新卡券。 func (c *Cards) Update(ctx context.Context, cf *CardFull) error { + // err 保存err,供当前处理流程使用 _, err := c.DB.ExecContext(ctx, `UPDATE cards SET name=?, type=?, api_config=?, text_content=?, data_content=?, image_url=?, description=?, enabled=?, delay_seconds=?, is_multi_spec=?, spec_name=?, spec_value=?, updated_at=CURRENT_TIMESTAMP @@ -404,10 +459,12 @@ func (c *Cards) Update(ctx context.Context, cf *CardFull) error { // Delete 删除卡券。 func (c *Cards) Delete(ctx context.Context, cardID int64) error { + // err 保存err,供当前处理流程使用 _, err := c.DB.ExecContext(ctx, `DELETE FROM cards WHERE id=?`, cardID) return err } +// nullable 负责nullable相关处理。 func nullable(s string) any { if s == "" { return nil diff --git a/internal/db/password.go b/internal/db/password.go index af80679..ea657f8 100644 --- a/internal/db/password.go +++ b/internal/db/password.go @@ -14,6 +14,7 @@ var ErrPasswordMismatch = errors.New("密码错误") // HashPassword 用 bcrypt 哈希明文密码(新用户/改密码用)。 func HashPassword(plain string) (string, error) { + // b、err 保存b、err,供当前处理流程使用 b, err := bcrypt.GenerateFromPassword([]byte(plain), bcrypt.DefaultCost) if err != nil { return "", err @@ -23,12 +24,14 @@ func HashPassword(plain string) (string, error) { // legacySHA256 兼容旧数据库中的 SHA-256 密码摘要。 func legacySHA256(plain string) string { + // sum 保存sum,供当前处理流程使用 sum := sha256.Sum256([]byte(plain)) return hex.EncodeToString(sum[:]) } // isLegacyHash 判断是否为老的无盐 SHA-256 哈希(64 位十六进制)。 // bcrypt 哈希以 $2 开头,据此区分。 +// isLegacyHash 负责isLegacyHash相关处理。 func isLegacyHash(h string) bool { return len(h) == 64 && !strings.HasPrefix(h, "$2") } @@ -38,6 +41,7 @@ func isLegacyHash(h string) bool { // - 老 SHA-256 哈希:逐字节对比(兼容老库) // // 返回 (matched, needsUpgrade)。needsUpgrade=true 表示命中老哈希、应升级到 bcrypt。 +// VerifyPassword 负责Verify密码相关处理。 func VerifyPassword(stored, plain string) (matched bool, needsUpgrade bool, err error) { if isLegacyHash(stored) { if stored == legacySHA256(plain) { @@ -45,7 +49,8 @@ func VerifyPassword(stored, plain string) (matched bool, needsUpgrade bool, err } return false, false, ErrPasswordMismatch } - if err := bcrypt.CompareHashAndPassword([]byte(stored), []byte(plain)); err != nil { + if // err 保存err,供当前处理流程使用 + err := bcrypt.CompareHashAndPassword([]byte(stored), []byte(plain)); err != nil { if errors.Is(err, bcrypt.ErrMismatchedHashAndPassword) { return false, false, ErrPasswordMismatch } diff --git a/internal/db/pgx_compat.go b/internal/db/pgx_compat.go index 9840dc5..ea1c571 100644 --- a/internal/db/pgx_compat.go +++ b/internal/db/pgx_compat.go @@ -12,8 +12,10 @@ import ( // pgxCompatDriverName 是包裹 pgx 的自定义 driver 名。 // 注册后 sql.Open(pgxCompatDriverName, dsn) 走 qPgDriver,把 ? 改写成 $N。 +// pgxCompatDriverName 保存pgxCompatDriver名称,供当前处理流程使用 const pgxCompatDriverName = "pgx_compat" +// init 负责init相关处理。 func init() { sql.Register(pgxCompatDriverName, &qPgDriver{base: stdlib.GetDefaultDriver()}) } @@ -21,9 +23,12 @@ func init() { // qPgDriver 包裹 pgx stdlib driver,仅为了把 ? 占位符改写成 $N。 // 全仓库业务 SQL 都用 ? 写(SQLite/MySQL 原生支持),Postgres 的 pgx // 只认 $1/$2/...,不重写会报 "syntax error at or near \",\""。 +// qPgDriver 保存qPgDriver,供当前处理流程使用 type qPgDriver struct{ base driver.Driver } +// Open 打开当前值。 func (d *qPgDriver) Open(name string) (driver.Conn, error) { + // c、err 保存c、err,供当前处理流程使用 c, err := d.base.Open(name) if err != nil { return nil, err @@ -34,11 +39,14 @@ func (d *qPgDriver) Open(name string) (driver.Conn, error) { // qConn 包裹 pgx 连接。Exec/Query/Prepare 重写 SQL,其余方法透传给底层 pgx conn。 // 嵌入 driver.Conn 接口会把 Close/Begin/Prepare(legacy)等方法自动透传; // 显式实现的可选接口方法(带 Context、Pinger、Validator 等)覆盖/补齐 pgx 行为。 +// qConn 保存qConn,供当前处理流程使用 type qConn struct { driver.Conn } +// ExecContext 负责Exec上下文相关处理。 func (c *qConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) { + // ex、ok 保存ex、ok,供当前处理流程使用 ex, ok := c.Conn.(driver.ExecerContext) if !ok { return nil, driver.ErrSkip @@ -46,7 +54,9 @@ func (c *qConn) ExecContext(ctx context.Context, query string, args []driver.Nam return ex.ExecContext(ctx, rewriteQuestionPlaceholders(query), args) } +// QueryContext 负责查询上下文相关处理。 func (c *qConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) { + // qx、ok 保存qx、ok,供当前处理流程使用 qx, ok := c.Conn.(driver.QueryerContext) if !ok { return nil, driver.ErrSkip @@ -54,7 +64,9 @@ func (c *qConn) QueryContext(ctx context.Context, query string, args []driver.Na return qx.QueryContext(ctx, rewriteQuestionPlaceholders(query), args) } +// PrepareContext 负责Prepare上下文相关处理。 func (c *qConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { + // px、ok 保存px、ok,供当前处理流程使用 px, ok := c.Conn.(driver.ConnPrepareContext) if !ok { return nil, driver.ErrSkip @@ -62,7 +74,9 @@ func (c *qConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, return px.PrepareContext(ctx, rewriteQuestionPlaceholders(query)) } +// BeginTx 负责BeginTx相关处理。 func (c *qConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) { + // bx、ok 保存bx、ok,供当前处理流程使用 bx, ok := c.Conn.(driver.ConnBeginTx) if !ok { return nil, driver.ErrSkip @@ -70,29 +84,37 @@ func (c *qConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, return bx.BeginTx(ctx, opts) } +// Ping 负责Ping相关处理。 func (c *qConn) Ping(ctx context.Context) error { - if p, ok := c.Conn.(driver.Pinger); ok { + if // p、ok 保存p、ok,供当前处理流程使用 + p, ok := c.Conn.(driver.Pinger); ok { return p.Ping(ctx) } return nil } +// IsValid 负责Is有效相关处理。 func (c *qConn) IsValid() bool { - if v, ok := c.Conn.(driver.Validator); ok { + if // v、ok 保存v、ok,供当前处理流程使用 + v, ok := c.Conn.(driver.Validator); ok { return v.IsValid() } return true } +// CheckNamedValue 检查Named值。 func (c *qConn) CheckNamedValue(nv *driver.NamedValue) error { - if nc, ok := c.Conn.(driver.NamedValueChecker); ok { + if // nc、ok 保存nc、ok,供当前处理流程使用 + nc, ok := c.Conn.(driver.NamedValueChecker); ok { return nc.CheckNamedValue(nv) } return driver.ErrSkip } +// ResetSession 负责Reset会话相关处理。 func (c *qConn) ResetSession(ctx context.Context) error { - if rs, ok := c.Conn.(driver.SessionResetter); ok { + if // rs、ok 保存rs、ok,供当前处理流程使用 + rs, ok := c.Conn.(driver.SessionResetter); ok { return rs.ResetSession(ctx) } return nil @@ -101,12 +123,18 @@ func (c *qConn) ResetSession(ctx context.Context) error { // rewriteQuestionPlaceholders 把 SQL 里的 ? 改写成 $1, $2, ...(Postgres 占位符)。 // 跳过单引号字符串字面量('...')和双引号标识符("...")内的 ?; // ” 转义单引号也正确处理(相邻两个 ' 不改变字面量状态)。 +// rewriteQuestionPlaceholders 负责rewriteQuestionPlaceholders相关处理。 func rewriteQuestionPlaceholders(query string) string { + // b 保存b,供当前处理流程使用 var b strings.Builder b.Grow(len(query) + 16) + // n 保存n,供当前处理流程使用 n := 0 + // inSingle、inDouble 保存inSingle、inDouble,供当前处理流程使用 inSingle, inDouble := false, false - for i := 0; i < len(query); i++ { + for // i 保存i,供当前处理流程使用 + i := 0; i < len(query); i++ { + // ch 保存ch,供当前处理流程使用 ch := query[i] switch ch { case '\'': diff --git a/internal/db/publish_batches_test.go b/internal/db/publish_batches_test.go index 790db6b..e0e45d6 100644 --- a/internal/db/publish_batches_test.go +++ b/internal/db/publish_batches_test.go @@ -19,19 +19,26 @@ func makePublishBatch(userID int64, id string) *ItemPublishBatch { } // TestPublishBatches_CreateGetRows Create + Get + Rows。 +// TestPublishBatches_CreateGetRows 负责Test发布批次列表CreateGetRows相关处理。 func TestPublishBatches_CreateGetRows(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid 保存uid,供当前处理流程使用 uid, _ := seedAccount(t, s) + // batch 保存批次,供当前处理流程使用 batch := makePublishBatch(uid, "b1") + // rows 保存rows,供当前处理流程使用 rows := []ItemPublishBatchRow{ {RowNo: 1, Title: "商品A", Price: "9.9", Quantity: 0, PostageMode: ""}, // 缺省值补 1 / free {RowNo: 2, Title: "商品B", Price: "19.9", Quantity: 5, PostageMode: "buyer", Status: ""}, {RowNo: 3, Title: "商品C", Price: "29.9", ImagesJSON: "", AutomationJSON: ""}, // 缺省 []/{} } - if err := s.PublishBatches.Create(ctx, batch, rows); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.Create(ctx, batch, rows); err != nil { t.Fatalf("Create: %v", err) } @@ -60,6 +67,7 @@ func TestPublishBatches_CreateGetRows(t *testing.T) { if len(gotRows) != 3 { t.Fatalf("rows len=%d want 3", len(gotRows)) } + // r0 保存r0,供当前处理流程使用 r0 := gotRows[0] if r0.Quantity != 1 || r0.PostageMode != "free" || r0.Status != "pending" || r0.ImagesJSON != "[]" || r0.CategoryJSON != "{}" || r0.AutomationJSON != "{}" || r0.RawJSON != "{}" { @@ -74,30 +82,40 @@ func TestPublishBatches_CreateGetRows(t *testing.T) { } } +// TestPublishBatchesListAndRecoverInterrupted 负责Test发布批次列表ListAndRecoverInterrupted相关处理。 func TestPublishBatchesListAndRecoverInterrupted(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid 保存uid,供当前处理流程使用 uid, _ := seedAccount(t, s) - if err := s.PublishBatches.Create(ctx, makePublishBatch(uid, "recover-list"), []ItemPublishBatchRow{{ + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.Create(ctx, makePublishBatch(uid, "recover-list"), []ItemPublishBatchRow{{ RowNo: 1, CookieID: "acc1", Title: "A", Price: "1", Status: "failed", FailureKind: "interrupted", ErrorMessage: "stopped", }}); err != nil { t.Fatal(err) } - if err := s.PublishBatches.SetBatchStatus(ctx, "recover-list", "failed"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.SetBatchStatus(ctx, "recover-list", "failed"); err != nil { t.Fatal(err) } + // listed、err 保存listed、err,供当前处理流程使用 listed, err := s.PublishBatches.ListForUser(ctx, uid, 10) if err != nil || len(listed) != 1 || listed[0].ID != "recover-list" { t.Fatalf("listed=%+v err=%v", listed, err) } + // recoverable、err 保存recoverable、err,供当前处理流程使用 recoverable, err := s.PublishBatches.Recoverable(ctx, time.Now().UTC().Unix(), 10) if err != nil || len(recoverable) != 1 || recoverable[0].ID != "recover-list" { t.Fatalf("recoverable=%+v err=%v", recoverable, err) } - if err := s.PublishBatches.ResetInterrupted(ctx, "recover-list"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.ResetInterrupted(ctx, "recover-list"); err != nil { t.Fatal(err) } + // rows 保存rows,供当前处理流程使用 rows, _ := s.PublishBatches.Rows(ctx, "recover-list") if rows[0].Status != "pending" || rows[0].FailureKind != "" || rows[0].ErrorMessage != "" { t.Fatalf("row=%+v", rows[0]) @@ -106,9 +124,12 @@ func TestPublishBatchesListAndRecoverInterrupted(t *testing.T) { // TestPublishBatches_PendingRowsAndStatus pending/failed 过滤 + 状态机流转 + Recount。 func TestPublishBatches_PendingRowsAndStatus(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid 保存uid,供当前处理流程使用 uid, _ := seedAccount(t, s) s.PublishBatches.Create(ctx, makePublishBatch(uid, "b1"), []ItemPublishBatchRow{ @@ -124,6 +145,7 @@ func TestPublishBatches_PendingRowsAndStatus(t *testing.T) { } // BatchStatus。 + // st、err 保存st、err,供当前处理流程使用 st, err := s.PublishBatches.BatchStatus(ctx, "b1") if err != nil || st != "pending" { t.Fatalf("BatchStatus: %q err=%v", st, err) @@ -134,7 +156,8 @@ func TestPublishBatches_PendingRowsAndStatus(t *testing.T) { } // SetBatchStatus → running。 - if err := s.PublishBatches.SetBatchStatus(ctx, "b1", "running"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.SetBatchStatus(ctx, "b1", "running"); err != nil { t.Fatalf("SetBatchStatus: %v", err) } st, _ = s.PublishBatches.BatchStatus(ctx, "b1") @@ -144,8 +167,10 @@ func TestPublishBatches_PendingRowsAndStatus(t *testing.T) { // 取第一行,走 running → success。 rows, _ := s.PublishBatches.Rows(ctx, "b1") + // rowID 保存rowID,供当前处理流程使用 rowID := rows[0].ID - if err := s.PublishBatches.MarkRowRunning(ctx, rowID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.MarkRowRunning(ctx, rowID); err != nil { t.Fatalf("MarkRowRunning: %v", err) } // running 中 error_message 应清空。 @@ -167,6 +192,7 @@ func TestPublishBatches_PendingRowsAndStatus(t *testing.T) { if err := s.PublishBatches.Recount(ctx, "b1"); err != nil { t.Fatalf("Recount: %v", err) } + // batch 保存批次,供当前处理流程使用 batch, _ := s.PublishBatches.Get(ctx, uid, "b1") if batch.TotalCount != 3 || batch.SuccessCount != 2 || batch.FailedCount != 1 { t.Fatalf("Recount 后: total=%d success=%d failed=%d want 3/2/1", @@ -186,12 +212,14 @@ func TestPublishBatches_PendingRowsAndStatus(t *testing.T) { if err := s.PublishBatches.ResetFailed(ctx, "b1"); err != nil { t.Fatalf("ResetFailed: %v", err) } + // pendingAfter 保存pendingAfter,供当前处理流程使用 pendingAfter, _ := s.PublishBatches.PendingRows(ctx, "b1", false) if len(pendingAfter) != 1 { t.Fatalf("ResetFailed 后 pending len=%d want 1", len(pendingAfter)) } // 验证 error_message 已清空。 rowsAfter, _ := s.PublishBatches.Rows(ctx, "b1") + // rr 表示当前遍历过程中的rr for _, rr := range rowsAfter { if rr.Status == "pending" && rr.ErrorMessage != "" { t.Fatalf("ResetFailed 后 pending 行 error_message 应空: %q", rr.ErrorMessage) @@ -201,48 +229,64 @@ func TestPublishBatches_PendingRowsAndStatus(t *testing.T) { // TestPublishBatches_RowsEmpty Rows 对不存在的 batch 返回空。 func TestPublishBatches_RowsEmpty(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // rows、err 保存rows、err,供当前处理流程使用 rows, err := s.PublishBatches.Rows(ctx, "nope") if err != nil || len(rows) != 0 { t.Fatalf("Rows 不存在: %#v err=%v", rows, err) } + // pending、err 保存pending、err,供当前处理流程使用 pending, err := s.PublishBatches.PendingRows(ctx, "nope", false) if err != nil || len(pending) != 0 { t.Fatalf("PendingRows 不存在: %#v err=%v", pending, err) } } +// TestPublishBatches_ClaimsAreAtomicAndLeaseCanBeRecovered 负责Test发布批次列表ClaimsAreAtomicAndLeaseCanBeRecovered相关处理。 func TestPublishBatches_ClaimsAreAtomicAndLeaseCanBeRecovered(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid 保存uid,供当前处理流程使用 uid, _ := seedAccount(t, s) - if err := s.PublishBatches.Create(ctx, makePublishBatch(uid, "claim-batch"), []ItemPublishBatchRow{ + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.Create(ctx, makePublishBatch(uid, "claim-batch"), []ItemPublishBatchRow{ {RowNo: 1, Title: "A", Price: "1"}, }); err != nil { t.Fatal(err) } + // future 保存future,供当前处理流程使用 future := time.Now().UTC().Add(time.Minute).Unix() - if claimed, err := s.PublishBatches.ClaimBatch(ctx, "claim-batch", "worker-1", future); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, "claim-batch", "worker-1", future); err != nil || !claimed { t.Fatalf("first batch claim: claimed=%v err=%v", claimed, err) } + // rows 保存rows,供当前处理流程使用 rows, _ := s.PublishBatches.Rows(ctx, "claim-batch") - if claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "worker-1"); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "worker-1"); err != nil || !claimed { t.Fatalf("first row claim: claimed=%v err=%v", claimed, err) } - if claimed, err := s.PublishBatches.ClaimBatch(ctx, "claim-batch", "worker-2", future); err != nil || claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, "claim-batch", "worker-2", future); err != nil || claimed { t.Fatalf("active lease must reject second worker: claimed=%v err=%v", claimed, err) } // 0 是从旧版本迁移来的 running 任务,和已过期租约一样必须允许接管。 if _, err := s.DB.ExecContext(ctx, `UPDATE item_publish_batches SET lease_expires_at=0 WHERE id=?`, "claim-batch"); err != nil { t.Fatal(err) } - if claimed, err := s.PublishBatches.ClaimBatch(ctx, "claim-batch", "worker-2", future); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, "claim-batch", "worker-2", future); err != nil || !claimed { t.Fatalf("expired lease should be recoverable: claimed=%v err=%v", claimed, err) } + // batch、err 保存batch、err,供当前处理流程使用 batch, err := s.PublishBatches.Get(ctx, uid, "claim-batch") if err != nil || batch.WorkerToken != "worker-2" { t.Fatalf("recovered batch=%+v err=%v", batch, err) @@ -251,43 +295,57 @@ func TestPublishBatches_ClaimsAreAtomicAndLeaseCanBeRecovered(t *testing.T) { if rows[0].Status != "pending" || rows[0].WorkerToken != "" { t.Fatalf("lease takeover must recover stale running row: %+v", rows[0]) } - if claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "worker-1"); err != nil || claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "worker-1"); err != nil || claimed { t.Fatalf("stale worker must not claim after takeover: claimed=%v err=%v", claimed, err) } - if claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "worker-2"); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "worker-2"); err != nil || !claimed { t.Fatalf("new worker row claim: claimed=%v err=%v", claimed, err) } - if claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "worker-3"); err != nil || claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "worker-3"); err != nil || claimed { t.Fatalf("row must only be claimed once: claimed=%v err=%v", claimed, err) } - if marked, err := s.PublishBatches.MarkClaimedRowSuccess(ctx, rows[0].ID, "worker-1", "stale", "", "{}"); err != nil || marked { + if // marked、err 保存marked、err,供当前处理流程使用 + marked, err := s.PublishBatches.MarkClaimedRowSuccess(ctx, rows[0].ID, "worker-1", "stale", "", "{}"); err != nil || marked { t.Fatalf("stale worker must not finish row: marked=%v err=%v", marked, err) } - if marked, err := s.PublishBatches.MarkClaimedRowSuccess(ctx, rows[0].ID, "worker-2", "item-1", "", "{}"); err != nil || !marked { + if // marked、err 保存marked、err,供当前处理流程使用 + marked, err := s.PublishBatches.MarkClaimedRowSuccess(ctx, rows[0].ID, "worker-2", "item-1", "", "{}"); err != nil || !marked { t.Fatalf("owner must finish row: marked=%v err=%v", marked, err) } - if finished, err := s.PublishBatches.FinishBatchStatus(ctx, "claim-batch", "worker-1", "completed"); err != nil || finished { + if // finished、err 保存finished、err,供当前处理流程使用 + finished, err := s.PublishBatches.FinishBatchStatus(ctx, "claim-batch", "worker-1", "completed"); err != nil || finished { t.Fatalf("stale worker must not finish batch: finished=%v err=%v", finished, err) } - if finished, err := s.PublishBatches.FinishBatchStatus(ctx, "claim-batch", "worker-2", "completed"); err != nil || !finished { + if // finished、err 保存finished、err,供当前处理流程使用 + finished, err := s.PublishBatches.FinishBatchStatus(ctx, "claim-batch", "worker-2", "completed"); err != nil || !finished { t.Fatalf("owner must finish batch: finished=%v err=%v", finished, err) } } +// TestPublishBatches_ResetFailedKeepsValidationFailures 负责Test发布批次列表Reset失败KeepsValidationFailures相关处理。 func TestPublishBatches_ResetFailedKeepsValidationFailures(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid 保存uid,供当前处理流程使用 uid, _ := seedAccount(t, s) - if err := s.PublishBatches.Create(ctx, makePublishBatch(uid, "validation-batch"), []ItemPublishBatchRow{ + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.Create(ctx, makePublishBatch(uid, "validation-batch"), []ItemPublishBatchRow{ {RowNo: 1, Title: "bad", Price: "0", Status: "failed", ErrorMessage: "价格错误", FailureKind: "validation"}, {RowNo: 2, Title: "retry", Price: "1", Status: "failed", ErrorMessage: "网络错误", FailureKind: "publish"}, }); err != nil { t.Fatal(err) } - if err := s.PublishBatches.ResetFailed(ctx, "validation-batch"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.ResetFailed(ctx, "validation-batch"); err != nil { t.Fatal(err) } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := s.PublishBatches.Rows(ctx, "validation-batch") if err != nil { t.Fatal(err) @@ -300,63 +358,86 @@ func TestPublishBatches_ResetFailedKeepsValidationFailures(t *testing.T) { } } +// TestPublishBatchLeaseTakeoverQuarantinesRemoteStartedRow 负责Test发布批次LeaseTakeoverQuarantinesRemoteStartedRow相关处理。 func TestPublishBatchLeaseTakeoverQuarantinesRemoteStartedRow(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid 保存uid,供当前处理流程使用 uid, _ := seedAccount(t, s) - if err := s.PublishBatches.Create(ctx, makePublishBatch(uid, "remote-started"), []ItemPublishBatchRow{{RowNo: 1, Title: "A", Price: "1"}}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.Create(ctx, makePublishBatch(uid, "remote-started"), []ItemPublishBatchRow{{RowNo: 1, Title: "A", Price: "1"}}); err != nil { t.Fatal(err) } - if claimed, err := s.PublishBatches.ClaimBatch(ctx, "remote-started", "old", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, "remote-started", "old", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { t.Fatalf("claim batch=%v err=%v", claimed, err) } + // rows 保存rows,供当前处理流程使用 rows, _ := s.PublishBatches.Rows(ctx, "remote-started") - if claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "old"); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "old"); err != nil || !claimed { t.Fatalf("claim row=%v err=%v", claimed, err) } - if marked, err := s.PublishBatches.MarkClaimedRemoteStarted(ctx, rows[0].ID, "old"); err != nil || !marked { + if // marked、err 保存marked、err,供当前处理流程使用 + marked, err := s.PublishBatches.MarkClaimedRemoteStarted(ctx, rows[0].ID, "old"); err != nil || !marked { t.Fatalf("mark remote started=%v err=%v", marked, err) } _, _ = s.DB.ExecContext(ctx, `UPDATE item_publish_batches SET lease_expires_at=0 WHERE id='remote-started'`) - if claimed, err := s.PublishBatches.ClaimBatch(ctx, "remote-started", "new", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, "remote-started", "new", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { t.Fatalf("takeover=%v err=%v", claimed, err) } rows, _ = s.PublishBatches.Rows(ctx, "remote-started") if rows[0].Status != "failed" || rows[0].FailureKind != "uncertain_remote" { t.Fatalf("remote-started row must be quarantined: %+v", rows[0]) } - if pending, err := s.PublishBatches.PendingRows(ctx, "remote-started", false); err != nil || len(pending) != 0 { + if // pending、err 保存pending、err,供当前处理流程使用 + pending, err := s.PublishBatches.PendingRows(ctx, "remote-started", false); err != nil || len(pending) != 0 { t.Fatalf("quarantined row must not be replayable: %+v err=%v", pending, err) } } +// TestPublishBatchCancelPreservesRemoteCheckpointBeforeFinalizing 负责Test发布批次取消PreservesRemoteCheckpointBeforeFinalizing相关处理。 func TestPublishBatchCancelPreservesRemoteCheckpointBeforeFinalizing(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid 保存uid,供当前处理流程使用 uid, _ := seedAccount(t, s) - if err := s.PublishBatches.Create(ctx, makePublishBatch(uid, "cancel-checkpoint"), []ItemPublishBatchRow{{RowNo: 1, Title: "A", Price: "1"}}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.Create(ctx, makePublishBatch(uid, "cancel-checkpoint"), []ItemPublishBatchRow{{RowNo: 1, Title: "A", Price: "1"}}); err != nil { t.Fatal(err) } - if claimed, err := s.PublishBatches.ClaimBatch(ctx, "cancel-checkpoint", "worker", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, "cancel-checkpoint", "worker", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { t.Fatalf("claim batch=%v err=%v", claimed, err) } + // rows 保存rows,供当前处理流程使用 rows, _ := s.PublishBatches.Rows(ctx, "cancel-checkpoint") - if claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "worker"); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "worker"); err != nil || !claimed { t.Fatalf("claim row=%v err=%v", claimed, err) } + // token、running、err 保存token、running、err,供当前处理流程使用 token, running, err := s.PublishBatches.RequestCancel(ctx, "cancel-checkpoint") if err != nil || !running || token != "worker" { t.Fatalf("request cancel token=%q running=%v err=%v", token, running, err) } - if saved, err := s.PublishBatches.SaveClaimedRemoteResult(ctx, rows[0].ID, "worker", "remote-1", "https://example/item", `{}`); err != nil || !saved { + if // saved、err 保存saved、err,供当前处理流程使用 + saved, err := s.PublishBatches.SaveClaimedRemoteResult(ctx, rows[0].ID, "worker", "remote-1", "https://example/item", `{}`); err != nil || !saved { t.Fatalf("remote checkpoint after cancel saved=%v err=%v", saved, err) } - if _, err := s.PublishBatches.MarkClaimedRowFailed(ctx, rows[0].ID, "worker", "任务已取消", "post_publish"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.PublishBatches.MarkClaimedRowFailed(ctx, rows[0].ID, "worker", "任务已取消", "post_publish"); err != nil { t.Fatal(err) } - if finalized, err := s.PublishBatches.FinalizeCanceled(ctx, "cancel-checkpoint", "worker"); err != nil || !finalized { + if // finalized、err 保存finalized、err,供当前处理流程使用 + finalized, err := s.PublishBatches.FinalizeCanceled(ctx, "cancel-checkpoint", "worker"); err != nil || !finalized { t.Fatalf("finalized=%v err=%v", finalized, err) } rows, _ = s.PublishBatches.Rows(ctx, "cancel-checkpoint") @@ -365,33 +446,45 @@ func TestPublishBatchCancelPreservesRemoteCheckpointBeforeFinalizing(t *testing. } } +// TestFinalizeBatchRejectsUnfinishedRows 负责TestFinalize批次RejectsUnfinishedRows相关处理。 func TestFinalizeBatchRejectsUnfinishedRows(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid 保存uid,供当前处理流程使用 uid, _ := seedAccount(t, s) - if err := s.PublishBatches.Create(ctx, makePublishBatch(uid, "terminal-guard"), []ItemPublishBatchRow{ + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.Create(ctx, makePublishBatch(uid, "terminal-guard"), []ItemPublishBatchRow{ {RowNo: 1, Title: "pending", Price: "1"}, }); err != nil { t.Fatal(err) } - if claimed, err := s.PublishBatches.ClaimBatch(ctx, "terminal-guard", "worker", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, "terminal-guard", "worker", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { t.Fatalf("claim=%v err=%v", claimed, err) } - if _, finalized, err := s.PublishBatches.FinalizeBatch(ctx, "terminal-guard", "worker"); err == nil || finalized { + if // finalized、err 保存finalized、err,供当前处理流程使用 + _, finalized, err := s.PublishBatches.FinalizeBatch(ctx, "terminal-guard", "worker"); err == nil || finalized { t.Fatalf("unfinished batch finalized=%v err=%v", finalized, err) } + // batch 保存批次,供当前处理流程使用 batch, _ := s.PublishBatches.Get(ctx, uid, "terminal-guard") if batch.Status != "running" || batch.WorkerToken != "worker" { t.Fatalf("rejected finalization changed batch: %+v", batch) } + // rows 保存rows,供当前处理流程使用 rows, _ := s.PublishBatches.Rows(ctx, "terminal-guard") - if claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "worker"); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "worker"); err != nil || !claimed { t.Fatalf("claim row=%v err=%v", claimed, err) } - if marked, err := s.PublishBatches.MarkClaimedRowFailed(ctx, rows[0].ID, "worker", "failed", "publish"); err != nil || !marked { + if // marked、err 保存marked、err,供当前处理流程使用 + marked, err := s.PublishBatches.MarkClaimedRowFailed(ctx, rows[0].ID, "worker", "failed", "publish"); err != nil || !marked { t.Fatalf("mark failed=%v err=%v", marked, err) } + // status、finalized、err 保存status、finalized、err,供当前处理流程使用 status, finalized, err := s.PublishBatches.FinalizeBatch(ctx, "terminal-guard", "worker") if err != nil || !finalized || status != "failed" { t.Fatalf("status=%q finalized=%v err=%v", status, finalized, err) @@ -402,37 +495,50 @@ func TestFinalizeBatchRejectsUnfinishedRows(t *testing.T) { } } +// TestExpiredCancelingBatchIsRecoverableAndFinalizedSafely 负责TestExpiredCanceling批次IsRecoverableAndFinalizedSafely相关处理。 func TestExpiredCancelingBatchIsRecoverableAndFinalizedSafely(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid 保存uid,供当前处理流程使用 uid, _ := seedAccount(t, s) - if err := s.PublishBatches.Create(ctx, makePublishBatch(uid, "cancel-crash"), []ItemPublishBatchRow{ + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.Create(ctx, makePublishBatch(uid, "cancel-crash"), []ItemPublishBatchRow{ {RowNo: 1, Title: "remote", Price: "1"}, {RowNo: 2, Title: "pending", Price: "2"}, }); err != nil { t.Fatal(err) } - if claimed, err := s.PublishBatches.ClaimBatch(ctx, "cancel-crash", "dead-worker", 1); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, "cancel-crash", "dead-worker", 1); err != nil || !claimed { t.Fatalf("claim=%v err=%v", claimed, err) } + // rows 保存rows,供当前处理流程使用 rows, _ := s.PublishBatches.Rows(ctx, "cancel-crash") - if claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "dead-worker"); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "dead-worker"); err != nil || !claimed { t.Fatalf("claim row=%v err=%v", claimed, err) } - if marked, err := s.PublishBatches.MarkClaimedRemoteStarted(ctx, rows[0].ID, "dead-worker"); err != nil || !marked { + if // marked、err 保存marked、err,供当前处理流程使用 + marked, err := s.PublishBatches.MarkClaimedRemoteStarted(ctx, rows[0].ID, "dead-worker"); err != nil || !marked { t.Fatalf("remote started=%v err=%v", marked, err) } - if _, running, err := s.PublishBatches.RequestCancel(ctx, "cancel-crash"); err != nil || !running { + if // running、err 保存running、err,供当前处理流程使用 + _, running, err := s.PublishBatches.RequestCancel(ctx, "cancel-crash"); err != nil || !running { t.Fatalf("cancel running=%v err=%v", running, err) } + // recoverable、err 保存recoverable、err,供当前处理流程使用 recoverable, err := s.PublishBatches.Recoverable(ctx, 2, 10) if err != nil || len(recoverable) != 1 || recoverable[0].Status != "canceling" { t.Fatalf("recoverable=%+v err=%v", recoverable, err) } - if finalized, err := s.PublishBatches.FinalizeExpiredCancellation(ctx, "cancel-crash", 2); err != nil || !finalized { + if // finalized、err 保存finalized、err,供当前处理流程使用 + finalized, err := s.PublishBatches.FinalizeExpiredCancellation(ctx, "cancel-crash", 2); err != nil || !finalized { t.Fatalf("finalized=%v err=%v", finalized, err) } + // batch 保存批次,供当前处理流程使用 batch, _ := s.PublishBatches.Get(ctx, uid, "cancel-crash") rows, _ = s.PublishBatches.Rows(ctx, "cancel-crash") if batch.Status != "canceled" || batch.WorkerToken != "" || batch.LeaseExpiresAt != 0 { @@ -446,61 +552,81 @@ func TestExpiredCancelingBatchIsRecoverableAndFinalizedSafely(t *testing.T) { } } +// TestPublishBatchFinalizersFenceStaleWorker 负责Test发布批次FinalizersFenceStale工作器相关处理。 func TestPublishBatchFinalizersFenceStaleWorker(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // uid 保存uid,供当前处理流程使用 uid, _ := seedAccount(t, s) t.Run("cancel", func(t *testing.T) { + // batchID 保存批次ID,供当前处理流程使用 batchID := "cancel-fence" - if err := s.PublishBatches.Create(ctx, makePublishBatch(uid, batchID), []ItemPublishBatchRow{{RowNo: 1, Title: "A", Price: "1"}}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.Create(ctx, makePublishBatch(uid, batchID), []ItemPublishBatchRow{{RowNo: 1, Title: "A", Price: "1"}}); err != nil { t.Fatal(err) } - if claimed, err := s.PublishBatches.ClaimBatch(ctx, batchID, "old", 1); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, batchID, "old", 1); err != nil || !claimed { t.Fatalf("old claim=%v err=%v", claimed, err) } + // rows 保存rows,供当前处理流程使用 rows, _ := s.PublishBatches.Rows(ctx, batchID) - if claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "old"); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimRow(ctx, rows[0].ID, "old"); err != nil || !claimed { t.Fatalf("old row claim=%v err=%v", claimed, err) } - if claimed, err := s.PublishBatches.ClaimBatch(ctx, batchID, "new", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, batchID, "new", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { t.Fatalf("takeover=%v err=%v", claimed, err) } + // token、running、err 保存token、running、err,供当前处理流程使用 token, running, err := s.PublishBatches.RequestCancel(ctx, batchID) if err != nil || !running || token != "new" { t.Fatalf("cancel token=%q running=%v err=%v", token, running, err) } - if finalized, err := s.PublishBatches.FinalizeCanceled(ctx, batchID, "old"); err != nil || finalized { + if // finalized、err 保存finalized、err,供当前处理流程使用 + finalized, err := s.PublishBatches.FinalizeCanceled(ctx, batchID, "old"); err != nil || finalized { t.Fatalf("stale cancel finalized=%v err=%v", finalized, err) } rows, _ = s.PublishBatches.Rows(ctx, batchID) if rows[0].Status != "pending" { t.Fatalf("stale cancel changed current row: %+v", rows[0]) } - if finalized, err := s.PublishBatches.FinalizeCanceled(ctx, batchID, "new"); err != nil || !finalized { + if // finalized、err 保存finalized、err,供当前处理流程使用 + finalized, err := s.PublishBatches.FinalizeCanceled(ctx, batchID, "new"); err != nil || !finalized { t.Fatalf("current cancel finalized=%v err=%v", finalized, err) } }) t.Run("interrupted", func(t *testing.T) { + // batchID 保存批次ID,供当前处理流程使用 batchID := "interrupt-fence" - if err := s.PublishBatches.Create(ctx, makePublishBatch(uid, batchID), []ItemPublishBatchRow{{RowNo: 1, Title: "A", Price: "1"}}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.PublishBatches.Create(ctx, makePublishBatch(uid, batchID), []ItemPublishBatchRow{{RowNo: 1, Title: "A", Price: "1"}}); err != nil { t.Fatal(err) } - if claimed, err := s.PublishBatches.ClaimBatch(ctx, batchID, "old", 1); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, batchID, "old", 1); err != nil || !claimed { t.Fatalf("old claim=%v err=%v", claimed, err) } - if claimed, err := s.PublishBatches.ClaimBatch(ctx, batchID, "new", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { + if // claimed、err 保存claimed、err,供当前处理流程使用 + claimed, err := s.PublishBatches.ClaimBatch(ctx, batchID, "new", time.Now().Add(time.Minute).Unix()); err != nil || !claimed { t.Fatalf("takeover=%v err=%v", claimed, err) } - if _, finalized, err := s.PublishBatches.FinalizeInterrupted(ctx, batchID, "old", "old interrupted"); err != nil || finalized { + if // finalized、err 保存finalized、err,供当前处理流程使用 + _, finalized, err := s.PublishBatches.FinalizeInterrupted(ctx, batchID, "old", "old interrupted"); err != nil || finalized { t.Fatalf("stale interrupt finalized=%v err=%v", finalized, err) } + // rows 保存rows,供当前处理流程使用 rows, _ := s.PublishBatches.Rows(ctx, batchID) if rows[0].Status != "pending" { t.Fatalf("stale interrupt changed current row: %+v", rows[0]) } + // status、finalized、err 保存status、finalized、err,供当前处理流程使用 status, finalized, err := s.PublishBatches.FinalizeInterrupted(ctx, batchID, "new", "new interrupted") if err != nil || !finalized || status != "failed" { t.Fatalf("current interrupt status=%q finalized=%v err=%v", status, finalized, err) diff --git a/internal/db/renewal.go b/internal/db/renewal.go index 3039e44..499774b 100644 --- a/internal/db/renewal.go +++ b/internal/db/renewal.go @@ -60,6 +60,7 @@ type RenewalStore struct { // AllRenewalAccounts 返回所有账号,包含启用状态;浏览器 cookie 续期会用到禁用账号。 func (c *Cookies) AllRenewalAccounts(ctx context.Context) ([]RenewalAccount, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := c.DB.QueryContext(ctx, `SELECT c.id, c.value, c.user_id, COALESCE(cs.enabled, 1), COALESCE(cs.disable_reason,''), COALESCE(c.username,''), COALESCE(c.password,''), COALESCE(c.show_browser,0), @@ -76,6 +77,7 @@ func (c *Cookies) AllRenewalAccounts(ctx context.Context) ([]RenewalAccount, err // ActiveRenewalAccounts 返回启用账号,用于 WS/API 续期类任务。 func (c *Cookies) ActiveRenewalAccounts(ctx context.Context) ([]RenewalAccount, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := c.DB.QueryContext(ctx, `SELECT c.id, c.value, c.user_id, COALESCE(cs.enabled, 1), COALESCE(cs.disable_reason,''), COALESCE(c.username,''), COALESCE(c.password,''), COALESCE(c.show_browser,0), @@ -91,16 +93,22 @@ func (c *Cookies) ActiveRenewalAccounts(ctx context.Context) ([]RenewalAccount, return c.scanRenewalAccounts(rows) } +// scanRenewalAccounts 负责scanRenewal账号列表相关处理。 func (c *Cookies) scanRenewalAccounts(rows *sql.Rows) ([]RenewalAccount, error) { + // out 保存out,供当前处理流程使用 var out []RenewalAccount for rows.Next() { + // a 保存a,供当前处理流程使用 var a RenewalAccount + // enabled、showBrowser 保存enabled、show浏览器,供当前处理流程使用 var enabled, showBrowser int - if err := rows.Scan(&a.ID, &a.Value, &a.UserID, &enabled, &a.DisableReason, &a.Username, &a.Password, &showBrowser, &a.MetadataJSON, &a.LastRefreshAt); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&a.ID, &a.Value, &a.UserID, &enabled, &a.DisableReason, &a.Username, &a.Password, &showBrowser, &a.MetadataJSON, &a.LastRefreshAt); err != nil { return nil, err } a.Enabled = enabled != 0 a.ShowBrowser = showBrowser != 0 + // err 保存err,供当前处理流程使用 var err error a.Value, err = c.codec.decrypt("cookie", a.ID, a.Value) if err != nil { @@ -127,14 +135,17 @@ func (c *Cookies) UpdateRenewalCookie(ctx context.Context, cookieID, cookieValue if lastRefreshAt <= 0 { lastRefreshAt = time.Now().Unix() } + // encryptedCookie、err 保存encryptedCookie、err,供当前处理流程使用 encryptedCookie, err := c.codec.encrypt("cookie", cookieID, cookieValue) if err != nil { return fmt.Errorf("加密 Cookie: %w", err) } + // encryptedMetadata、err 保存encryptedMetadata、err,供当前处理流程使用 encryptedMetadata, err := c.codec.encrypt(cookieMetadataScope, cookieID, metadataJSON) if err != nil { return fmt.Errorf("加密 Cookie metadata: %w", err) } + // res、err 保存res、err,供当前处理流程使用 res, err := c.DB.ExecContext(ctx, `UPDATE cookies SET value=?, metadata_json=?, last_refresh_at=?, updated_at=CURRENT_TIMESTAMP @@ -143,6 +154,7 @@ func (c *Cookies) UpdateRenewalCookie(ctx context.Context, cookieID, cookieValue if err != nil { return err } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := res.RowsAffected() if err != nil { return err @@ -153,8 +165,10 @@ func (c *Cookies) UpdateRenewalCookie(ctx context.Context, cookieID, cookieValue if rows == 0 { // MySQL 默认报告“实际变更行数”,同值且同秒更新可能返回 0; // 只有记录确实不存在时才应映射为 ErrNotFound。 + // exists 保存exists,供当前处理流程使用 var exists bool - if err := c.DB.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM cookies WHERE id=?)`, cookieID).Scan(&exists); err != nil { + if // err 保存err,供当前处理流程使用 + err := c.DB.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM cookies WHERE id=?)`, cookieID).Scan(&exists); err != nil { return err } if !exists { @@ -166,8 +180,11 @@ func (c *Cookies) UpdateRenewalCookie(ctx context.Context, cookieID, cookieValue // GetCookieRefreshSchedule 读取浏览器 Cookie 续期计划。 func (r *RenewalStore) GetCookieRefreshSchedule(ctx context.Context, cookieID string) (*CookieRefreshSchedule, error) { + // s 保存s,供当前处理流程使用 var s CookieRefreshSchedule + // disabled 保存disabled,供当前处理流程使用 var disabled int + // err 保存err,供当前处理流程使用 err := r.DB.QueryRowContext(ctx, `SELECT cookie_id, expire_at, disabled, consecutive_failures, COALESCE(last_error,''), COALESCE(last_status,''), COALESCE(last_error_message,''), COALESCE(last_refresh_at,0) @@ -186,10 +203,12 @@ func (r *RenewalStore) GetCookieRefreshSchedule(ctx context.Context, cookieID st // UpsertCookieRefreshSchedule 写入浏览器 Cookie 续期计划。 func (r *RenewalStore) UpsertCookieRefreshSchedule(ctx context.Context, s CookieRefreshSchedule) error { + // disabled 保存disabled,供当前处理流程使用 disabled := 0 if s.Disabled { disabled = 1 } + // err 保存err,供当前处理流程使用 _, err := r.DB.ExecContext(ctx, `INSERT INTO cookie_refresh_schedules (cookie_id, expire_at, disabled, consecutive_failures, last_error, @@ -215,6 +234,7 @@ func (r *RenewalStore) AddBrowserCookieRenewLog(ctx context.Context, log Renewal if log.UpdatedCookieCount == 0 { log.UpdatedCookieCount = len(log.UpdatedCookieNames) } + // err 保存err,供当前处理流程使用 _, err := r.DB.ExecContext(ctx, `INSERT INTO scheduled_cookies_refresh_log (batch_id, cookie_id, status, message, error_message, updated_cookie_names, @@ -232,6 +252,7 @@ func (r *RenewalStore) AddLoginRenewLog(ctx context.Context, log RenewalLog) err if log.UpdatedCookieCount == 0 { log.UpdatedCookieCount = len(log.UpdatedCookieNames) } + // err 保存err,供当前处理流程使用 _, err := r.DB.ExecContext(ctx, `INSERT INTO scheduled_login_renew_log (batch_id, cookie_id, status, message, error_message, updated_cookie_names, @@ -249,6 +270,7 @@ func (r *RenewalStore) AddAPICookieRenewLog(ctx context.Context, log RenewalLog) if log.UpdatedCookieCount == 0 { log.UpdatedCookieCount = len(log.UpdatedCookieNames) } + // err 保存err,供当前处理流程使用 _, err := r.DB.ExecContext(ctx, `INSERT INTO scheduled_api_cookie_renew_log (batch_id, cookie_id, status, message, error_message, updated_cookie_names, @@ -266,6 +288,7 @@ func (r *RenewalStore) RecentAPICookieRenewStatuses(ctx context.Context, cookieI if limit <= 0 { return nil, nil } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := r.DB.QueryContext(ctx, `SELECT status FROM scheduled_api_cookie_renew_log WHERE cookie_id=? ORDER BY id DESC LIMIT ?`, cookieID, limit) @@ -273,10 +296,13 @@ func (r *RenewalStore) RecentAPICookieRenewStatuses(ctx context.Context, cookieI return nil, err } defer rows.Close() + // statuses 保存statuses,供当前处理流程使用 statuses := make([]string, 0, limit) for rows.Next() { + // status 保存状态,供当前处理流程使用 var status string - if err := rows.Scan(&status); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&status); err != nil { return nil, err } statuses = append(statuses, status) @@ -285,17 +311,21 @@ func (r *RenewalStore) RecentAPICookieRenewStatuses(ctx context.Context, cookieI } // CleanupLogs deletes renewal logs older than retentionDays. Non-positive values skip cleanup. +// CleanupLogs 负责CleanupLogs相关处理。 func (r *RenewalStore) CleanupLogs(ctx context.Context, retentionDays int) error { if retentionDays <= 0 { return nil } + // cutoff 保存cutoff,供当前处理流程使用 cutoff := time.Now().AddDate(0, 0, -retentionDays) + // table 表示当前遍历过程中的table for _, table := range []string{ "scheduled_cookies_refresh_log", "scheduled_login_renew_log", "scheduled_api_cookie_renew_log", } { - if _, err := r.DB.ExecContext(ctx, `DELETE FROM `+table+` WHERE created_at < ?`, cutoff); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := r.DB.ExecContext(ctx, `DELETE FROM `+table+` WHERE created_at < ?`, cutoff); err != nil { return err } } @@ -307,6 +337,7 @@ func (r *RenewalStore) RecentBrowserCookieRenewStatuses(ctx context.Context, coo if limit <= 0 { return nil, nil } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := r.DB.QueryContext(ctx, `SELECT status FROM scheduled_cookies_refresh_log WHERE cookie_id=? ORDER BY id DESC LIMIT ?`, cookieID, limit) @@ -314,10 +345,13 @@ func (r *RenewalStore) RecentBrowserCookieRenewStatuses(ctx context.Context, coo return nil, err } defer rows.Close() + // statuses 保存statuses,供当前处理流程使用 var statuses []string for rows.Next() { + // status 保存状态,供当前处理流程使用 var status string - if err := rows.Scan(&status); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&status); err != nil { return nil, err } statuses = append(statuses, status) @@ -325,7 +359,9 @@ func (r *RenewalStore) RecentBrowserCookieRenewStatuses(ctx context.Context, coo return statuses, rows.Err() } +// firstNonEmpty 负责firstNonEmpty相关处理。 func firstNonEmpty(values ...string) string { + // v 表示当前遍历过程中的v for _, v := range values { if strings.TrimSpace(v) != "" { return v diff --git a/internal/db/renewal_test.go b/internal/db/renewal_test.go index 895aba9..af97697 100644 --- a/internal/db/renewal_test.go +++ b/internal/db/renewal_test.go @@ -7,32 +7,44 @@ import ( "testing" ) +// TestUpdateRenewalCookieEncryptsCookieAndMetadataAtRest 负责TestUpdateRenewal登录凭证Encrypts登录凭证AndMetadataAtRest相关处理。 func TestUpdateRenewalCookieEncryptsCookieAndMetadataAtRest(t *testing.T) { t.Setenv("XIANYU_DATA_KEY", "renewal-encryption-key") + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if ok, err := store.Users.Create(ctx, "renewal-owner", "renewal-owner@example.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := store.Users.Create(ctx, "renewal-owner", "renewal-owner@example.com", "pw"); err != nil || !ok { t.Fatalf("create owner: ok=%v err=%v", ok, err) } + // owner 保存所有者,供当前处理流程使用 owner, _ := store.Users.GetByUsername(ctx, "renewal-owner") - if err := store.Cookies.CreateOwned(ctx, "renewal-cookie", "old=1", owner.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.CreateOwned(ctx, "renewal-cookie", "old=1", owner.ID); err != nil { t.Fatal(err) } + // metadata 保存metadata,供当前处理流程使用 metadata := `{"cookies_refresh_snapshot":[{"name":"token","value":"metadata-secret","domain":".goofish.com","path":"/"}],"other":true}` - if err := store.Cookies.UpdateRenewalCookie(ctx, "renewal-cookie", "token=cookie-secret", metadata, 12345); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.UpdateRenewalCookie(ctx, "renewal-cookie", "token=cookie-secret", metadata, 12345); err != nil { t.Fatal(err) } + // rawCookie、rawMetadata 保存原始Cookie、rawMetadata,供当前处理流程使用 var rawCookie, rawMetadata string - if err := store.DB.QueryRowContext(ctx, `SELECT value,metadata_json FROM cookies WHERE id=?`, "renewal-cookie").Scan(&rawCookie, &rawMetadata); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT value,metadata_json FROM cookies WHERE id=?`, "renewal-cookie").Scan(&rawCookie, &rawMetadata); err != nil { t.Fatal(err) } + // name、raw 表示当前遍历过程中的name、raw for name, raw := range map[string]string{"cookie": rawCookie, "metadata": rawMetadata} { if !strings.HasPrefix(raw, encryptedValuePrefix) || strings.Contains(raw, "secret") { t.Fatalf("%s was not encrypted at rest: %q", name, raw) } } + // detail、err 保存detail、err,供当前处理流程使用 detail, err := store.Cookies.GetDetails(ctx, "renewal-cookie") if err != nil { t.Fatal(err) @@ -40,6 +52,7 @@ func TestUpdateRenewalCookieEncryptsCookieAndMetadataAtRest(t *testing.T) { if detail.Value != "token=cookie-secret" || detail.MetadataJSON != metadata || detail.LastRefreshAt != 12345 { t.Fatalf("detail=%+v", detail) } + // accounts、err 保存accounts、err,供当前处理流程使用 accounts, err := store.Cookies.ActiveRenewalAccounts(ctx) if err != nil || len(accounts) != 1 { t.Fatalf("accounts=%+v err=%v", accounts, err) @@ -49,34 +62,47 @@ func TestUpdateRenewalCookieEncryptsCookieAndMetadataAtRest(t *testing.T) { } } +// TestUpdateRenewalCookieRejectsMissingAccount 负责TestUpdateRenewal登录凭证RejectsMissing账号相关处理。 func TestUpdateRenewalCookieRejectsMissingAccount(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // err 保存err,供当前处理流程使用 err := store.Cookies.UpdateRenewalCookie(context.Background(), "missing", "a=1", `{}`, 1) if !errors.Is(err, ErrNotFound) { t.Fatalf("err=%v want ErrNotFound", err) } } +// TestFlatCookieUpdateClearsSnapshotAndPreservesOtherMetadata 负责TestFlat登录凭证UpdateClearsSnapshotAndPreservesOtherMetadata相关处理。 func TestFlatCookieUpdateClearsSnapshotAndPreservesOtherMetadata(t *testing.T) { t.Setenv("XIANYU_DATA_KEY", "flat-update-metadata-key") + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if ok, err := store.Users.Create(ctx, "flat-owner", "flat-owner@example.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := store.Users.Create(ctx, "flat-owner", "flat-owner@example.com", "pw"); err != nil || !ok { t.Fatalf("create owner: ok=%v err=%v", ok, err) } + // owner 保存所有者,供当前处理流程使用 owner, _ := store.Users.GetByUsername(ctx, "flat-owner") - if err := store.Cookies.CreateOwned(ctx, "flat-cookie", "sid=old", owner.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.CreateOwned(ctx, "flat-cookie", "sid=old", owner.ID); err != nil { t.Fatal(err) } + // metadata 保存metadata,供当前处理流程使用 metadata := `{"cookies_refresh_snapshot":[{"name":"sid","value":"old","domain":".goofish.com","path":"/"}],"other":true}` - if err := store.Cookies.UpdateRenewalCookie(ctx, "flat-cookie", "sid=old", metadata, 1); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.UpdateRenewalCookie(ctx, "flat-cookie", "sid=old", metadata, 1); err != nil { t.Fatal(err) } - if err := store.Cookies.UpdateValueExisting(ctx, "flat-cookie", "sid=fresh"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.UpdateValueExisting(ctx, "flat-cookie", "sid=fresh"); err != nil { t.Fatal(err) } + // detail、err 保存detail、err,供当前处理流程使用 detail, err := store.Cookies.GetDetails(ctx, "flat-cookie") if err != nil { t.Fatal(err) @@ -84,8 +110,10 @@ func TestFlatCookieUpdateClearsSnapshotAndPreservesOtherMetadata(t *testing.T) { if detail.Value != "sid=fresh" || strings.Contains(detail.MetadataJSON, "cookies_refresh_snapshot") || !strings.Contains(detail.MetadataJSON, `"other":true`) { t.Fatalf("detail=%+v", detail) } + // rawMetadata 保存原始Metadata,供当前处理流程使用 var rawMetadata string - if err := store.DB.QueryRowContext(ctx, `SELECT metadata_json FROM cookies WHERE id=?`, "flat-cookie").Scan(&rawMetadata); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT metadata_json FROM cookies WHERE id=?`, "flat-cookie").Scan(&rawMetadata); err != nil { t.Fatal(err) } if !strings.HasPrefix(rawMetadata, encryptedValuePrefix) || strings.Contains(rawMetadata, "other") { @@ -93,31 +121,42 @@ func TestFlatCookieUpdateClearsSnapshotAndPreservesOtherMetadata(t *testing.T) { } } +// TestEncryptLegacySecretsMigratesCookieMetadata 负责TestEncryptLegacySecretsMigrates登录凭证Metadata相关处理。 func TestEncryptLegacySecretsMigratesCookieMetadata(t *testing.T) { t.Setenv("XIANYU_DATA_KEY", "metadata-migration-key") + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if ok, err := store.Users.Create(ctx, "metadata-owner", "metadata-owner@example.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := store.Users.Create(ctx, "metadata-owner", "metadata-owner@example.com", "pw"); err != nil || !ok { t.Fatalf("create owner: ok=%v err=%v", ok, err) } + // owner 保存所有者,供当前处理流程使用 owner, _ := store.Users.GetByUsername(ctx, "metadata-owner") + // metadata 保存metadata,供当前处理流程使用 metadata := `{"cookies_refresh_snapshot":[{"name":"sid","value":"legacy-secret"}]}` - if _, err := store.DB.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `INSERT INTO cookies (id,value,user_id,metadata_json) VALUES (?,?,?,?)`, "legacy-metadata", "legacy-cookie", owner.ID, metadata); err != nil { t.Fatal(err) } - if err := store.EncryptLegacySecrets(ctx); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.EncryptLegacySecrets(ctx); err != nil { t.Fatal(err) } + // raw 保存原始,供当前处理流程使用 var raw string - if err := store.DB.QueryRowContext(ctx, `SELECT metadata_json FROM cookies WHERE id=?`, "legacy-metadata").Scan(&raw); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT metadata_json FROM cookies WHERE id=?`, "legacy-metadata").Scan(&raw); err != nil { t.Fatal(err) } if !strings.HasPrefix(raw, encryptedValuePrefix) || strings.Contains(raw, "legacy-secret") { t.Fatalf("legacy metadata was not encrypted: %q", raw) } + // detail、err 保存detail、err,供当前处理流程使用 detail, err := store.Cookies.GetDetails(ctx, "legacy-metadata") if err != nil || detail.MetadataJSON != metadata { t.Fatalf("detail=%+v err=%v", detail, err) diff --git a/internal/db/reply.go b/internal/db/reply.go index f9694f2..de69308 100644 --- a/internal/db/reply.go +++ b/internal/db/reply.go @@ -60,6 +60,7 @@ type Keywords struct { // AllWithType 取某账号所有关键字(含类型/图片)。 func (k *Keywords) AllWithType(ctx context.Context, cookieID string) ([]Keyword, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := k.DB.QueryContext(ctx, `SELECT keyword, reply, COALESCE(item_id,''), COALESCE(type,'text'), COALESCE(image_url,'') FROM keywords WHERE cookie_id=? ORDER BY LENGTH(keyword) DESC,id ASC`, cookieID) @@ -67,10 +68,13 @@ func (k *Keywords) AllWithType(ctx context.Context, cookieID string) ([]Keyword, return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []Keyword for rows.Next() { + // kw 保存kw,供当前处理流程使用 var kw Keyword - if err := rows.Scan(&kw.Keyword, &kw.Reply, &kw.ItemID, &kw.Type, &kw.ImageURL); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&kw.Keyword, &kw.Reply, &kw.ItemID, &kw.Type, &kw.ImageURL); err != nil { return nil, err } out = append(out, kw) @@ -86,9 +90,13 @@ type DefaultReplies struct { // Get 取某账号默认回复设置。不存在返回 ErrNotFound。 func (d *DefaultReplies) Get(ctx context.Context, cookieID string) (*DefaultReply, error) { + // dr 保存dr,供当前处理流程使用 var dr DefaultReply + // enabled、replyOnce 保存enabled、replyOnce,供当前处理流程使用 var enabled, replyOnce int + // content、imageURL 保存content、imageURL,供当前处理流程使用 var content, imageURL sql.NullString + // err 保存err,供当前处理流程使用 err := d.DB.QueryRowContext(ctx, `SELECT enabled, reply_content, reply_image_url, reply_once FROM default_replies WHERE cookie_id=?`, cookieID).Scan(&enabled, &content, &imageURL, &replyOnce) @@ -107,6 +115,7 @@ func (d *DefaultReplies) Get(ctx context.Context, cookieID string) (*DefaultRepl // Upsert 保存或覆盖指定账号的默认回复配置。 func (d *DefaultReplies) Upsert(ctx context.Context, cookieID string, reply DefaultReply) error { + // err 保存err,供当前处理流程使用 _, err := d.DB.ExecContext(ctx, `INSERT INTO default_replies (cookie_id, enabled, reply_content, reply_image_url, reply_once, updated_at) VALUES (?,?,?,?,?,CURRENT_TIMESTAMP)`+dialectUpsert(d.Dialect, []string{"cookie_id"}, map[string]string{ @@ -130,6 +139,7 @@ func defaultReplyNullableString(value string) any { // ListForUser 查询用户所有账号的默认回复配置。 func (d *DefaultReplies) ListForUser(ctx context.Context, userID int64) ([]DefaultReplySummary, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := d.DB.QueryContext(ctx, ` SELECT dr.cookie_id, dr.enabled, COALESCE(dr.reply_content,''), dr.reply_once, COALESCE(dr.reply_image_url,'') FROM default_replies dr JOIN cookies c ON c.id=dr.cookie_id WHERE c.user_id=?`, userID) @@ -137,11 +147,15 @@ func (d *DefaultReplies) ListForUser(ctx context.Context, userID int64) ([]Defau return nil, err } defer rows.Close() + // out 保存out,供当前处理流程使用 var out []DefaultReplySummary for rows.Next() { + // item 保存商品,供当前处理流程使用 var item DefaultReplySummary + // enabled、replyOnce 保存enabled、replyOnce,供当前处理流程使用 var enabled, replyOnce int - if err := rows.Scan(&item.CookieID, &enabled, &item.ReplyContent, &replyOnce, &item.ReplyImageURL); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&item.CookieID, &enabled, &item.ReplyContent, &replyOnce, &item.ReplyImageURL); err != nil { return nil, err } item.Enabled = enabled != 0 @@ -153,19 +167,23 @@ func (d *DefaultReplies) ListForUser(ctx context.Context, userID int64) ([]Defau // Delete 删除指定账号的默认回复配置。 func (d *DefaultReplies) Delete(ctx context.Context, cookieID string) error { + // err 保存err,供当前处理流程使用 _, err := d.DB.ExecContext(ctx, `DELETE FROM default_replies WHERE cookie_id=?`, cookieID) return err } // ClearRecords 清空指定账号的默认回复投递记录。 func (d *DefaultReplies) ClearRecords(ctx context.Context, cookieID string) error { + // err 保存err,供当前处理流程使用 _, err := d.DB.ExecContext(ctx, `DELETE FROM default_reply_records WHERE cookie_id=?`, cookieID) return err } // HasRecord 是否已对该 chat_id 回复过(reply_once 用)。 func (d *DefaultReplies) HasRecord(ctx context.Context, cookieID, chatID string) bool { + // n 保存n,供当前处理流程使用 var n int + // err 保存err,供当前处理流程使用 err := d.DB.QueryRowContext(ctx, `SELECT 1 FROM default_reply_records WHERE cookie_id=? AND chat_id=? AND status='sent' LIMIT 1`, cookieID, chatID).Scan(&n) @@ -174,20 +192,27 @@ func (d *DefaultReplies) HasRecord(ctx context.Context, cookieID, chatID string) // ClaimRecord 原子领取一次默认回复投递。新记录初始化为 pending;失败记录允许继续 // 投递尚未成功的部分;pending/sent 记录会阻止并发重复发送。 +// ClaimRecord 负责ClaimRecord相关处理。 func (d *DefaultReplies) ClaimRecord(ctx context.Context, cookieID, chatID string, needsText, needsImage bool) (DefaultReplyRecord, bool, error) { + // now 保存now,供当前处理流程使用 now := time.Now().UTC().Unix() + // leaseExpiresAt 保存leaseExpiresAt,供当前处理流程使用 leaseExpiresAt := now + int64((5*time.Minute)/time.Second) + // query 保存查询,供当前处理流程使用 query := dialectInsertIgnorePrefix(d.Dialect) + ` INTO default_reply_records (cookie_id,chat_id,status,text_sent,image_sent,last_error,lease_expires_at,updated_at) VALUES (?,?, 'pending', ?, ?, '', ?, CURRENT_TIMESTAMP)` + dialectInsertIgnore(d.Dialect, []string{"cookie_id", "chat_id"}) + // res、err 保存res、err,供当前处理流程使用 res, err := d.DB.ExecContext(ctx, query, cookieID, chatID, boolToInt(!needsText), boolToInt(!needsImage), leaseExpiresAt) if err != nil { return DefaultReplyRecord{}, false, err } - if affected, _ := res.RowsAffected(); affected > 0 { + if // affected 保存affected,供当前处理流程使用 + affected, _ := res.RowsAffected(); affected > 0 { return DefaultReplyRecord{Status: "pending", TextSent: !needsText, ImageSent: !needsImage}, true, nil } + // record、err 保存record、err,供当前处理流程使用 record, err := d.Record(ctx, cookieID, chatID) if err != nil { return DefaultReplyRecord{}, false, err @@ -205,14 +230,18 @@ func (d *DefaultReplies) ClaimRecord(ctx context.Context, cookieID, chatID strin if err != nil { return DefaultReplyRecord{}, false, err } + // affected 保存affected,供当前处理流程使用 affected, _ := res.RowsAffected() return record, affected > 0, nil } // Record 查询一次默认回复的投递状态。 func (d *DefaultReplies) Record(ctx context.Context, cookieID, chatID string) (DefaultReplyRecord, error) { + // record 保存record,供当前处理流程使用 var record DefaultReplyRecord + // textSent、imageSent 保存文本Sent、imageSent,供当前处理流程使用 var textSent, imageSent int + // err 保存err,供当前处理流程使用 err := d.DB.QueryRowContext(ctx, `SELECT status,text_sent,image_sent FROM default_reply_records WHERE cookie_id=? AND chat_id=?`, cookieID, chatID). Scan(&record.Status, &textSent, &imageSent) @@ -223,6 +252,7 @@ func (d *DefaultReplies) Record(ctx context.Context, cookieID, chatID string) (D // MarkPartSent 标记图片或文字已经成功投递。 func (d *DefaultReplies) MarkPartSent(ctx context.Context, cookieID, chatID, part string) error { + // column 保存column,供当前处理流程使用 column := "" switch part { case "text": @@ -232,18 +262,23 @@ func (d *DefaultReplies) MarkPartSent(ctx context.Context, cookieID, chatID, par default: return errors.New("未知默认回复部分") } + // err 保存err,供当前处理流程使用 _, err := d.DB.ExecContext(ctx, `UPDATE default_reply_records SET `+column+`=1,updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND chat_id=?`, cookieID, chatID) return err } +// MarkRecordFailed 负责MarkRecord失败相关处理。 func (d *DefaultReplies) MarkRecordFailed(ctx context.Context, cookieID, chatID, message string) error { + // err 保存err,供当前处理流程使用 _, err := d.DB.ExecContext(ctx, `UPDATE default_reply_records SET status='failed',last_error=?,lease_expires_at=0,updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND chat_id=?`, message, cookieID, chatID) return err } +// MarkRecordSent 负责MarkRecordSent相关处理。 func (d *DefaultReplies) MarkRecordSent(ctx context.Context, cookieID, chatID string) error { + // err 保存err,供当前处理流程使用 _, err := d.DB.ExecContext(ctx, `UPDATE default_reply_records SET status='sent',last_error='',lease_expires_at=0,replied_at=CURRENT_TIMESTAMP,updated_at=CURRENT_TIMESTAMP WHERE cookie_id=? AND chat_id=?`, cookieID, chatID) @@ -252,6 +287,7 @@ func (d *DefaultReplies) MarkRecordSent(ctx context.Context, cookieID, chatID st // AddRecord 记录已回复(reply_once 防重复)。 func (d *DefaultReplies) AddRecord(ctx context.Context, cookieID, chatID string) error { + // err 保存err,供当前处理流程使用 _, err := d.DB.ExecContext(ctx, dialectInsertIgnorePrefix(d.Dialect)+` INTO default_reply_records (cookie_id, chat_id) VALUES (?, ?)`+dialectInsertIgnore(d.Dialect, []string{"cookie_id", "chat_id"}), cookieID, chatID) @@ -266,8 +302,11 @@ type ItemReplies struct { // Get 取某账号某商品的指定回复。 func (i *ItemReplies) Get(ctx context.Context, cookieID, itemID string) (*ItemReply, error) { + // ir 保存ir,供当前处理流程使用 var ir ItemReply + // content 保存内容,供当前处理流程使用 var content sql.NullString + // err 保存err,供当前处理流程使用 err := i.DB.QueryRowContext(ctx, `SELECT item_id, cookie_id, reply_content FROM item_replay WHERE cookie_id=? AND item_id=?`, cookieID, itemID).Scan(&ir.ItemID, &ir.CookieID, &content) diff --git a/internal/db/reply_state_test.go b/internal/db/reply_state_test.go index 654e23f..a58aded 100644 --- a/internal/db/reply_state_test.go +++ b/internal/db/reply_state_test.go @@ -7,27 +7,35 @@ import ( "time" ) +// TestDefaultReplyClaimReclaimsExpiredPendingLease 负责TestDefault回复ClaimReclaimsExpiredPendingLease相关处理。 func TestDefaultReplyClaimReclaimsExpiredPendingLease(t *testing.T) { + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // database、dialect、err 保存database、dialect、err,供当前处理流程使用 database, dialect, err := Open(ctx, filepath.Join(t.TempDir(), "reply-state.db")) if err != nil { t.Fatalf("Open: %v", err) } defer database.Close() + // store 保存store,供当前处理流程使用 store := NewStore(database, dialect) + // result、err 保存result、err,供当前处理流程使用 result, err := database.ExecContext(ctx, `INSERT INTO users (username,email,password_hash) VALUES (?,?,?)`, "reply-test", "reply-test@example.com", "hash") if err != nil { t.Fatalf("insert user: %v", err) } + // userID、err 保存用户ID、err,供当前处理流程使用 userID, err := result.LastInsertId() if err != nil { t.Fatalf("LastInsertId: %v", err) } - if err := store.Cookies.Save(ctx, "cookie-1", "unb=1", userID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.Save(ctx, "cookie-1", "unb=1", userID); err != nil { t.Fatalf("save cookie: %v", err) } + // initial、claimed、err 保存initial、claimed、err,供当前处理流程使用 initial, claimed, err := store.DefaultReps.ClaimRecord(ctx, "cookie-1", "chat-1", true, true) if err != nil || !claimed || initial.Status != "pending" { t.Fatalf("initial claim: record=%+v claimed=%v err=%v", initial, claimed, err) @@ -40,6 +48,7 @@ func TestDefaultReplyClaimReclaimsExpiredPendingLease(t *testing.T) { if err != nil { t.Fatalf("expire lease: %v", err) } + // reclaimed、claimed、err 保存reclaimed、claimed、err,供当前处理流程使用 reclaimed, claimed, err := store.DefaultReps.ClaimRecord(ctx, "cookie-1", "chat-1", true, true) if err != nil || !claimed || reclaimed.Status != "pending" { t.Fatalf("expired pending lease should be reclaimed: record=%+v claimed=%v err=%v", reclaimed, claimed, err) diff --git a/internal/db/repository_test.go b/internal/db/repository_test.go index 33f3ac3..c0210df 100644 --- a/internal/db/repository_test.go +++ b/internal/db/repository_test.go @@ -6,24 +6,31 @@ import ( "testing" ) +// newTestDB 负责newTestDB相关处理。 func newTestDB(t *testing.T) (*Store, func()) { t.Helper() + // dbPath 保存db路径,供当前处理流程使用 dbPath := filepath.Join(t.TempDir(), "test.db") + // db、err 保存db、err,供当前处理流程使用 db, _, err := Open(context.Background(), dbPath) if err != nil { t.Fatalf("Open: %v", err) } + // s 保存s,供当前处理流程使用 s := NewStore(db, DialectSQLite) return s, func() { db.Close() } } // TestPassword_LegacySHA256Compat 老 SHA-26 哈希能校验、且标记需升级。 func TestPassword_LegacySHA256Compat(t *testing.T) { + // legacy 保存legacy,供当前处理流程使用 legacy := legacySHA256("hunter2") + // matched、needsUpgrade、err 保存matched、needsUpgrade、err,供当前处理流程使用 matched, needsUpgrade, err := VerifyPassword(legacy, "hunter2") if err != nil || !matched || !needsUpgrade { t.Fatalf("老哈希校验失败: matched=%v needsUpgrade=%v err=%v", matched, needsUpgrade, err) } + // matched2 保存matched2,供当前处理流程使用 matched2, _, _ := VerifyPassword(legacy, "wrong") if matched2 { t.Fatal("错误密码不应通过") @@ -32,10 +39,12 @@ func TestPassword_LegacySHA256Compat(t *testing.T) { // TestPassword_Bcrypt 新 bcrypt 哈希正常工作且不标记升级。 func TestPassword_Bcrypt(t *testing.T) { + // h、err 保存h、err,供当前处理流程使用 h, err := HashPassword("s3cret") if err != nil { t.Fatal(err) } + // matched、needsUpgrade、err 保存matched、needsUpgrade、err,供当前处理流程使用 matched, needsUpgrade, err := VerifyPassword(h, "s3cret") if err != nil || !matched || needsUpgrade { t.Fatalf("bcrypt 校验: matched=%v needsUpgrade=%v err=%v", matched, needsUpgrade, err) @@ -44,8 +53,10 @@ func TestPassword_Bcrypt(t *testing.T) { // TestUserLifecycle 创建→验证→升级→改密 全链路。 func TestUserLifecycle(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() // 系统未初始化。 @@ -53,14 +64,17 @@ func TestUserLifecycle(t *testing.T) { t.Fatal("新库不应已初始化") } + // ok、err 保存ok、err,供当前处理流程使用 ok, err := s.Users.Create(ctx, "admin", "admin@example.com", "pw123") if err != nil || !ok { t.Fatalf("Create: ok=%v err=%v", ok, err) } - if err := s.Users.SetAdmin(ctx, "admin"); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Users.SetAdmin(ctx, "admin"); err != nil { t.Fatalf("SetAdmin: %v", err) } - if init, _ := s.Users.IsSystemInitialized(ctx); !init { + if // init 保存init,供当前处理流程使用 + init, _ := s.Users.IsSystemInitialized(ctx); !init { t.Fatal("创建 admin 后应已初始化") } @@ -81,10 +95,12 @@ func TestUserLifecycle(t *testing.T) { // 改密后旧密码失效。 _, _ = s.Users.UpdatePassword(ctx, "admin", "newpw") + // okOld 保存okOld,供当前处理流程使用 _, okOld, _ := s.Users.VerifyAndUpgrade(ctx, "admin", "pw123") if okOld { t.Fatal("旧密码应失效") } + // okNew 保存okNew,供当前处理流程使用 _, okNew, _ := s.Users.VerifyAndUpgrade(ctx, "admin", "newpw") if !okNew { t.Fatal("新密码应可用") @@ -93,35 +109,45 @@ func TestUserLifecycle(t *testing.T) { // TestSessionRoundTrip 创建→读取→删除。 func TestSessionRoundTrip(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() s.Users.Create(ctx, "u1", "u1@e.com", "pw") + // user 保存用户,供当前处理流程使用 user, _, _ := s.Users.VerifyAndUpgrade(ctx, "u1", "pw") + // sid、err 保存sid、err,供当前处理流程使用 sid, err := s.Sessions.Create(ctx, user) if err != nil { t.Fatalf("Create session: %v", err) } + // got、err 保存got、err,供当前处理流程使用 got, err := s.Sessions.Get(ctx, sid) if err != nil || got == nil || got.UserID != user.ID { t.Fatalf("Get session: got=%+v err=%v", got, err) } - if err := s.Sessions.Delete(ctx, sid); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Sessions.Delete(ctx, sid); err != nil { t.Fatalf("Delete: %v", err) } - if _, err := s.Sessions.Get(ctx, sid); err != ErrNotFound { + if // err 保存err,供当前处理流程使用 + _, err := s.Sessions.Get(ctx, sid); err != ErrNotFound { t.Fatalf("删除后应 ErrNotFound,got err=%v", err) } } // TestCookieSaveRequiresInit 未初始化时 Save 应报错(不兜底 user_id=1)。 func TestCookieSaveRequiresInit(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // err 保存err,供当前处理流程使用 err := s.Cookies.Save(ctx, "cid", "cookievalue", 0) if err == nil { t.Fatal("系统未初始化时 Save cookie 应报错") @@ -129,50 +155,67 @@ func TestCookieSaveRequiresInit(t *testing.T) { // 初始化 admin 后,用其 user_id 保存。 s.Users.Create(ctx, "admin", "a@e.com", "pw") + // admin 保存admin,供当前处理流程使用 admin, _ := s.Users.GetByUsername(ctx, "admin") - if err := s.Cookies.Save(ctx, "cid", "cookievalue", admin.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.Save(ctx, "cid", "cookievalue", admin.ID); err != nil { t.Fatalf("Save: %v", err) } + // d、err 保存d、err,供当前处理流程使用 d, err := s.Cookies.GetDetails(ctx, "cid") if err != nil || d.Value != "cookievalue" || d.PauseDuration != 10 { t.Fatalf("GetDetails: %+v err=%v", d, err) } + // all 保存all,供当前处理流程使用 all, _ := s.Cookies.AllForUser(ctx, admin.ID) if all["cid"] != "cookievalue" { t.Fatalf("AllForUser: %v", all) } - if pd := s.Cookies.GetPauseDuration(ctx, "cid"); pd != 10 { + if // pd 保存pd,供当前处理流程使用 + pd := s.Cookies.GetPauseDuration(ctx, "cid"); pd != 10 { t.Fatalf("GetPauseDuration=%d want 10", pd) } - if enabled, err := s.Cookies.GetAutoConfirm(ctx, "cid"); err != nil || !enabled { + if // enabled、err 保存enabled、err,供当前处理流程使用 + enabled, err := s.Cookies.GetAutoConfirm(ctx, "cid"); err != nil || !enabled { t.Fatalf("GetAutoConfirm=%v want true, err=%v", enabled, err) } - if _, err := s.DB.ExecContext(ctx, `UPDATE cookies SET auto_confirm=0 WHERE id=?`, "cid"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `UPDATE cookies SET auto_confirm=0 WHERE id=?`, "cid"); err != nil { t.Fatalf("关闭 auto_confirm: %v", err) } - if enabled, err := s.Cookies.GetAutoConfirm(ctx, "cid"); err != nil || enabled { + if // enabled、err 保存enabled、err,供当前处理流程使用 + enabled, err := s.Cookies.GetAutoConfirm(ctx, "cid"); err != nil || enabled { t.Fatalf("GetAutoConfirm=%v want false, err=%v", enabled, err) } } +// TestCookieLoginAudit 负责Test登录凭证登录Audit相关处理。 func TestCookieLoginAudit(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if _, err := s.Users.Create(ctx, "admin", "a@e.com", "pw"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := s.Users.Create(ctx, "admin", "a@e.com", "pw"); err != nil { t.Fatalf("Create user: %v", err) } + // admin 保存admin,供当前处理流程使用 admin, _ := s.Users.GetByUsername(ctx, "admin") - if err := s.Cookies.Save(ctx, "cid", "cookievalue", admin.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.Save(ctx, "cid", "cookievalue", admin.ID); err != nil { t.Fatalf("Save cookie: %v", err) } - if err := s.Cookies.UpdateLoginInfo(ctx, "cid", "login-user", "secret", true); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.UpdateLoginInfo(ctx, "cid", "login-user", "secret", true); err != nil { t.Fatalf("UpdateLoginInfo: %v", err) } - if err := s.Cookies.MarkLogin(ctx, "cid", "password", 12345); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.Cookies.MarkLogin(ctx, "cid", "password", 12345); err != nil { t.Fatalf("MarkLogin: %v", err) } + // d、err 保存d、err,供当前处理流程使用 d, err := s.Cookies.GetDetails(ctx, "cid") if err != nil { t.Fatalf("GetDetails: %v", err) @@ -184,12 +227,15 @@ func TestCookieLoginAudit(t *testing.T) { t.Fatalf("登录审计字段异常: method=%q at=%d", d.LoginMethod, d.LastLoginAt) } - if err := s.LoginLogs.Add(ctx, AccountLoginLog{CookieID: "cid", UserID: admin.ID, Method: "password", Status: "failed", Message: "wrong", CreatedAt: 10}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.LoginLogs.Add(ctx, AccountLoginLog{CookieID: "cid", UserID: admin.ID, Method: "password", Status: "failed", Message: "wrong", CreatedAt: 10}); err != nil { t.Fatalf("Add log failed: %v", err) } - if err := s.LoginLogs.Add(ctx, AccountLoginLog{CookieID: "cid", UserID: admin.ID, Method: "password", Status: "success", Message: "ok", CreatedAt: 20}); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.LoginLogs.Add(ctx, AccountLoginLog{CookieID: "cid", UserID: admin.ID, Method: "password", Status: "success", Message: "ok", CreatedAt: 20}); err != nil { t.Fatalf("Add log success: %v", err) } + // logs、err 保存logs、err,供当前处理流程使用 logs, err := s.LoginLogs.ListByCookie(ctx, "cid", 10) if err != nil { t.Fatalf("ListByCookie: %v", err) diff --git a/internal/db/risk_control_logs.go b/internal/db/risk_control_logs.go index da1a3e3..154b88b 100644 --- a/internal/db/risk_control_logs.go +++ b/internal/db/risk_control_logs.go @@ -33,6 +33,7 @@ func (r *RiskControlLogs) Update(ctx context.Context, id int64, log RiskControlL if id == 0 { return nil } + // err 保存err,供当前处理流程使用 _, err := r.DB.ExecContext(ctx, `UPDATE risk_control_logs SET processing_result=?, processing_status=?, captcha_engine=?, diff --git a/internal/db/secrets.go b/internal/db/secrets.go index d89d8cc..ac83c77 100644 --- a/internal/db/secrets.go +++ b/internal/db/secrets.go @@ -14,6 +14,7 @@ import ( "strings" ) +// encryptedValuePrefix 保存encrypted值Prefix,供当前处理流程使用 const ( encryptedValuePrefix = "enc:v1:" cookieMetadataScope = "cookie-metadata" @@ -21,23 +22,31 @@ const ( // secretCodec 对数据库敏感字段做 AES-256-GCM 信封加密。未配置密钥时保持 // 明文兼容;已加密数据若缺少/使用错误密钥会明确报错,绝不把密文当凭证使用。 +// secretCodec 保存secretCodec,供当前处理流程使用 type secretCodec struct{ aead cipher.AEAD } +// secretCodecFromEnvironment 负责secretCodecFromEnvironment相关处理。 func secretCodecFromEnvironment() *secretCodec { + // codec 保存codec,供当前处理流程使用 codec, _ := newSecretCodec(strings.TrimSpace(os.Getenv("XIANYU_DATA_KEY"))) return codec } +// newSecretCodec 负责newSecretCodec相关处理。 func newSecretCodec(key string) (*secretCodec, error) { + // codec 保存codec,供当前处理流程使用 codec := &secretCodec{} if key == "" { return codec, nil } + // digest 保存digest,供当前处理流程使用 digest := sha256.Sum256([]byte(key)) + // block、err 保存block、err,供当前处理流程使用 block, err := aes.NewCipher(digest[:]) if err != nil { return nil, err } + // aead、err 保存aead、err,供当前处理流程使用 aead, err := cipher.NewGCM(block) if err != nil { return nil, err @@ -46,12 +55,14 @@ func newSecretCodec(key string) (*secretCodec, error) { return codec, nil } +// encrypt 负责encrypt相关处理。 func (c *secretCodec) encrypt(scope, owner, value string) (string, error) { if value == "" { return value, nil } if strings.HasPrefix(value, encryptedValuePrefix) { - if _, err := c.decrypt(scope, owner, value); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := c.decrypt(scope, owner, value); err != nil { return "", err } return value, nil @@ -59,106 +70,136 @@ func (c *secretCodec) encrypt(scope, owner, value string) (string, error) { if c == nil || c.aead == nil { return value, nil } + // nonce 保存nonce,供当前处理流程使用 nonce := make([]byte, c.aead.NonceSize()) - if _, err := io.ReadFull(rand.Reader, nonce); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := io.ReadFull(rand.Reader, nonce); err != nil { return "", err } + // sealed 保存sealed,供当前处理流程使用 sealed := c.aead.Seal(nonce, nonce, []byte(value), []byte(scope+"\x00"+owner)) return encryptedValuePrefix + base64.RawStdEncoding.EncodeToString(sealed), nil } // EncryptLegacySecrets 将启用 XIANYU_DATA_KEY 前写入的明文敏感字段原地升级。 // 已加密行同时用于校验当前密钥,错误密钥会在启动业务 worker 前失败。 +// EncryptLegacySecrets 负责EncryptLegacySecrets相关处理。 func (s *Store) EncryptLegacySecrets(ctx context.Context) error { if s == nil || s.DB == nil { return nil } + // codec 保存codec,供当前处理流程使用 codec := s.Cookies.codec + // tx、err 保存tx、err,供当前处理流程使用 tx, err := s.DB.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() + // cookieSecret 保存登录凭证Secret,供当前处理流程使用 type cookieSecret struct{ id, value, password, metadata string } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := tx.QueryContext(ctx, `SELECT id,value,COALESCE(password,''),COALESCE(metadata_json,'') FROM cookies`) if err != nil { return err } + // cookies 保存cookies,供当前处理流程使用 var cookies []cookieSecret for rows.Next() { + // row 保存row,供当前处理流程使用 var row cookieSecret - if err := rows.Scan(&row.id, &row.value, &row.password, &row.metadata); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&row.id, &row.value, &row.password, &row.metadata); err != nil { rows.Close() return err } cookies = append(cookies, row) } - if err := rows.Close(); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Close(); err != nil { return err } + // row 表示当前遍历过程中的row for _, row := range cookies { + // value、err 保存value、err,供当前处理流程使用 value, err := codec.encrypt("cookie", row.id, row.value) if err != nil { return fmt.Errorf("校验账号 %s Cookie: %w", row.id, err) } + // password、err 保存password、err,供当前处理流程使用 password, err := codec.encrypt("login-password", row.id, row.password) if err != nil { return fmt.Errorf("校验账号 %s 登录密码: %w", row.id, err) } + // metadata、err 保存metadata、err,供当前处理流程使用 metadata, err := codec.encrypt(cookieMetadataScope, row.id, row.metadata) if err != nil { return fmt.Errorf("校验账号 %s Cookie metadata: %w", row.id, err) } if value != row.value || password != row.password || metadata != row.metadata { - if _, err := tx.ExecContext(ctx, `UPDATE cookies SET value=?,password=?,metadata_json=? WHERE id=?`, value, password, metadata, row.id); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `UPDATE cookies SET value=?,password=?,metadata_json=? WHERE id=?`, value, password, metadata, row.id); err != nil { return err } } } + // tokenSecret 保存令牌Secret,供当前处理流程使用 type tokenSecret struct{ cookieID, deviceID, accessToken string } rows, err = tx.QueryContext(ctx, `SELECT cookie_id,device_id,access_token FROM account_tokens`) if err != nil { return err } + // tokens 保存tokens,供当前处理流程使用 var tokens []tokenSecret for rows.Next() { + // row 保存row,供当前处理流程使用 var row tokenSecret - if err := rows.Scan(&row.cookieID, &row.deviceID, &row.accessToken); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&row.cookieID, &row.deviceID, &row.accessToken); err != nil { rows.Close() return err } tokens = append(tokens, row) } - if err := rows.Close(); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Close(); err != nil { return err } + // row 表示当前遍历过程中的row for _, row := range tokens { + // deviceID、err 保存deviceID、err,供当前处理流程使用 deviceID, err := codec.encrypt("device-id", row.cookieID, row.deviceID) if err != nil { return err } + // accessToken、err 保存accessToken、err,供当前处理流程使用 accessToken, err := codec.encrypt("access-token", row.cookieID, row.accessToken) if err != nil { return err } if deviceID != row.deviceID || accessToken != row.accessToken { - if _, err := tx.ExecContext(ctx, `UPDATE account_tokens SET device_id=?,access_token=? WHERE cookie_id=?`, deviceID, accessToken, row.cookieID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `UPDATE account_tokens SET device_id=?,access_token=? WHERE cookie_id=?`, deviceID, accessToken, row.cookieID); err != nil { return err } } } + // keyCol 保存keyCol,供当前处理流程使用 keyCol := dialectQuote(s.Dialect, "key") rows, err = tx.QueryContext(ctx, `SELECT `+keyCol+`,value FROM system_settings`) if err != nil { return err } + // settings 保存设置,供当前处理流程使用 settings := make(map[string]string) for rows.Next() { + // key、value 保存key、value,供当前处理流程使用 var key, value string - if err := rows.Scan(&key, &value); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&key, &value); err != nil { rows.Close() return err } @@ -166,21 +207,26 @@ func (s *Store) EncryptLegacySecrets(ctx context.Context) error { settings[key] = value } } - if err := rows.Close(); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Close(); err != nil { return err } + // key、value 表示当前遍历过程中的key、value for key, value := range settings { + // encrypted、err 保存encrypted、err,供当前处理流程使用 encrypted, err := codec.encrypt("system-setting", key, value) if err != nil { return err } if encrypted != value { - if _, err := tx.ExecContext(ctx, `UPDATE system_settings SET value=? WHERE `+keyCol+`=?`, encrypted, key); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `UPDATE system_settings SET value=? WHERE `+keyCol+`=?`, encrypted, key); err != nil { return err } } } + // channelSecret 保存渠道Secret,供当前处理流程使用 type channelSecret struct { id, userID int64 config string @@ -189,25 +235,32 @@ func (s *Store) EncryptLegacySecrets(ctx context.Context) error { if err != nil { return err } + // channels 保存渠道列表,供当前处理流程使用 var channels []channelSecret for rows.Next() { + // row 保存row,供当前处理流程使用 var row channelSecret - if err := rows.Scan(&row.id, &row.userID, &row.config); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&row.id, &row.userID, &row.config); err != nil { rows.Close() return err } channels = append(channels, row) } - if err := rows.Close(); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Close(); err != nil { return err } + // row 表示当前遍历过程中的row for _, row := range channels { + // encrypted、err 保存encrypted、err,供当前处理流程使用 encrypted, err := codec.encrypt("notification-config", fmt.Sprint(row.userID), row.config) if err != nil { return err } if encrypted != row.config { - if _, err := tx.ExecContext(ctx, `UPDATE notification_channels SET config=? WHERE id=?`, encrypted, row.id); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `UPDATE notification_channels SET config=? WHERE id=?`, encrypted, row.id); err != nil { return err } } @@ -216,6 +269,7 @@ func (s *Store) EncryptLegacySecrets(ctx context.Context) error { return tx.Commit() } +// decrypt 负责decrypt相关处理。 func (c *secretCodec) decrypt(scope, owner, value string) (string, error) { if !strings.HasPrefix(value, encryptedValuePrefix) { return value, nil @@ -223,11 +277,14 @@ func (c *secretCodec) decrypt(scope, owner, value string) (string, error) { if c == nil || c.aead == nil { return "", errors.New("数据库包含加密凭证,但 XIANYU_DATA_KEY 未配置") } + // raw、err 保存raw、err,供当前处理流程使用 raw, err := base64.RawStdEncoding.DecodeString(strings.TrimPrefix(value, encryptedValuePrefix)) if err != nil || len(raw) < c.aead.NonceSize() { return "", fmt.Errorf("敏感字段密文格式无效") } + // nonce 保存nonce,供当前处理流程使用 nonce := raw[:c.aead.NonceSize()] + // plain、err 保存plain、err,供当前处理流程使用 plain, err := c.aead.Open(nil, nonce, raw[c.aead.NonceSize():], []byte(scope+"\x00"+owner)) if err != nil { return "", errors.New("敏感字段解密失败,请检查 XIANYU_DATA_KEY") @@ -235,6 +292,7 @@ func (c *secretCodec) decrypt(scope, owner, value string) (string, error) { return string(plain), nil } +// isSensitiveSettingKey 负责isSensitive设置Key相关处理。 func isSensitiveSettingKey(key string) bool { switch strings.ToLower(strings.TrimSpace(key)) { case "ai_api_key", "smtp_password", "qq_reply_secret_key", "captcha.remote_secret_key": diff --git a/internal/db/secrets_test.go b/internal/db/secrets_test.go index 49ebce4..b1461bf 100644 --- a/internal/db/secrets_test.go +++ b/internal/db/secrets_test.go @@ -7,30 +7,41 @@ import ( "time" ) +// TestSensitiveRepositoriesEncryptAtRestAndDecryptOnRead 负责TestSensitiveRepositoriesEncryptAtRestAndDecryptOnRead相关处理。 func TestSensitiveRepositoriesEncryptAtRestAndDecryptOnRead(t *testing.T) { t.Setenv("XIANYU_DATA_KEY", "unit-test-data-key") + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if ok, err := store.Users.Create(ctx, "secret-owner", "secret-owner@example.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := store.Users.Create(ctx, "secret-owner", "secret-owner@example.com", "pw"); err != nil || !ok { t.Fatalf("create owner: ok=%v err=%v", ok, err) } + // owner 保存所有者,供当前处理流程使用 owner, _ := store.Users.GetByUsername(ctx, "secret-owner") - if err := store.Cookies.CreateOwned(ctx, "secret-cookie", "unb=secret; token=plain", owner.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.CreateOwned(ctx, "secret-cookie", "unb=secret; token=plain", owner.ID); err != nil { t.Fatal(err) } - if err := store.Cookies.UpdateLoginInfo(ctx, "secret-cookie", "login", "password-plain", false); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.UpdateLoginInfo(ctx, "secret-cookie", "login", "password-plain", false); err != nil { t.Fatal(err) } - if err := store.Tokens.Save(ctx, "secret-cookie", "device-plain", "access-plain", time.Now().Add(time.Hour).Unix()); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Tokens.Save(ctx, "secret-cookie", "device-plain", "access-plain", time.Now().Add(time.Hour).Unix()); err != nil { t.Fatal(err) } - if err := store.Settings.Set(ctx, "ai_api_key", "sk-plain"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, "ai_api_key", "sk-plain"); err != nil { t.Fatal(err) } - if err := store.Settings.Set(ctx, "captcha.remote_secret_key", "captcha-secret-plain"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, "captcha.remote_secret_key", "captcha-secret-plain"); err != nil { t.Fatal(err) } + // channelID、err 保存渠道ID、err,供当前处理流程使用 channelID, err := store.Notifications.CreateChannel(ctx, &NotificationChannelRow{ Name: "secret", Type: "webhook", Config: `{"webhook_url":"https://example.test/plain-token"}`, Enabled: true, UserID: owner.ID, }) @@ -38,94 +49,127 @@ func TestSensitiveRepositoriesEncryptAtRestAndDecryptOnRead(t *testing.T) { t.Fatal(err) } + // rawCookie、rawPassword、rawDevice、rawToken、rawSetting、rawCaptchaSecret、rawConfig 保存原始Cookie、rawPassword、rawDevice、rawToken、rawSetting、rawCaptchaSecret、raw配置,供当前处理流程使用 var rawCookie, rawPassword, rawDevice, rawToken, rawSetting, rawCaptchaSecret, rawConfig string - if err := store.DB.QueryRowContext(ctx, `SELECT value,password FROM cookies WHERE id=?`, "secret-cookie").Scan(&rawCookie, &rawPassword); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT value,password FROM cookies WHERE id=?`, "secret-cookie").Scan(&rawCookie, &rawPassword); err != nil { t.Fatal(err) } - if err := store.DB.QueryRowContext(ctx, `SELECT device_id,access_token FROM account_tokens WHERE cookie_id=?`, "secret-cookie").Scan(&rawDevice, &rawToken); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT device_id,access_token FROM account_tokens WHERE cookie_id=?`, "secret-cookie").Scan(&rawDevice, &rawToken); err != nil { t.Fatal(err) } + // keyCol 保存keyCol,供当前处理流程使用 keyCol := dialectQuote(store.Dialect, "key") - if err := store.DB.QueryRowContext(ctx, `SELECT value FROM system_settings WHERE `+keyCol+`=?`, "ai_api_key").Scan(&rawSetting); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT value FROM system_settings WHERE `+keyCol+`=?`, "ai_api_key").Scan(&rawSetting); err != nil { t.Fatal(err) } - if err := store.DB.QueryRowContext(ctx, `SELECT value FROM system_settings WHERE `+keyCol+`=?`, "captcha.remote_secret_key").Scan(&rawCaptchaSecret); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT value FROM system_settings WHERE `+keyCol+`=?`, "captcha.remote_secret_key").Scan(&rawCaptchaSecret); err != nil { t.Fatal(err) } - if err := store.DB.QueryRowContext(ctx, `SELECT config FROM notification_channels WHERE id=?`, channelID).Scan(&rawConfig); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT config FROM notification_channels WHERE id=?`, channelID).Scan(&rawConfig); err != nil { t.Fatal(err) } + // name、raw 表示当前遍历过程中的name、raw for name, raw := range map[string]string{"cookie": rawCookie, "password": rawPassword, "device": rawDevice, "token": rawToken, "setting": rawSetting, "captcha-secret": rawCaptchaSecret, "config": rawConfig} { if !strings.HasPrefix(raw, encryptedValuePrefix) || strings.Contains(raw, "plain") { t.Fatalf("%s was not encrypted at rest: %q", name, raw) } } + // detail、err 保存detail、err,供当前处理流程使用 detail, err := store.Cookies.GetDetails(ctx, "secret-cookie") if err != nil || detail.Value != "unb=secret; token=plain" || detail.Password != "password-plain" { t.Fatalf("cookie detail=%+v err=%v", detail, err) } + // token、err 保存token、err,供当前处理流程使用 token, err := store.Tokens.Get(ctx, "secret-cookie") if err != nil || token.DeviceID != "device-plain" || token.AccessToken != "access-plain" { t.Fatalf("token=%+v err=%v", token, err) } - if setting, err := store.Settings.Get(ctx, "ai_api_key"); err != nil || setting != "sk-plain" { + if // setting、err 保存setting、err,供当前处理流程使用 + setting, err := store.Settings.Get(ctx, "ai_api_key"); err != nil || setting != "sk-plain" { t.Fatalf("setting=%q err=%v", setting, err) } - if setting, err := store.Settings.Get(ctx, "captcha.remote_secret_key"); err != nil || setting != "captcha-secret-plain" { + if // setting、err 保存setting、err,供当前处理流程使用 + setting, err := store.Settings.Get(ctx, "captcha.remote_secret_key"); err != nil || setting != "captcha-secret-plain" { t.Fatalf("captcha secret=%q err=%v", setting, err) } + // channel、err 保存channel、err,供当前处理流程使用 channel, err := store.Notifications.GetChannel(ctx, channelID) if err != nil || channel == nil || !strings.Contains(channel.Config, "plain-token") { t.Fatalf("channel=%+v err=%v", channel, err) } } +// TestSecretCodecReadsLegacyPlaintextAndRejectsWrongKey 负责TestSecretCodecReadsLegacyPlaintextAndRejectsWrongKey相关处理。 func TestSecretCodecReadsLegacyPlaintextAndRejectsWrongKey(t *testing.T) { + // codec 保存codec,供当前处理流程使用 codec, _ := newSecretCodec("correct") + // encrypted、err 保存encrypted、err,供当前处理流程使用 encrypted, err := codec.encrypt("cookie", "owner", "secret") if err != nil { t.Fatal(err) } - if plain, err := codec.decrypt("cookie", "owner", "legacy-plaintext"); err != nil || plain != "legacy-plaintext" { + if // plain、err 保存plain、err,供当前处理流程使用 + plain, err := codec.decrypt("cookie", "owner", "legacy-plaintext"); err != nil || plain != "legacy-plaintext" { t.Fatalf("legacy plain=%q err=%v", plain, err) } + // wrong 保存wrong,供当前处理流程使用 wrong, _ := newSecretCodec("wrong") - if _, err := wrong.decrypt("cookie", "owner", encrypted); err == nil { + if // err 保存err,供当前处理流程使用 + _, err := wrong.decrypt("cookie", "owner", encrypted); err == nil { t.Fatal("wrong key must not return ciphertext as plaintext") } + // withoutKey 保存withoutKey,供当前处理流程使用 withoutKey, _ := newSecretCodec("") - if _, err := withoutKey.decrypt("cookie", "owner", encrypted); err == nil { + if // err 保存err,供当前处理流程使用 + _, err := withoutKey.decrypt("cookie", "owner", encrypted); err == nil { t.Fatal("missing key must reject encrypted data") } } +// TestEncryptLegacySecretsUpgradesPlaintextAndValidatesKey 负责TestEncryptLegacySecretsUpgradesPlaintextAndValidatesKey相关处理。 func TestEncryptLegacySecretsUpgradesPlaintextAndValidatesKey(t *testing.T) { t.Setenv("XIANYU_DATA_KEY", "migration-key") + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newTestDB(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if ok, err := store.Users.Create(ctx, "legacy-owner", "legacy-owner@example.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := store.Users.Create(ctx, "legacy-owner", "legacy-owner@example.com", "pw"); err != nil || !ok { t.Fatalf("create owner: ok=%v err=%v", ok, err) } + // owner 保存所有者,供当前处理流程使用 owner, _ := store.Users.GetByUsername(ctx, "legacy-owner") - if _, err := store.DB.ExecContext(ctx, `INSERT INTO cookies (id,value,user_id,password) VALUES (?,?,?,?)`, "legacy-secret", "legacy-cookie", owner.ID, "legacy-password"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `INSERT INTO cookies (id,value,user_id,password) VALUES (?,?,?,?)`, "legacy-secret", "legacy-cookie", owner.ID, "legacy-password"); err != nil { t.Fatal(err) } - if err := store.EncryptLegacySecrets(ctx); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.EncryptLegacySecrets(ctx); err != nil { t.Fatal(err) } + // raw 保存原始,供当前处理流程使用 var raw string - if err := store.DB.QueryRowContext(ctx, `SELECT value FROM cookies WHERE id='legacy-secret'`).Scan(&raw); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT value FROM cookies WHERE id='legacy-secret'`).Scan(&raw); err != nil { t.Fatal(err) } if !strings.HasPrefix(raw, encryptedValuePrefix) { t.Fatalf("legacy value was not upgraded: %q", raw) } + // wrongCodec 保存wrongCodec,供当前处理流程使用 wrongCodec, _ := newSecretCodec("wrong-key") + // wrongStore 保存wrongStore,供当前处理流程使用 wrongStore := NewStore(store.DB, store.Dialect) wrongStore.Cookies.codec = wrongCodec - if err := wrongStore.EncryptLegacySecrets(ctx); err == nil { + if // err 保存err,供当前处理流程使用 + err := wrongStore.EncryptLegacySecrets(ctx); err == nil { t.Fatal("startup validation must reject the wrong data key") } } diff --git a/internal/db/sessions.go b/internal/db/sessions.go index eb1dda0..100559e 100644 --- a/internal/db/sessions.go +++ b/internal/db/sessions.go @@ -21,12 +21,16 @@ type Sessions struct { // Create 为已认证用户创建会话,返回 session_id。 func (s *Sessions) Create(ctx context.Context, u *User) (string, error) { + // sessionID、err 保存会话ID、err,供当前处理流程使用 sessionID, err := randomSessionID() if err != nil { return "", fmt.Errorf("生成 session id: %w", err) } + // now 保存now,供当前处理流程使用 now := time.Now().Unix() + // expires 保存expires,供当前处理流程使用 expires := now + int64(SessionTTL.Seconds()) + // isAdmin 保存isAdmin,供当前处理流程使用 isAdmin := 0 if u.IsAdmin { isAdmin = 1 @@ -46,8 +50,11 @@ func (s *Sessions) Get(ctx context.Context, sessionID string) (*Session, error) if sessionID == "" { return nil, ErrNotFound } + // sess 保存sess,供当前处理流程使用 var sess Session + // isAdmin 保存isAdmin,供当前处理流程使用 var isAdmin int + // err 保存err,供当前处理流程使用 err := s.DB.QueryRowContext(ctx, `SELECT s.session_id, s.user_id, u.username, u.is_admin, s.expires_at FROM sessions s @@ -70,24 +77,29 @@ func (s *Sessions) Get(ctx context.Context, sessionID string) (*Session, error) // Delete 删除会话(登出)。 func (s *Sessions) Delete(ctx context.Context, sessionID string) error { + // err 保存err,供当前处理流程使用 _, err := s.DB.ExecContext(ctx, `DELETE FROM sessions WHERE session_id=?`, sessionID) return err } // DeleteExpired 清理所有过期会话(可由定时任务调用)。 func (s *Sessions) DeleteExpired(ctx context.Context) (int64, error) { + // res、err 保存res、err,供当前处理流程使用 res, err := s.DB.ExecContext(ctx, `DELETE FROM sessions WHERE expires_at <= ?`, time.Now().Unix()) if err != nil { return 0, err } + // n 保存n,供当前处理流程使用 n, _ := res.RowsAffected() return n, nil } // randomSessionID 生成 URL 安全的随机会话 ID。 func randomSessionID() (string, error) { + // b 保存b,供当前处理流程使用 b := make([]byte, 32) - if _, err := rand.Read(b); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := rand.Read(b); err != nil { return "", err } return base64.RawURLEncoding.EncodeToString(b), nil diff --git a/internal/db/store.go b/internal/db/store.go index c4ae58e..22da873 100644 --- a/internal/db/store.go +++ b/internal/db/store.go @@ -40,6 +40,7 @@ type Store struct { // NewStore 基于 *sql.DB 构造聚合 store。dialect 用于业务 SQL 方言分支。 func NewStore(db *sql.DB, dialect Dialect) *Store { + // codec 保存codec,供当前处理流程使用 codec := secretCodecFromEnvironment() return &Store{ DB: db, @@ -75,6 +76,7 @@ func NewStore(db *sql.DB, dialect Dialect) *Store { // LockAccountCredentials serializes Cookie/token state transitions for one // account across the IM runtime and renewal scheduler. The returned function // must be called exactly once. +// LockAccountCredentials 负责锁账号Credentials相关处理。 func (s *Store) LockAccountCredentials(cookieID string) func() { if s == nil { return func() {} @@ -83,6 +85,7 @@ func (s *Store) LockAccountCredentials(cookieID string) func() { if s.credentialLocks == nil { s.credentialLocks = make(map[string]*sync.Mutex) } + // lock 保存锁,供当前处理流程使用 lock := s.credentialLocks[cookieID] if lock == nil { lock = &sync.Mutex{} diff --git a/internal/db/users.go b/internal/db/users.go index 0765444..33f38bd 100644 --- a/internal/db/users.go +++ b/internal/db/users.go @@ -27,8 +27,11 @@ type Users struct { // IsSystemInitialized 系统是否已初始化(至少存在 admin 用户)。 // IsSystemInitialized 判断系统是否已有管理员账号。 +// IsSystemInitialized 负责Is系统Initialized相关处理。 func (u *Users) IsSystemInitialized(ctx context.Context) (bool, error) { + // exists 保存exists,供当前处理流程使用 var exists bool + // err 保存err,供当前处理流程使用 err := u.DB.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM users WHERE is_admin=1)`).Scan(&exists) if err != nil { return false, fmt.Errorf("检查系统初始化: %w", err) @@ -44,11 +47,14 @@ func (u *Users) GetAdmin(ctx context.Context) (*User, error) { // Create 创建用户,密码用 bcrypt 哈希。 // 用户名或邮箱重复时返回 false。 +// Create 创建当前值。 func (u *Users) Create(ctx context.Context, username, email, plainPassword string) (bool, error) { + // hash、err 保存hash、err,供当前处理流程使用 hash, err := HashPassword(plainPassword) if err != nil { return false, fmt.Errorf("哈希密码: %w", err) } + // res、err 保存res、err,供当前处理流程使用 res, err := u.DB.ExecContext(ctx, `INSERT INTO users (username, email, password_hash) VALUES (?, ?, ?)`, username, email, hash) @@ -58,19 +64,24 @@ func (u *Users) Create(ctx context.Context, username, email, plainPassword strin } return false, fmt.Errorf("创建用户: %w", err) } + // n 保存n,供当前处理流程使用 n, _ := res.RowsAffected() return n > 0, nil } +// isUniqueViolation 负责isUniqueViolation相关处理。 func isUniqueViolation(err error) bool { + // mysqlErr 保存mysqlErr,供当前处理流程使用 var mysqlErr *mysql.MySQLError if errors.As(err, &mysqlErr) { return mysqlErr.Number == 1062 } + // pgErr 保存pgErr,供当前处理流程使用 var pgErr *pgconn.PgError if errors.As(err, &pgErr) { return pgErr.Code == "23505" } + // message 保存消息,供当前处理流程使用 message := strings.ToLower(err.Error()) return strings.Contains(message, "unique constraint") || strings.Contains(message, "constraint failed") } @@ -95,7 +106,9 @@ func (u *Users) GetByID(ctx context.Context, id int64) (*User, error) { // VerifyAndUpgrade 验证密码;若命中老 SHA-256 哈希则静默升级到 bcrypt。 // 返回 (user, ok)。ok=false 表示密码错误或用户不存在/未激活。 +// VerifyAndUpgrade 负责VerifyAndUpgrade相关处理。 func (u *Users) VerifyAndUpgrade(ctx context.Context, username, plainPassword string) (*User, bool, error) { + // user、err 保存user、err,供当前处理流程使用 user, err := u.GetByUsername(ctx, username) if err != nil { if errors.Is(err, ErrNotFound) { @@ -106,6 +119,7 @@ func (u *Users) VerifyAndUpgrade(ctx context.Context, username, plainPassword st if !user.IsActive { return nil, false, nil } + // matched、needsUpgrade、err 保存matched、needsUpgrade、err,供当前处理流程使用 matched, needsUpgrade, err := VerifyPassword(user.PasswordHash, plainPassword) if err != nil || !matched { return nil, false, err @@ -124,31 +138,38 @@ func (u *Users) VerifyAndUpgrade(ctx context.Context, username, plainPassword st // UpdatePassword 更新密码(bcrypt)。返回是否找到用户。 func (u *Users) UpdatePassword(ctx context.Context, username, plainPassword string) (bool, error) { + // hash、err 保存hash、err,供当前处理流程使用 hash, err := HashPassword(plainPassword) if err != nil { return false, fmt.Errorf("哈希密码: %w", err) } + // tx、err 保存tx、err,供当前处理流程使用 tx, err := u.DB.BeginTx(ctx, nil) if err != nil { return false, err } defer tx.Rollback() + // userID 保存用户ID,供当前处理流程使用 var userID int64 + // res、err 保存res、err,供当前处理流程使用 res, err := tx.ExecContext(ctx, `UPDATE users SET password_hash=?, updated_at=CURRENT_TIMESTAMP WHERE username=?`, hash, username) if err != nil { return false, err } + // n 保存n,供当前处理流程使用 n, _ := res.RowsAffected() if n == 0 { return false, nil } - if err := tx.QueryRowContext(ctx, `SELECT id FROM users WHERE username=?`, username).Scan(&userID); err != nil { + if // err 保存err,供当前处理流程使用 + err := tx.QueryRowContext(ctx, `SELECT id FROM users WHERE username=?`, username).Scan(&userID); err != nil { return false, err } - if _, err := tx.ExecContext(ctx, `DELETE FROM sessions WHERE user_id=?`, userID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `DELETE FROM sessions WHERE user_id=?`, userID); err != nil { return false, err } return true, tx.Commit() @@ -156,14 +177,17 @@ func (u *Users) UpdatePassword(ctx context.Context, username, plainPassword stri // UpdateCredentials 原子更新用户名及可选密码,并撤销该用户的全部登录会话。 func (u *Users) UpdateCredentials(ctx context.Context, userID int64, username, plainPassword string) error { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := u.DB.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() + // exists 保存exists,供当前处理流程使用 var exists bool - if err := tx.QueryRowContext(ctx, + if // err 保存err,供当前处理流程使用 + err := tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM users WHERE username=? AND id<>?)`, username, userID).Scan(&exists); err != nil { return err } @@ -171,8 +195,10 @@ func (u *Users) UpdateCredentials(ctx context.Context, userID int64, username, p return ErrUsernameTaken } + // res 保存响应,供当前处理流程使用 var res sql.Result if plainPassword != "" { + // hash、hashErr 保存hash、hashErr,供当前处理流程使用 hash, hashErr := HashPassword(plainPassword) if hashErr != nil { return fmt.Errorf("哈希密码: %w", hashErr) @@ -187,10 +213,12 @@ func (u *Users) UpdateCredentials(ctx context.Context, userID int64, username, p if err != nil { return err } - if rows, _ := res.RowsAffected(); rows == 0 { + if // rows 保存rows,供当前处理流程使用 + rows, _ := res.RowsAffected(); rows == 0 { return ErrNotFound } - if _, err := tx.ExecContext(ctx, `DELETE FROM sessions WHERE user_id=?`, userID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `DELETE FROM sessions WHERE user_id=?`, userID); err != nil { return err } return tx.Commit() @@ -198,29 +226,36 @@ func (u *Users) UpdateCredentials(ctx context.Context, userID int64, username, p // Delete 删除用户,并撤销该用户的全部登录会话。 func (u *Users) Delete(ctx context.Context, userID int64) error { + // tx、err 保存tx、err,供当前处理流程使用 tx, err := u.DB.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() - if _, err := tx.ExecContext(ctx, `DELETE FROM sessions WHERE user_id=?`, userID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, `DELETE FROM sessions WHERE user_id=?`, userID); err != nil { return err } + // rows、err 保存rows、err,供当前处理流程使用 rows, err := tx.QueryContext(ctx, `SELECT id FROM cookies WHERE user_id=? ORDER BY id`, userID) if err != nil { return err } + // cookieIDs 保存登录凭证IDs,供当前处理流程使用 var cookieIDs []string for rows.Next() { + // cookieID 保存登录凭证ID,供当前处理流程使用 var cookieID string - if err := rows.Scan(&cookieID); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&cookieID); err != nil { _ = rows.Close() return err } cookieIDs = append(cookieIDs, cookieID) } - if err := rows.Close(); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Close(); err != nil { return err } // 旧 schema 中这些外键没有 ON DELETE CASCADE,必须显式清理。 @@ -229,20 +264,25 @@ func (u *Users) Delete(ctx context.Context, userID int64) error { `DELETE FROM cards WHERE user_id=?`, `DELETE FROM notification_channels WHERE user_id=?`, } { - if _, err := tx.ExecContext(ctx, query, userID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := tx.ExecContext(ctx, query, userID); err != nil { return err } } + // cookieID 表示当前遍历过程中的登录凭证ID for _, cookieID := range cookieIDs { - if err := deleteCookieTx(ctx, tx, cookieID); err != nil { + if // err 保存err,供当前处理流程使用 + err := deleteCookieTx(ctx, tx, cookieID); err != nil { return err } } + // res、err 保存res、err,供当前处理流程使用 res, err := tx.ExecContext(ctx, `DELETE FROM users WHERE id=?`, userID) if err != nil { return err } - if rows, _ := res.RowsAffected(); rows == 0 { + if // rows 保存rows,供当前处理流程使用 + rows, _ := res.RowsAffected(); rows == 0 { return ErrNotFound } return tx.Commit() @@ -250,13 +290,18 @@ func (u *Users) Delete(ctx context.Context, userID int64) error { // SetAdmin 标记用户为管理员(init-admin CLI 用)。 func (u *Users) SetAdmin(ctx context.Context, username string) error { + // err 保存err,供当前处理流程使用 _, err := u.DB.ExecContext(ctx, `UPDATE users SET is_admin=1 WHERE username=?`, username) return err } +// scanUser 负责scan用户相关处理。 func (u *Users) scanUser(ctx context.Context, query string, args ...any) (*User, error) { + // usr 保存usr,供当前处理流程使用 var usr User + // isActive、isAdmin 保存isActive、isAdmin,供当前处理流程使用 var isActive, isAdmin int + // err 保存err,供当前处理流程使用 err := u.DB.QueryRowContext(ctx, query, args...).Scan( &usr.ID, &usr.Username, &usr.Email, &usr.PasswordHash, &isActive, &isAdmin, &usr.CreatedAt, &usr.UpdatedAt) diff --git a/internal/db/ws_message.go b/internal/db/ws_message.go index 9dc4899..354ed51 100644 --- a/internal/db/ws_message.go +++ b/internal/db/ws_message.go @@ -32,9 +32,12 @@ func (w *WSMessageStore) AddBatch(ctx context.Context, messages []WSMessage) err return nil } + // query 保存查询,供当前处理流程使用 var query strings.Builder query.WriteString("INSERT INTO ws_messages (cookie_id, direction, raw_text, parsed_json, message_kind, parse_status, error, created_at) VALUES ") + // args 保存args,供当前处理流程使用 args := make([]any, 0, len(messages)*7) + // i、message 表示当前遍历过程中的i、message for i, message := range messages { if i > 0 { query.WriteByte(',') @@ -50,12 +53,14 @@ func (w *WSMessageStore) AddBatch(ctx context.Context, messages []WSMessage) err message.MessageKind, message.ParseStatus, message.Error) } + // err 保存err,供当前处理流程使用 _, err := w.DB.ExecContext(ctx, query.String(), args...) return err } // DeleteBefore 删除指定账号在 cutoff 之前的 WS 诊断消息。 func (w *WSMessageStore) DeleteBefore(ctx context.Context, cookieID string, cutoff time.Time) (int64, error) { + // result、err 保存result、err,供当前处理流程使用 result, err := w.DB.ExecContext(ctx, "DELETE FROM ws_messages WHERE cookie_id=? AND created_at < ?", cookieID, cutoff) if err != nil {