Skip to content

🔄 Sync Caregiver Data from Firestore to Local DB 3 Times Daily #6

@suleymansurucu

Description

@suleymansurucu

🎯 Goal

Ensure that caregiver-related data (e.g., shared baby profiles) is synchronized from Firestore to local database up to 3 times per day.
This ensures consistent and up-to-date caregiver access across multiple devices without requiring real-time syncing, reducing performance costs.


🧩 Context

  • In Sara Baby, a baby can be shared among multiple users (caregivers)
  • Each user’s local database (e.g. SQLite) stores baby + caregiver data
  • When a user makes changes (e.g., adds an activity), a local-to-cloud sync occurs every 15 seconds
  • However, changes made by other caregivers on Firestore aren't reflected unless the app explicitly pulls data from Firestore

✅ Tasks

  • Add a sync frequency limiter

    • Limit Firestore → local caregiver sync to 3 times per day
    • Use SQLite or similar to store timestamps of last 3 syncs
    • Avoid redundant reads if the limit is reached
  • Schedule sync on key app events:

    • App launch
    • App foreground resume (with cooldown)
    • Home screen visited (optional)
  • On sync trigger:

    • Pull caregiver-related baby and activity data from Firestore
    • Update or merge into local SQLite
    • Handle removed caregivers / new caregivers properly
  • Ensure sync logic is idempotent (running it multiple times doesn’t duplicate or corrupt data)


🧪 Test Scenarios

  • New caregiver added from another device → shows after sync
  • Removed caregiver → no longer has access
  • Caregiver sync triggers max 3 times/day
  • App does not crash or slow down on large data sync

🔧 Tech Suggestions

  • Use SQLite to store last sync timestamps
  • Use BLoC or Repository to trigger sync from AppLifecycle or HomePage
  • Consider future use of workmanager or flutter_background_fetch for automated scheduling

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions