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

Expired document regression with expiresAt check #8

Closed
johnnyoshika opened this issue Aug 7, 2023 · 0 comments
Closed

Expired document regression with expiresAt check #8

johnnyoshika opened this issue Aug 7, 2023 · 0 comments
Assignees

Comments

@johnnyoshika
Copy link
Contributor

johnnyoshika commented Aug 7, 2023

Problem

In version 2.0, we introduced a client-side expiresAt check in IDatabase's Get to ensure that expired documents don't get returned:

.filter(doc => !this.hasExpired(doc));

This client-side check is required because Firestore's TTL's deletion time in non-deterministic. Excerpt: https://firebase.google.com/docs/firestore/ttl#ttl_deletion

Deletion through TTL is not an instantaneous process. Expired documents continue to appear in queries and lookup requests until the TTL process actually deletes them. TTL trades deletion timeliness for the benefit of reduced total cost of ownership for deletions. Data is typically deleted within 72 hours after its expiration date.

A regression was introduced because we don't reset expiresAt when document is replaced:

else transaction.update(snap.docs[0].ref, newDocData);

This means that a fresh document can be updated for an existing but expired document. Such document will not be returned by Get. So in other words:

  • If a document expired but is still in Firestore
  • That document is replaced by LTIJS by calling IDatabase.Replace()
  • Inside IDatabase.Replace(), that document is updated but expiresAt doesn't get extended
  • That document can never be retrieved by IDatabase.Get() because it will still be tagged with the old expiresAt date

Requirement

Reset timestamps (including expiresAt) in Replace:

else transaction.update(snap.docs[0].ref, newDocData);

@johnnyoshika johnnyoshika self-assigned this Aug 7, 2023
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

1 participant