!7 concept CSnippet { long id; S type; S title, md5, text; } static Thread downloadThread; p { dbIndexing(CSnippet, 'id); bot("Snippets."); } svoid fullDownload { L l = listAllSnippets(); print(n(l, "snippet") + " on server"); slurp(l); } static int slurp(L l) { int changes =0 ; for (Snippet s : l) { CSnippet cs = uniq(CSnippet, id := parseSnippetID(s.id)); changes += cset(cs, title := s.title, type := s.type); if (neq(cs.md5, s.md5)) changes += cset(cs, md5 := s.md5, text := null); } print(n(changes, "change")); ret changes; } svoid update { L l = listRecentlyChangedSnippets(); print(n(l, "snippet") + " on server"); slurp(l); } answer { if "full download" { fullDownload(); ret "OK, have " + n(countConcepts(CSnippet), "snippet"); } if "update" { update(); ret "OK"; } if "download some text" { if (downloadThread != null) ret "Already downloading"; downloadThread = startThread(r { try { for (CSnippet s) { ping(); if (s.text == null) cset(s, text := loadSnippet(s.id)); } } finally { downloadThread = null; } }); ret "Yo"; } if "stop downloading" { cancelThread(downloadThread); downloadThread = null; ret "OK"; } }