nodejs / nodejs/undici

Upsert in SQLiteStore

Open
#3,867 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
7.7k
Forks
880
Avg merge
2d 16h
Merged PRs (30d)
68

Description

As pointed out by @ronag in https://github.com/nodejs/undici/pull/3657, we can improve our SQLite store design by using a composite cache key as the ID of the table instead of an auto increment field.

One specific problem of our SQLiteStore design is that on reading the cache, we read all the values for a given route, independently of the vary headers: https://github.com/nodejs/undici/blob/e49b5751ddfe726ebc6498f07a4af86de319b691/lib/cache/sqlite-cache-store.js#L375-L421.

For similar reasons in writing, we need to first read the cache, find if we have a matching row, and the go update that.

https://github.com/nodejs/undici/blob/e49b5751ddfe726ebc6498f07a4af86de319b691/lib/cache/sqlite-cache-store.js#L276-L315

We should be able to fix both problems at the same time by using a primary key that includes the vary headers, so we can avoid loading everything at once during getting.

For the algorithm to compute the key, check https://github.com/nodejs/undici/pull/3657#issuecomment-2493064369.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/cache/sqlite-cache-store.js at the read path around lines 375-421 and the write path around lines 276-315. Read the algorithm described in the linked pull request comment, then trace how the SQLite table key and vary headers are handled. Done means the composite key includes the vary headers and both reads and writes avoid loading or separately searching unrelated rows.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, sqlite
Domain
backend, databases
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.