Add fail_count and last_failed_at to kb_documents
All checks were successful
BotServer CI/CD / build (push) Successful in 3m7s
All checks were successful
BotServer CI/CD / build (push) Successful in 3m7s
Simplified KB indexing state tracking - added columns directly to kb_documents instead of separate table. This enables per-file backoff retry logic.
This commit is contained in:
parent
256d55fc93
commit
73f1898b62
3 changed files with 29 additions and 1 deletions
|
|
@ -11,6 +11,8 @@ CREATE TABLE IF NOT EXISTS kb_documents (
|
||||||
first_published_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
first_published_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
last_modified_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
last_modified_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
indexed_at TIMESTAMPTZ,
|
indexed_at TIMESTAMPTZ,
|
||||||
|
fail_count INT NOT NULL DEFAULT 0,
|
||||||
|
last_failed_at TIMESTAMPTZ,
|
||||||
metadata JSONB DEFAULT '{}'::jsonb,
|
metadata JSONB DEFAULT '{}'::jsonb,
|
||||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
|
|
@ -21,6 +23,7 @@ CREATE INDEX IF NOT EXISTS idx_kb_documents_bot_id ON kb_documents(bot_id);
|
||||||
CREATE INDEX IF NOT EXISTS idx_kb_documents_collection ON kb_documents(collection_name);
|
CREATE INDEX IF NOT EXISTS idx_kb_documents_collection ON kb_documents(collection_name);
|
||||||
CREATE INDEX IF NOT EXISTS idx_kb_documents_hash ON kb_documents(file_hash);
|
CREATE INDEX IF NOT EXISTS idx_kb_documents_hash ON kb_documents(file_hash);
|
||||||
CREATE INDEX IF NOT EXISTS idx_kb_documents_indexed_at ON kb_documents(indexed_at);
|
CREATE INDEX IF NOT EXISTS idx_kb_documents_indexed_at ON kb_documents(indexed_at);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_kb_documents_fail ON kb_documents(bot_id, collection_name, fail_count) WHERE fail_count > 0;
|
||||||
|
|
||||||
-- Knowledge Base Collections
|
-- Knowledge Base Collections
|
||||||
CREATE TABLE IF NOT EXISTS kb_collections (
|
CREATE TABLE IF NOT EXISTS kb_collections (
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ diesel::table! {
|
||||||
first_published_at -> Timestamptz,
|
first_published_at -> Timestamptz,
|
||||||
last_modified_at -> Timestamptz,
|
last_modified_at -> Timestamptz,
|
||||||
indexed_at -> Nullable<Timestamptz>,
|
indexed_at -> Nullable<Timestamptz>,
|
||||||
|
fail_count -> Int4,
|
||||||
|
last_failed_at -> Nullable<Timestamptz>,
|
||||||
metadata -> Nullable<Jsonb>,
|
metadata -> Nullable<Jsonb>,
|
||||||
created_at -> Timestamptz,
|
created_at -> Timestamptz,
|
||||||
updated_at -> Timestamptz,
|
updated_at -> Timestamptz,
|
||||||
|
|
@ -171,3 +173,17 @@ diesel::joinable!(research_findings -> research_projects (project_id));
|
||||||
diesel::joinable!(research_citations -> research_sources (source_id));
|
diesel::joinable!(research_citations -> research_sources (source_id));
|
||||||
diesel::joinable!(research_collaborators -> research_projects (project_id));
|
diesel::joinable!(research_collaborators -> research_projects (project_id));
|
||||||
diesel::joinable!(research_exports -> research_projects (project_id));
|
diesel::joinable!(research_exports -> research_projects (project_id));
|
||||||
|
|
||||||
|
diesel::allow_tables_to_appear_in_same_query!(
|
||||||
|
kb_documents,
|
||||||
|
kb_collections,
|
||||||
|
kb_group_associations,
|
||||||
|
user_kb_associations,
|
||||||
|
research_projects,
|
||||||
|
research_sources,
|
||||||
|
research_notes,
|
||||||
|
research_findings,
|
||||||
|
research_citations,
|
||||||
|
research_collaborators,
|
||||||
|
research_exports,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -565,10 +565,19 @@ impl DriveMonitor {
|
||||||
file_states.remove(&path);
|
file_states.remove(&path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (path, mut state) in current_files {
|
for (path, new_state) in current_files {
|
||||||
|
let mut state = new_state;
|
||||||
if path.ends_with(".bas") {
|
if path.ends_with(".bas") {
|
||||||
state.indexed = true;
|
state.indexed = true;
|
||||||
}
|
}
|
||||||
|
// Preserve fail_count and last_failed_at for existing files that weren't modified
|
||||||
|
if let Some(prev_state) = file_states.get(&path) {
|
||||||
|
if prev_state.etag == state.etag {
|
||||||
|
// File wasn't modified - preserve fail_count and last_failed_at
|
||||||
|
state.fail_count = prev_state.fail_count;
|
||||||
|
state.last_failed_at = prev_state.last_failed_at;
|
||||||
|
}
|
||||||
|
}
|
||||||
file_states.insert(path, state);
|
file_states.insert(path, state);
|
||||||
}
|
}
|
||||||
// Save file states to disk in background to avoid blocking
|
// Save file states to disk in background to avoid blocking
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue