Skip to content

Offline-database-forbedringer#956

Open
jorgkv wants to merge 5 commits intodevelopfrom
fix/offline-db
Open

Offline-database-forbedringer#956
jorgkv wants to merge 5 commits intodevelopfrom
fix/offline-db

Conversation

@jorgkv
Copy link
Contributor

@jorgkv jorgkv commented Mar 26, 2026

  • Unngå at observasjoner kan dukke opp i feil miljø
  • Litt småfiksing fra Claude
  • Forsøk på forenklinger rundt initialisering og connection-håndtering
  • Legg til fail-fast logikk i withConnection() om this.sqlite ikke er initialisert

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

jorgkv added 3 commits March 26, 2026 09:53
Problemet var bruken av combineLatest i offline-capable-search-service. combineLatest emitter når én av kildene emitter, så når man byttet miljø emitter den med forrige observasjon fra miljøet du sendte inn i, og lagrer denne i feil miljø.
Litt skeptisk til json-endringen, må testes...
Forenkler initialisering og connection-håndtering
@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://victorious-water-056410803-956.westeurope.azurestaticapps.net

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the offline SQLite layer to better separate data between environments (via app_mode) and to simplify/strengthen initialization and connection handling in the hybrid app lifecycle.

Changes:

  • Adds a DB schema upgrade (v6) that recreates tables so registration uses a composite PK (reg_id, app_mode) and sync time uses (app_mode, lang).
  • Refactors SQLite usage to run operations through a withConnection() helper and adds locking intended to prevent close/open interference during pause/resume.
  • Moves SQLite initialization out of AppComponent and into an APP_INITIALIZER, and adjusts offline save/delete subscriptions to avoid reprocessing on appMode changes.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
src/app/core/services/sqlite/sqlite.service.ts DB v6 migration + new locking/connection wrapper + query/pagination adjustments
src/app/core/services/search-registration/offline-capable-search-service.ts Uses withLatestFrom to avoid duplicate writes when appMode changes
src/app/app.providers.ts Initializes SqliteService via provideAppInitializer on hybrid only
src/app/app.component.ts Removes SQLite init responsibility from the root component
Comments suppressed due to low confidence (1)

src/app/core/services/sqlite/sqlite.service.ts:432

  • parseLimit uses truthy checks (if (c.NumberOfRecords && c.Offset)), which skips valid values like Offset = 0 (or NumberOfRecords = 0). Use explicit null/undefined checks so pagination works correctly when offset is zero.
  private parseLimit(c: SearchCriteria) {
    if (c.NumberOfRecords && c.Offset) {
      return `LIMIT ${c.NumberOfRecords} OFFSET ${c.Offset}`;
    } else if (c.NumberOfRecords) {
      return `LIMIT ${c.NumberOfRecords}`;
    }
    return '';

@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://victorious-water-056410803-956.westeurope.azurestaticapps.net

1 similar comment
@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://victorious-water-056410803-956.westeurope.azurestaticapps.net

@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://victorious-water-056410803-956.westeurope.azurestaticapps.net

jorgkv and others added 2 commits March 26, 2026 22:49
 - Legg til fail-fast logikk i withConnection om sqlite ikke er initialisert
 - Fiks kommentar

Agent-Logs-Url: https://github.com/NVE/regObs4/sessions/1eb057f8-f130-4ea5-a330-f8650d23c679

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://victorious-water-056410803-956.westeurope.azurestaticapps.net

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants