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

Sql cache: use a single transaction when using MemoryCache chaining #5840

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

BoD
Copy link
Contributor

@BoD BoD commented Apr 22, 2024

A single transaction is used in merge(records: Collection<Record>), but merge(record: Record) was called instead when using memory cache chaining, resulting in using 1 transaction per insert (significantly slower).

Also - enable WAL by default. This has no noticeable perf impact with the fix above (single transaction), but showed significant improvement without it. (moved to its own PR)

Related to #5834

@BoD BoD requested a review from martinbonnin as a code owner April 22, 2024 14:52
Copy link

netlify bot commented Apr 22, 2024

Deploy Preview for apollo-android-docs canceled.

Name Link
🔨 Latest commit d271ab7
🔍 Latest deploy log https://app.netlify.com/sites/apollo-android-docs/deploys/6626805c1df9530008bad7fb

@@ -43,6 +43,7 @@ actual class SqlNormalizedCacheFactory actual constructor(
object : AndroidSqliteDriver.Callback(getSchema(withDates)) {
override fun onConfigure(db: SupportSQLiteDatabase) {
super.onConfigure(db)
db.enableWriteAheadLogging()
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the impact for existing databases? Can this be enabled on a database that wasn't using WAL previously?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great question! 👀

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe turn this into 2 separate PRs? One for transactions, one for WAL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tested that opening a db created without WAL and enabling WAL on it works without an issue.

Opened a separate PR: #5843

Comment on lines +111 to +112
val changedKeys = records.flatMap { record -> internalMerge(record, cacheHeaders, recordMerger) }.toSet()
changedKeys + nextCache?.merge(records, cacheHeaders, recordMerger).orEmpty()
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@BoD BoD merged commit 7079290 into main Apr 22, 2024
9 checks passed
@BoD BoD deleted the sql-cache-transactions branch April 22, 2024 16:15
BoD added a commit that referenced this pull request Apr 29, 2024
BoD added a commit that referenced this pull request Apr 29, 2024
(cherry picked from commit 7079290)
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.

None yet

2 participants