MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / store_graph_mem

Function store_graph_mem

src/store/store.c:6713–6751  ·  view source on GitHub ↗

This store's adjacency layer, or NULL for the SQL path; tried once per * store. The layer's version is the store generation plus the file state, and * both — like a miss's edge scan — are read inside one read transaction, so a * layer holds exactly the edges of the version it is keyed to. */

Source from the content-addressed store, hash-verified

6711 * both — like a miss's edge scan — are read inside one read transaction, so a
6712 * layer holds exactly the edges of the version it is keyed to. */
6713static cbm_graph_mem_t *store_graph_mem(cbm_store_t *s) {
6714 if (s->graph_mem_tried) {
6715 return s->graph_mem;
6716 }
6717 s->graph_mem_tried = true;
6718 if (!s->query_store || !s->db || !s->db_path) {
6719 return NULL;
6720 }
6721 bool own_txn = sqlite3_get_autocommit(s->db) != 0;
6722 if (own_txn && sqlite3_exec(s->db, "BEGIN DEFERRED;", NULL, NULL, NULL) != SQLITE_OK) {
6723 return NULL;
6724 }
6725 char generation[CBM_SZ_128];
6726 char state[CBM_SZ_64];
6727 char version[CBM_SZ_256];
6728 /* The generation read is the transaction's first read: the SHARED lock
6729 * the file-state read relies on is held from here on. */
6730 if (cbm_store_generation(s, generation, sizeof(generation)) == CBM_STORE_OK &&
6731 strcmp(generation, "legacy") != 0 && store_rollback_file_state(s, state, sizeof(state))) {
6732 snprintf(version, sizeof(version), "%s/%s", generation, state);
6733 s->graph_mem = cbm_graph_mem_acquire(s->db, s->db_path, version);
6734 }
6735 if (own_txn) {
6736 (void)sqlite3_exec(s->db, "COMMIT;", NULL, NULL, NULL);
6737 }
6738 if (s->graph_mem &&
6739 sqlite3_create_function(s->db, "cbm_adj_degree", ST_COL_2,
6740 SQLITE_UTF8 | SQLITE_DETERMINISTIC | SQLITE_DIRECTONLY, s,
6741 sqlite_graph_mem_degree, NULL, NULL) != SQLITE_OK) {
6742 cbm_graph_mem_release(s->graph_mem);
6743 s->graph_mem = NULL;
6744 }
6745 if (s->graph_mem) {
6746 s->graph_mem_degree_mask =
6747 cbm_graph_mem_type_mask(s->graph_mem, st_degree_types,
6748 (int)(sizeof(st_degree_types) / sizeof(st_degree_types[0])));
6749 }
6750 return s->graph_mem;
6751}
6752
6753/* ── Search ─────────────────────────────────────────────────────── */
6754

Callers 2

cbm_store_searchFunction · 0.85
store_bfsFunction · 0.85

Calls 5

cbm_store_generationFunction · 0.85
cbm_graph_mem_acquireFunction · 0.85
cbm_graph_mem_releaseFunction · 0.85
cbm_graph_mem_type_maskFunction · 0.85

Tested by

no test coverage detected