mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[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.
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user