Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timetagger doesn't synchronize in the background #439

Open
Scotsguy opened this issue Dec 20, 2023 · 1 comment
Open

Timetagger doesn't synchronize in the background #439

Scotsguy opened this issue Dec 20, 2023 · 1 comment

Comments

@Scotsguy
Copy link

Or: Using Timetagger as a PWA makes you lose records if you're too quick.

Steps to reproduce:

  • Open Timetagger as a PWA
  • Create a record
  • Close the PWA before the next sync happens (within a few seconds)
  • Wait a bit
  • Force-kill/Swipe away the PWA *
  • Open the PWA
  • Observe that the record is gone
    (*Why am I killing the PWA? Due to a long-standing bug in Firefox Android, PWAs will sometimes fail to start the renderer process when you open them, resulting in a blank screen. This persists until you kill the PWA, open the main Firefox app, and then reopen the PWA.)
    Alternatively:
  • Open Timetagger in a desktop browser
  • Create a record
  • Close the tab before the next sync happens
  • Reopen Timetagger
  • Observe that the record is gone

Workaround:
Each time you add a record, wait until Timetagger has synchronized with the server. This is rather annoying to do every single time, though.

Ideal solution:
I'd like for Timetagger to finish synchronizing records in the background, or at the very least remember records until the next time you open the app, so that it can synchronize them in the foreground.

@almarklein
Copy link
Owner

It looks like this is accurate:

async def _save_to_cache(self):
if self._auth and self._auth.username:
try:
dump = {
"key": self._auth.username,
"server_time": self._server_time,
"settings": self.settings.get_dump(),
"records": self.records.get_dump(),
}
storage = window.tools.AsyncStorage()
await storage.setItem(dump)
except Exception as err:
console.warn(err)
# Sync the settings API
if this_is_js():
window.simplesettings.update_store(self.settings)
async def _sync(self):
# Ignore sync if there is no auth info
auth = self.get_auth()
if not auth or auth.cantuse:
self._set_state("error")
self.last_error = auth.cantuse or "Not authenticated"
return
# Get from local cache?
if self._server_time == 0:
await self._load_from_cache()
# Push to server, then pull
for kind in ["settings", "records"]:
await self._push(kind, auth.token)
await self._pull(auth.token)
# Save to local cache
await self._save_to_cache()

When the _sync() method is called, it first tries to sync with the server and then saves to the local cache. This is deliberate to maintain data integrity.

But I think it can still be fixed by storing the pending records to the local storage/db and retrieving them as well when the app starts.

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

No branches or pull requests

2 participants