| 3464 | } |
| 3465 | |
| 3466 | cbm_store_node_scan_t *cbm_store_node_scan_open(cbm_store_t *s, const char *project, |
| 3467 | const char *label) { |
| 3468 | if (!s || !s->db) { |
| 3469 | return NULL; |
| 3470 | } |
| 3471 | cbm_store_node_scan_t *scan = cbm_calloc(CBM_MEM_CLASS_STORE, sizeof(*scan)); |
| 3472 | if (!scan) { |
| 3473 | return NULL; |
| 3474 | } |
| 3475 | scan->store = s; |
| 3476 | scan->project = cbm_mem_strdup(CBM_MEM_CLASS_STORE, project); |
| 3477 | scan->label = cbm_mem_strdup(CBM_MEM_CLASS_STORE, label); |
| 3478 | if ((project && !scan->project) || (label && !scan->label)) { |
| 3479 | cbm_store_node_scan_close(scan); |
| 3480 | return NULL; |
| 3481 | } |
| 3482 | scan->phase = label ? NODE_SCAN_LABEL : NODE_SCAN_NULL_FILE; /* NULL file_path rows first */ |
| 3483 | if (label) { |
| 3484 | scan->paged = |
| 3485 | node_scan_plan_is(s, NODE_SCAN_COLS "WHERE project = ?1 AND label = ?2;", |
| 3486 | "SEARCH nodes USING INDEX idx_nodes_label (project=? AND label=?)"); |
| 3487 | } else { |
| 3488 | scan->paged = node_scan_plan_is(s, NODE_SCAN_COLS "WHERE project = ?1;", |
| 3489 | "SEARCH nodes USING INDEX idx_nodes_file (project=?)"); |
| 3490 | } |
| 3491 | if (!scan->paged) { |
| 3492 | int rc = label ? cbm_store_find_nodes_by_label(s, project, label, &scan->eager, |
| 3493 | &scan->eager_count) |
| 3494 | : cbm_store_find_nodes(s, project, &scan->eager, &scan->eager_count); |
| 3495 | scan->eager_failed = rc != CBM_STORE_OK; |
| 3496 | } |
| 3497 | return scan; |
| 3498 | } |
| 3499 | |
| 3500 | bool cbm_store_node_scan_paged(const cbm_store_node_scan_t *scan) { |
| 3501 | return scan && scan->paged; |