MCPcopy
hub / github.com/seanprashad/leetcode-patterns / downloadAndMerge

Function downloadAndMerge

src/lib/sync.ts:36–57  ·  view source on GitHub ↗
(userId: string)

Source from the content-addressed store, hash-verified

34
35// Download remote progress and replace local state with it
36export async function downloadAndMerge(userId: string): Promise<boolean> {
37 const { data, error } = await supabase
38 .from("user_progress")
39 .select("*")
40 .eq("user_id", userId)
41 .single();
42
43 if (error || !data) {
44 // No remote data yet — push local up
45 await uploadProgress(userId);
46 return false;
47 }
48
49 // Remote is the source of truth — overwrite local state
50 saveCompleted(new Set<number>(data.completed ?? []));
51 saveStarred(new Set<number>(data.starred ?? []));
52 saveNotes((data.notes as Record<number, string>) ?? {});
53 saveSolvedDates((data.solved_dates as Record<number, string>) ?? {});
54 saveReminders((data.reminders as Record<number, Reminder>) ?? {});
55
56 return true;
57}
58
59// Track when we last uploaded to ignore our own realtime events
60let lastUploadAt = 0;

Callers 2

AuthProviderFunction · 0.90
sync.test.tsFile · 0.90

Calls 6

saveCompletedFunction · 0.90
saveStarredFunction · 0.90
saveNotesFunction · 0.90
saveSolvedDatesFunction · 0.90
saveRemindersFunction · 0.90
uploadProgressFunction · 0.85

Tested by

no test coverage detected