Skip to content

GSAK backup import: recalculate distances in the background instead of on the GUI thread #955

Description

@nagisml

Current State

Followup of #947

Problem

After a GSAK backup import, the distances of each imported database are recalculated with recalculate_distances() on the GUI thread: for the active database in _refresh_after_import(), for every other database the first time you switch to it (_on_database_switched). On large databases this freezes the UI for a noticeable time.

There is also a gap in distances_up_to_date(). It only spot-checks the lowest-id cache, so after a merge import it can report "up to date" while the newly added caches still have distance = NULL.

Proposed Improvement

Proposed fix

  • GsakImportWorker brings each target database's distances up to date while it is already running in the background, right after the import.
  • recalculate_distances() / distances_up_to_date() take an optional db_path. While the worker has the engine switched to a target database, db_settings is not bound to it, so dist_calc_* has to be read from and written to that file's own db_settings table. Otherwise it would end up in the active database's legacy opensak.json keys.
  • New helpers db_settings.peek_value() / write_file() (never create a missing file; writing drops the cache) and AppSettings.home_for_db_file().
  • After a GSAK import, the main window only recalculates if distances_up_to_date() can't confirm the distances. The check on database switch stays as a safety net. Other imports (GPX etc.) keep recalculating every time.
  • distances_up_to_date() also returns False when any cache with coordinates has distance IS NULL.

Acceptance criteria

  • Importing a GSAK backup into several databases doesn't freeze the UI afterwards, and switching to an imported database doesn't trigger a full recalculation.
  • Imported databases have distances for all caches with coordinates, and dist_calc_* is stored in their own settings table.
  • The active database's settings are unchanged by importing into other databases.
  • If the background recalculation fails, it is only logged; the import still succeeds, and the check on refresh/switch recalculates later.

Branch: improvement/gsak-import-recalc-distances-in-worker

Expected Benefits

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions