Files
velixio fb232a3b38 fix(account): address Greptile and code-scanning review on #2931
Greptile:
- Settings changed while sync was stopped are compared with the merge bases
  when sync starts again, so they are pushed instead of lost.
- A pulled value for a partly-synced object (clone settings, dictation)
  merges into the local one, so the draft, reference text and chosen voice
  survive a first sync.
- A stalled stream or too_many_streams runs the fallback poll and marks the
  stream down, so the 60-second poll keeps going.
- Replacing a voice's reference audio clears its sync consent attestation.
- A request stays aborted-on-off and timed until its body is read, not just
  until headers arrive.
- Cancel invalidates the sign-in attempt at every step: no browser opens and
  no token is stored after Cancel.

Code scanning:
- The sync client accepts only https (or loopback http) endpoints and Base62
  Organization IDs.
- Static SQL for sync IDs; no empty excepts; no unused imports or no-op
  statements; Cloud-sync applies notify stores through an app event instead of
  a synthetic StorageEvent.
2026-10-17 11:36:04 +05:30

29 lines
1.0 KiB
Python

"""Stable ``sync_id``s for synced records (guide §4): filled once, never changed."""
from __future__ import annotations
from core import db as core_db
from services.cloud_sync.ids import new_sync_id
#: Record tables that carry a sync_id today (S2: voices) and their fixed SQL.
#: S3 adds takes and projects. No SQL is built from strings.
_QUERIES = {
"voice_profiles": (
"SELECT id FROM voice_profiles WHERE sync_id IS NULL OR sync_id = ''",
"UPDATE voice_profiles SET sync_id=? WHERE id=? AND (sync_id IS NULL OR sync_id='')",
),
}
SYNCED_TABLES = tuple(_QUERIES)
def ensure_sync_ids(table: str = "voice_profiles") -> int:
"""Give every row without a ``sync_id`` a new one; returns how many were filled."""
if table not in _QUERIES:
raise ValueError(f"not a synced table: {table}")
select, update = _QUERIES[table]
filled = 0
with core_db.db_conn() as conn:
for (row_id,) in conn.execute(select).fetchall():
conn.execute(update, (new_sync_id(), row_id))
filled += 1
return filled