[plugin] Statistics: do not increment db sequences unnecessarily during cloud sync (#9921)

When you do an insert using either ON CONFLICT [...] DO NOTHING or INSERT OR IGNORE to prevent duplicate rows, sqlite still increments the sequence counter for each of the duplicate rows that it did not insert.
The only way around that is to explicitly write the SQL statement so that it doesn't try to insert the duplicates in the first place.
reviewable/pr9926/r1
Glen Sawyer 1 year ago committed by GitHub
parent a53e9847fa
commit 932ed44a9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2966,7 +2966,10 @@ function ReaderStatistics.onSync(local_path, cached_path, income_path)
title, authors, notes, last_open, highlights, pages, series, language, md5, total_read_time, total_read_pages
) SELECT
title, authors, notes, last_open, highlights, pages, series, language, md5, total_read_time, total_read_pages
FROM income_db.book WHERE true ON CONFLICT (title, authors, md5) DO NOTHING;
FROM income_db.book
WHERE (title, authors, md5) NOT IN (
SELECT title, authors, md5 FROM book
);
-- We create a book_id mapping temp table (view not possible due to attached db)
CREATE TEMP TABLE book_id_map AS

@ -436,7 +436,7 @@ function VocabularyBuilder.onSync(local_path, cached_path, income_path)
sql = sql .. [[
-- We merge the local db with income db to form the synced db.
-- First we do the books
INSERT OR IGNORE INTO title (name) SELECT name FROM income_db.title;
INSERT INTO title (name) SELECT name FROM income_db.title WHERE name NOT IN (SELECT name FROM title);
-- Then update income db's book title id references
UPDATE income_db.vocabulary SET title_id = ifnull(

Loading…
Cancel
Save