themoeway / local-audio-yomichan

Anki add-on to run a local audio server for Yomichan.
MIT License
72 stars 10 forks source link

Combine the SQL tables #1

Closed Aquafina-water-bottle closed 1 year ago

Aquafina-water-bottle commented 1 year ago

From Zetta:

You could make the sqlite most likely faster than my original lazy memory solution. Combining the tables into one with a "source" column so you only have to run 1 query to get all results for all sources.

CREATE TABLE entries (
  id integer PRIMARY KEY,
  source text NOT NULL,
  expression text NOT NULL,
  reading text,
  speaker text,
  file text NOT NULL
);

SELECT * FROM entries WHERE expression = :expression AND (reading IS NULL OR reading = :reading)

Then adding an index (after inserting all the rows) so that you can minimize the page lookups.

CREATE INDEX idx_entries_expression ON entries(expression);

Minimally, so you don't have to try to make one big global query to match all your cases, just add indexes to each of the tables. I think there is a CREATE INDEX IF NOT EXISTS or similar to upgrade existing tables. It will make it take up a tad bit more storage but nothing compared to the multiple gigs of audio.

Reading material: