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

Add squashed update after deleting document history #53

Merged
merged 1 commit into from
Nov 23, 2022

Conversation

davidbrochart
Copy link
Collaborator

@davidbrochart davidbrochart commented Nov 23, 2022

Copy link
Contributor

@dlqqq dlqqq left a comment

Choose a reason for hiding this comment

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

It looks like the "diff > document_ttl" case is getting pretty expensive to handle now, so we'll definitely want to run this in a separate asyncio task like @ellisonbg suggested. We'd bind this to an instance attribute, and on every document write, we cancel any existing task and create a new task that sleeps for document_ttl and then runs this squash logic.

But, this can be done in a follow-up PR.

async with aiosqlite.connect(ystore.db_path) as db:
assert (await (await db.execute("SELECT count(*) FROM yupdates")).fetchone())[
0
] == i + 1

# assert that adding a record after document TTL deletes previous document history
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# assert that adding a record after document TTL deletes previous document history
# assert that adding a record after document TTL squashes previous document history

await db.execute("DELETE FROM yupdates WHERE path = ?", (self.path,))
# insert squashed updates
squashed_update = Y.encode_state_as_update(ydoc)
metadata = await self.get_metadata()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we lift this definition out of the if block so it's not evaluated again on line 256?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so, as the metadata can depend on time, for instance.

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.

2 participants