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

66
LINES

< > BotCompany Repo | #1010746 // cachedNodeIndex2 - with automatic update on CE changes

JavaX fragment (include)

static Cache<MultiMap<S, WebNode>> cachedNodeIndex2_cache = new Cache(f cachedNodeIndex2_make);
static bool cachedNodeIndex_autoMake = true;
sbool cachedNodeIndex2_monitorCircleEditor;
static bool cachedNodeIndex2_first = true;
static FileStatus cachedNodeIndex2_status;

please include function postSoftwareMadeWeb.

static MultiMap<S, WebNode> cachedNodeIndex2() {
  if (cachedNodeIndex2_first) {
    cachedNodeIndex2_first = false;
    onWebsChanged(f cachedNodeIndex2_clear);
    onTransientWebAdded_do(f cachedNodeIndex2_onNewWeb);
    onTransientWebRemoved_do(f cachedNodeIndex2_onWebRemoved);
    setAdd(postSoftwareMadeWeb_onNewWeb, f cachedNodeIndex2_onNewWeb);
  }
  
  if (cachedNodeIndex2_monitorCircleEditor) {
    FileStatus status = conceptsFileStatus(circlesEditorDBID());
    if (neq(cachedNodeIndex2_status, status)) {
      cachedNodeIndex2_status = status;
      cachedNodeIndex2_cache.clear();
    }
  }
  
  ret cachedNodeIndex2_cache!;
}

static void cachedNodeIndex2_clear() {
  cachedNodeIndex2_cache.clear();
}

sbool cachedNodeIndex2_onNewWeb(Web web, O[] params) {
  ret cachedNodeIndex2_onNewWeb(web);
}

sbool cachedNodeIndex2_onNewWeb(Web web) {
  if (!cachedNodeIndex_autoMake) false;
  lock cachedNodeIndex2_cache.lock;
  //print("Incremental update");
  ai_addWebToIndex(cachedNodeIndex2_cache!, web);
  cachedNodeIndex2_cache.changeCount++;
  false; // don't trigger full update
}

svoid cachedNodeIndex2_onWebRemoved(Web web) {
  if (!cachedNodeIndex_autoMake) ret;
  lock cachedNodeIndex2_cache.lock;
  print("Incremental removal");
  ai_removeWebFromIndex(cachedNodeIndex2_cache!, web);
  cachedNodeIndex2_cache.changeCount++;
}

static long cachedNodeIndex_changeCount() {
  ret cachedNodeIndex2_cache.changeCount;
}

static MultiMap<S, WebNode> cachedNodeIndex2_make() {
  if (cachedNodeIndex_autoMake) {
    print("Making index");
    ret dwlw_fullNodeIndex_ci();
  } else {
    //print("Skipping making index");
    ret ai_emptyWebIndex();
  }
}

Author comment

Began life as a copy of #1010574

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: #1010746
Snippet name: cachedNodeIndex2 - with automatic update on CE changes
Eternal ID of this version: #1010746/25
Text MD5: 04920617f809c8c9526f748b66b6ac3f
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-12-08 17:57:42
Source code size: 2052 bytes / 66 lines
Pitched / IR pitched: No / No
Views / Downloads: 431 / 446
Version history: 24 change(s)
Referenced in: [show references]