Skip to content

A re-fetched message is rewritten and re-indexed even when nothing changed #87

Closed

Description

@neoromantic

A message that is fetched again is written again in full, and the messages_cache_au trigger deletes and re-inserts its search index row, even when nothing the index holds has changed. After every daemon restart or reconnect, catch-up fetches again the messages that arrived live (about one getHistory call per 100 of them per chat, see docs/sync-strategy.md), so each of them costs a row rewrite and an index update. Marking a message deleted re-indexes it too. The cost hasn't been measured.

idx_messages_cache_fetched (messages_cache(fetched_at)) has no query that reads it; it only takes space for every message.

Proposed:

  • The upsert skips the update when the stored row would not change apart from fetched_at and updated_at.
  • The update trigger fires only when a column that feeds the index changes (text, from_id, media_path). Existing caches get the new trigger on their first open.
  • Drop idx_messages_cache_fetched, after checking with EXPLAIN QUERY PLAN that no query uses it.

Done when tests show that re-fetching an unchanged message and marking one deleted leave the index alone, an edit still re-indexes it, an existing cache gets the new trigger and loses the index, and the docs describe it. Related: #80.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions