Skip to content

Commit 87ccb82

Browse files
committed
Detect fast→full mode change + auto-enable UI for ui-variant binary
Pipeline routing: when discovered files outnumber stored hashes by >50%, the DB was built with a narrower file set (fast mode). Delete and do a fresh parallel full index instead of single-threading thousands of "new" files through the incremental path. UI config: auto-enable ui_enabled when no config file exists and the binary has embedded UI assets (CBM_EMBEDDED_FILE_COUNT > 0). Previously the UI variant required --ui=true on first run.
1 parent bcf594f commit 87ccb82

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/pipeline/pipeline.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,23 @@ int cbm_pipeline_run(cbm_pipeline_t *p) {
382382
cbm_store_close(check_store);
383383

384384
if (hash_count > 0) {
385-
cbm_log_info("pipeline.route", "path", "incremental", "stored_hashes",
386-
itoa_buf(hash_count));
387-
rc = cbm_pipeline_run_incremental(p, db_path, files, file_count);
388-
cbm_discover_free(files, file_count);
389-
free(db_path);
390-
return rc;
385+
/* Detect mode change (e.g. fast→full): if discovered files
386+
* outnumber stored hashes by >50%, the DB was built with a
387+
* narrower file set. Delete and reindex fresh instead of
388+
* single-threading ~thousands of "new" files incrementally. */
389+
if (file_count > hash_count + (hash_count / 2)) {
390+
cbm_log_info("pipeline.route", "path", "mode_change_reindex",
391+
"stored_hashes", itoa_buf(hash_count), "discovered",
392+
itoa_buf(file_count));
393+
/* Falls through to delete-and-reindex below */
394+
} else {
395+
cbm_log_info("pipeline.route", "path", "incremental", "stored_hashes",
396+
itoa_buf(hash_count));
397+
rc = cbm_pipeline_run_incremental(p, db_path, files, file_count);
398+
cbm_discover_free(files, file_count);
399+
free(db_path);
400+
return rc;
401+
}
391402
}
392403
} else if (check_store) {
393404
cbm_store_close(check_store);

src/ui/config.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Format: {"ui_enabled": false, "ui_port": 9749}
66
*/
77
#include "ui/config.h"
8+
#include "ui/embedded_assets.h"
89
#include "foundation/log.h"
910
#include "foundation/platform.h"
1011
#include "foundation/compat_fs.h"
@@ -37,7 +38,11 @@ void cbm_ui_config_load(cbm_ui_config_t *cfg) {
3738

3839
FILE *f = fopen(path, "rb");
3940
if (!f) {
40-
return; /* no config file → defaults */
41+
/* No config file — auto-enable UI if binary has embedded assets */
42+
if (CBM_EMBEDDED_FILE_COUNT > 0) {
43+
cfg->ui_enabled = true;
44+
}
45+
return;
4146
}
4247

4348
fseek(f, 0, SEEK_END);

0 commit comments

Comments
 (0)