Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

41
LINES

< > BotCompany Repo | #1003875 - loadSnippets v2 - fetch multiple snippets in one go - yes it uses POST (LIVE)

JavaX fragment (include)

sbool loadSnippets_verbose;

static L<S> loadSnippets(S... ids) {
  ret loadSnippets(asList(ids));
}

static L<S> loadSnippets(L<S> ids) ctex {
  new L<S> texts;
    
  new StringBuilder buf;
  new Map<Long, S> cached;
  initSnippetCache();
  for (S id : ids) {
    long snippetID = psI(id);
    S text = DiskSnippetCache_get(snippetID);
    S md5 = text != null ? md5(text) : ".";
    if (loadSnippets_verbose)
      print(id + " => " + md5 + " - " + quote(shorten(text, 20)));
    mapPut(cached, snippetID, text);
    buf.append(snippetID).append(" ").append(md5).append(" ");
  }
  if (loadSnippets_verbose)
    print("loadSnippets post data: " + buf);

  Map<S, O> map = jsonDecodeMap(doPost(
    "ids=" + urlencode(trim(str(buf))) + standardCredentials(),
    tb_mainServer() + "/get-multi2.php"));
    
  for (S id : ids) {
    long snippetID = psI(id);
    O result = map.get(str(snippetID));
    if (loadSnippets_verbose)
      print(id + " => " + className(result));
    if (result instanceof S) {
      texts.add((S) result);
      DiskSnippetCache_put(snippetID, (S) result);
    } else
      texts.add(cached.get(snippetID));
  }
  ret texts;
}

Author comment

Began life as a copy of #1003764

download  show line numbers  debug dex   

Travelled to 11 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1003875
Snippet name: loadSnippets v2 - fetch multiple snippets in one go - yes it uses POST (LIVE)
Eternal ID of this version: #1003875/13
Text MD5: ca49ea691c1e7e769de14329f39f434f
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-19 23:47:10
Source code size: 1196 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 358 / 979
Version history: 12 change(s)
Referenced in: #1003876 #1006654 #1011991

Formerly at http://tinybrain.de/1003875 & http://1003875.tinybrain.de