Use local SQLite database#138
Open
ScriptRaccoon wants to merge 11 commits intomainfrom
Open
Conversation
9f5455d to
480405f
Compare
75aaa50 to
ec8caf6
Compare
1931663 to
64c5f70
Compare
64c5f70 to
7443d7c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements a fundamental change to CatDat's infrastructure.
Since CatDat only reads from the database at runtime, it should be possible to use a local database file for its queries (both live and during prerendering) instead of a remote database (currently hosted on Turso). Netlify's file system is ephemeral, so storing a database there is generally not recommended, but for read-only use it appears to be OK.
This should provide a major performance boost, especially for the search and comparison pages, since database queries now have almost no latency. All other pages are prerendered anyway. I also expect a significant reduction in complexity, since the CatDat database can be removed from Turso* and the deployment workflow only needs to build the local file (which it already did). This should also speed up deployment pipelines. Furthermore, migrations are not required anymore since the database can be recreated from scratch anytime.
(The second database,
app.db, which stores page visits and user submissions, requires write access and will remain on Turso.)I went for the
better-sqlite3package. Its queries are synchronous, so the query helper function is no longer async. This is the only change required in the load functions of the Svelte files. More adjustments were needed in the deduction scripts. The packagenode:sqliteis still considered experimental, which is why I don't want to use it for now.*Hence, the environment variables
CATDAT_DB_URLandCATDAT_DB_AUTH_TOKENcan be removed.Performance comparison
Search
The search feels much faster now. The following shortened Netlify logs demonstrate this. I ran the same four search queries in each case. The reported time is the total request duration.
Before
After
Comparison
The comparison feels much faster now. Again, this is confirmed by the Netlify logs. I ran the same two comparison queries in each case. The reported time is the total request duration.
Before
After
Deployment
This measures the time required for the preview deployment pipeline to complete. The production pipeline is likely similar.
Before
~3–4 min
After
~1 min
Lighthouse Tests
Performance results from Lighthouse were inconclusive. The main current bottleneck is loading KaTeX.