Libraryless. Click here for Pure Java version (3053L/20K/67K).
1 | // Logic: Checks every 10 seconds and clears full cache when |
2 | // anything changed in the DB. So it's as good as traffic-free |
3 | // when the DB is not changing. |
4 | |
5 | !752 |
6 | |
7 | static int updateInterval = 10000; |
8 | static long lastVersionCount; |
9 | |
10 | static new Map<S, S> md5s; |
11 | |
12 | p { |
13 | startBot("Version Count Bot", "#1001745"); |
14 | makeBot("Transpilation MD5 Bot."); |
15 | updateLoop(); |
16 | } |
17 | |
18 | static void update() { |
19 | new Matches m; |
20 | if (match("version count: *", sendToLocalBot_cached("Version Count Bot", "get version count"), m)) { |
21 | long count = parseLong(m.get(0)); |
22 | if (count != lastVersionCount) { |
23 | lastVersionCount = count; |
24 | clear(); |
25 | } |
26 | } |
27 | } |
28 | |
29 | static synchronized S answer(S s) { |
30 | new Matches m; |
31 | // current = get transpilation md5 only if transpilation is up to date |
32 | if (match3("what is the current transpilation md5 of snippet *", s, m)) { |
33 | S snippetID = formatSnippetID(m.unq(0)); |
34 | S md5 = md5s.get(snippetID); |
35 | if (md5 == null) { |
36 | md5 = getCurrentTranspilationMD5(snippetID); |
37 | if (md5 == null) ret "null"; |
38 | md5s.put(snippetID, md5); |
39 | } |
40 | if (isMD5(md5)) |
41 | ret format("The current transpilation md5 of snippet * is *.", snippetID, md5); |
42 | else |
43 | ret "Transpilation is out of date."; |
44 | } |
45 | |
46 | if (match3("clear snippet md5 cache", s, m)) { |
47 | clear(); |
48 | ret "OK."; |
49 | } |
50 | |
51 | if (match3("get snippet md5 cache size", s, m)) { |
52 | ret "Cache entries: " + md5s.size(); |
53 | } |
54 | |
55 | ret null; |
56 | } |
57 | |
58 | static synchronized void clear() { |
59 | md5s.clear(); |
60 | } |
61 | |
62 | static S getCurrentTranspilationMD5(S snippetID) { |
63 | S s = loadPage("http://tinybrain.de:8080/tb-int/get-transpilation-md5.php?id=" + parseSnippetID(snippetID)).trim(); |
64 | ret s; |
65 | } |
Began life as a copy of #1002079
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1002243 |
Snippet name: | Transpilation MD5 Bot (developing) |
Eternal ID of this version: | #1002243/1 |
Text MD5: | 2222b3a35fd3324698cd300dc8e6edc7 |
Transpilation MD5: | 82fc37d498b8e69d25a182e593cda777 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-12-31 22:45:52 |
Source code size: | 1728 bytes / 65 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 628 / 702 |
Referenced in: | [show references] |