Download Jar. Uses 3874K of libraries. Click here for Pure Java version (12922L/93K).
1 | !7 |
2 | |
3 | static double updateInterval = 60; |
4 | sbool infoBoxes, fullUpdateAtStart = true; |
5 | sbool snippetsDB_inited; |
6 | |
7 | !include once #1014750 // CSnippet |
8 | |
9 | static Thread downloadThread; |
10 | |
11 | p-subst { |
12 | //restartWith384MBHeap(); // for xfullgrab |
13 | autoRestart10Mins(); |
14 | snippetsDB_init(); |
15 | } |
16 | |
17 | svoid snippetsDB_init() { |
18 | lock programLock(); |
19 | if (snippetsDB_inited) ret; |
20 | set snippetsDB_inited; |
21 | mainConcepts.autoSaveInterval = 1000*60; // every minute |
22 | mainConcepts.noXFullGrab = true; |
23 | dbIndexing(CSnippet, 'id); |
24 | for (CSnippet s) s.legacyCompaction(); |
25 | botWithCommandList("Snippets."); |
26 | if (fullUpdateAtStart) fullDownload(); |
27 | doEvery(0, updateInterval, f update); |
28 | } |
29 | |
30 | svoid fullDownload { |
31 | L<Snippet> l = listAllSnippets(); |
32 | printWithTime(n(l, "snippet") + " on server"); |
33 | slurp(l); |
34 | downloadSomeText(); |
35 | } |
36 | |
37 | static int slurp(L<Snippet> l) { |
38 | lock dbLock(); |
39 | int changes = 0; |
40 | for (Snippet s : l) { |
41 | CSnippet cs = uniq(CSnippet, id := parseSnippetID(s.id)); |
42 | changes += cset(cs, title := s.title, type := s.type); |
43 | if (neq(cs.md5, s.md5)) |
44 | changes += cset(cs, md5 := s.md5, text := null); |
45 | } |
46 | S text = n2(changes, "changed snippet"); |
47 | if (infoBoxes && changes != 0) infoBox(text); |
48 | printWithTime(text); |
49 | ret changes; |
50 | } |
51 | |
52 | // with text |
53 | svoid update { |
54 | L<Snippet> l = listRecentlyChangedSnippets(); |
55 | printWithTime(n(l, "snippet") + " on server"); |
56 | slurp(l); |
57 | downloadSomeText(); |
58 | } |
59 | |
60 | answer { |
61 | lock dbLock(); |
62 | if "full download" { |
63 | fullDownload(); |
64 | ret "OK, have " + n(countConcepts(CSnippet), "snippet"); |
65 | } |
66 | |
67 | if "update" { |
68 | update(); |
69 | ret "OK"; |
70 | } |
71 | |
72 | if "download some text" { |
73 | if (downloadThread != null) ret "Already downloading"; |
74 | downloadSomeText(); |
75 | ret "Yo"; |
76 | } |
77 | |
78 | if "stop downloading" { |
79 | cancelThread(downloadThread); |
80 | downloadThread = null; |
81 | ret "OK"; |
82 | } |
83 | |
84 | if "get snippet text *" { |
85 | CSnippet c = findConcept(CSnippet, id := parseSnippetID($1)); |
86 | if (c == null) ret "not found"; |
87 | downloadText(c); |
88 | ret "OK " + quote(c.text()); |
89 | } |
90 | |
91 | if "count" ret n2(countConcepts(CSnippet), "snippet"); |
92 | |
93 | if "all snippet ids" |
94 | ret struct(map fsI(sorted(collect(CSnippet, 'id)))); |
95 | |
96 | if "kill" { cleanKillIn1(); ret "OK"; } |
97 | } |
98 | |
99 | svoid downloadText(CSnippet s) { |
100 | if (s.text != null) ret; |
101 | cset(s, text := eq(s.md5, emptyMD5()) ? "" : toUtf8(loadSnippet(s.id))); |
102 | } |
103 | |
104 | svoid downloadSomeText { |
105 | lock dbLock(); |
106 | if (downloadThread != null) ret; |
107 | downloadThread = startThread(r { |
108 | try { |
109 | int n = 0; for (CSnippet s) if (s.text != null) ++n; |
110 | printWithTime("Have text for " + n + "/" + n(countConcepts(CSnippet), "concept"); |
111 | new ConcurrentEvaluator e; |
112 | e.coresToUse = 10; |
113 | for (final CSnippet s) { |
114 | ping(); |
115 | if (s.text == null) e.add(r { |
116 | ping(); |
117 | downloadText(s); |
118 | /*++n; |
119 | if ((n % 100) == 0) |
120 | printWithTime("Have text for " + n + "/" + n(countConcepts(CSnippet), "concept");*/ |
121 | }); |
122 | } |
123 | e.startWaitCleanUp(); |
124 | } finally { |
125 | downloadThread = null; |
126 | } |
127 | }); |
128 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1009918 |
Snippet name: | Local Snippets DB [OK, now with regular update every minute] |
Eternal ID of this version: | #1009918/55 |
Text MD5: | ba551e38235e53fd6fecb37c8a9e5cd9 |
Transpilation MD5: | af424bbc02729c6be69f1407cc047c05 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-06-03 01:06:34 |
Source code size: | 3177 bytes / 128 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 731 / 2985 |
Version history: | 54 change(s) |
Referenced in: | [show references] |