refactor(flatfile): drop dead cursor_offset, guard inverted range
Some checks failed
CI Code / Code Coverage (pull_request) Failing after 13m22s
CI Code / Check spelling (pull_request) Failing after 13m25s
CI Code / Check coding style (pull_request) Failing after 13m29s
CI Code / Linux (ubuntu) (pull_request) Failing after 13m32s
CI Code / Linux (debian) (pull_request) Failing after 13m36s
CI Code / Linux (arch) (pull_request) Failing after 13m39s

This commit is contained in:
2026-05-04 15:28:34 +03:00
parent 875f8f4100
commit 36d260db88
2 changed files with 9 additions and 11 deletions

View File

@@ -54,7 +54,6 @@ ff_state_new(const char* filepath)
{
ff_contact_state_t* state = g_malloc0(sizeof(ff_contact_state_t));
state->filepath = g_strdup(filepath);
state->cursor_offset = -1;
state->archive_ids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
state->stanza_senders = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
return state;
@@ -294,7 +293,6 @@ ff_state_ensure_fresh(ff_contact_state_t* state)
if (st.st_ino == state->stamp.inode && st.st_size > state->stamp.size)
return _ff_state_extend(state);
state->cursor_offset = -1;
return _ff_state_build(state);
}
@@ -726,10 +724,6 @@ _flatfile_get_previous_chat(const gchar* const contact_barejid, const gchar* sta
if (state->n_entries == 0)
return DB_RESPONSE_EMPTY;
// Reset cursor for filtered (non-Page-Up) queries
if (start_time)
state->cursor_offset = -1;
// Determine read byte-range using the sparse index
off_t read_from = state->bom_len;
off_t read_to = state->stamp.size;
@@ -789,6 +783,15 @@ _flatfile_get_previous_chat(const gchar* const contact_barejid, const gchar* sta
read_from = backed;
}
// Defensive: an empty or inverted range means there is nothing to read.
// Reachable when start_time bisects past end_time, or when an end_time
// upper-bound shrinks read_to below the BOM-adjusted read_from.
if (read_from >= read_to) {
log_debug("flatfile: empty range [%ld, %ld) for %s",
(long)read_from, (long)read_to, contact_barejid);
return DB_RESPONSE_EMPTY;
}
// Open file and read lines in [read_from, read_to)
FILE* fp = fopen(state->filepath, "r");
if (!fp)
@@ -861,10 +864,6 @@ _flatfile_get_previous_chat(const gchar* const contact_barejid, const gchar* sta
if (!all_parsed)
return DB_RESPONSE_EMPTY;
// Update cursor: byte offset of oldest parsed message in this batch
ff_parsed_line_t* oldest = all_parsed->data;
state->cursor_offset = oldest->file_offset;
// Apply LMC corrections (if enabled) and build ProfMessage list
GSList* pre_result = NULL;
if (prefs_get_boolean(PREF_CORRECTION_ALLOW)) {

View File

@@ -88,7 +88,6 @@ typedef struct
size_t cap_entries;
size_t total_lines;
ff_file_stamp_t stamp;
off_t cursor_offset;
int bom_len;
GHashTable* archive_ids; // set: archive_id -> NULL (MAM dedup, O(1))
GHashTable* stanza_senders; // map: stanza_id -> from_jid (LMC validation, O(1))