diff --git a/dashboard/sync.py b/dashboard/sync.py index 163d863..7f17767 100644 --- a/dashboard/sync.py +++ b/dashboard/sync.py @@ -272,12 +272,29 @@ def pull(st): return got +def prepare_new(st): + """Tables made since start-up (a plugin creates some on first use) → stamped now, and their file read from + the start once ("behind") — the batches with their rows were passed by while they weren't there.""" + for name, path, tables in specs(): + if not os.path.exists(path): + continue + new = syncdb.unprepared(path, tables) + if not new: + continue + print(f"sync: {name}: preparing {', '.join(new)} (made since start-up)", flush=True) + syncdb.prepare(path, tables, st["device"]) + rel = os.path.relpath(path, DATA) + if st.get("pulled") and rel not in (st.get("behind") or {}): # applying again changes nothing else + st["behind"] = dict(st.get("behind") or {}, **{rel: 0}) + + def sync_now(): with _lock: st = load_state() if not configured(st): raise RuntimeError("sync isn't set up (python3 sync.py setup …)") st["key_bytes"] = base64.b64decode(st["key"]) + prepare_new(st) res = {"pulled": pull(st), "pushed": push(st)} status.update(last=time.time(), error=None, result=res) return res diff --git a/dashboard/syncdb.py b/dashboard/syncdb.py index 882bb53..fd009c8 100644 --- a/dashboard/syncdb.py +++ b/dashboard/syncdb.py @@ -181,6 +181,16 @@ def changes(path, tables, name): con.close() +def unprepared(path, tables): + """The synced tables made since prepare() ran (a plugin creates some on first use): there, but without + the sync columns. Read only.""" + con = connect(path) + try: + return [t for t in tables if (cs := _cols(con, t)) and "_uid" not in cs] + finally: + con.close() + + def is_empty(path, tables): """Nothing synced in this file yet (no rows, no delete markers)? Read only.""" con = connect(path)