fix(sms,apps): login code no longer waits ~15s; wage quotes stop re-requesting

SMS: with SMS_RELAY_HOST unset inside Docker, every send first looked up the
server's public IP from ipify / ifconfig.me / icanhazip, one after another
with a 5s timeout each. They are unreachable from the server, and a failed
lookup was not remembered, so EVERY SMS, the login code included, waited
~15s. The three are now tried in parallel (3s), concurrent sends share one
lookup, and a failure is not retried for 10 minutes.

Apps: the server answers /customer/me/wage-quote only for variants that
exist. The store re-asked for every unanswered id from a computed, and each
answer replaced `quotes`, re-running every card, so one missing variant kept
the app posting wage-quote in a loop. Unanswered ids are now remembered, an
empty answer does not touch `quotes`, and a failed call waits 30s.

Tests: relay-host.spec (failed lookup not repeated, one shared lookup).

اپ: کد ورود بدون معطلی ارسال می‌شود.
اپ: صفحه‌ها بعد از ورود دیگر چند بار پشت سر هم بارگذاری نمی‌شوند.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
s.esmaeili
2026-10-10 16:56:30 +03:30
co-authored by Cursor
parent 840311a2a0
commit b3dae57f0b
4 changed files with 84 additions and 21 deletions
+19 -4
View File
@@ -14,6 +14,11 @@ export const useWageQuoteStore = defineStore('wageQuotes', () => {
const quotes = ref<Record<string, WageQuote>>({})
const pending = new Set<string>()
const inFlight = new Set<string>()
// Asked for but not answered: the server only returns variants that exist,
// and re-asking from a computed on every re-render looped forever.
const unanswered = new Set<string>()
// A failed call is retried, but not before this time.
let retryAfter = 0
let timer: ReturnType<typeof setTimeout> | null = null
// A different customer has a different percent: never reuse another's quotes.
@@ -23,6 +28,8 @@ export const useWageQuoteStore = defineStore('wageQuotes', () => {
quotes.value = {}
pending.clear()
inFlight.clear()
unanswered.clear()
retryAfter = 0
},
)
@@ -37,10 +44,17 @@ export const useWageQuoteStore = defineStore('wageQuotes', () => {
if (!ids.length) return
try {
const rows = await api.getWageQuotes(ids)
const next = { ...quotes.value }
for (const r of rows) next[r.variantId] = r
quotes.value = next
const answered = new Set(rows.map((r) => r.variantId))
ids.forEach((id) => {
if (!answered.has(id)) unanswered.add(id)
})
if (rows.length) {
const next = { ...quotes.value }
for (const r of rows) next[r.variantId] = r
quotes.value = next
}
} catch (e) {
retryAfter = Date.now() + 30_000
console.warn('wage quote failed', e)
} finally {
ids.forEach((id) => inFlight.delete(id))
@@ -49,7 +63,8 @@ export const useWageQuoteStore = defineStore('wageQuotes', () => {
/** Asks for a variant's quote (idempotent; safe to call from a computed). */
function request(variantId: string) {
if (!session.token || quotes.value[variantId] || pending.has(variantId) || inFlight.has(variantId)) return
if (!session.token || Date.now() < retryAfter) return
if (quotes.value[variantId] || unanswered.has(variantId) || pending.has(variantId) || inFlight.has(variantId)) return
pending.add(variantId)
if (!timer) timer = setTimeout(flush, 30)
}