From 81b2f22b046ff752ce3b384d3946c6beee3203db Mon Sep 17 00:00:00 2001 From: weijiuqiao <59040746+weijiuqiao@users.noreply.github.com> Date: Sun, 20 Nov 2022 07:53:18 +0800 Subject: [PATCH] ReaderStatistics: fix sync sql command (#9811) Fixes sync sql command that uses left join instead of inner join, which adds unnecessary comparisons and might result in incorrect mapping between databases. --- plugins/statistics.koplugin/main.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index 348c1c625..7b6be9655 100644 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -2825,8 +2825,8 @@ function ReaderStatistics.onSync(local_path, cached_path, income_path) -- We create a book_id mapping temp table (view not possible due to attached db) CREATE TEMP TABLE book_id_map AS - SELECT m.id as mid, ifnull(i.id, m.id) as iid FROM book m --main - LEFT JOIN income_db.book i + SELECT m.id as mid, i.id as iid FROM book m --main + INNER JOIN income_db.book i ON (m.title, m.authors, m.md5) = (i.title, i.authors, i.md5); ]] if attached_cache then @@ -2835,7 +2835,7 @@ function ReaderStatistics.onSync(local_path, cached_path, income_path) -- DELETE stat_data items DELETE FROM income_db.page_stat_data WHERE (id_book, page, start_time) IN ( SELECT map.iid, page, start_time FROM cached_db.page_stat_data - LEFT JOIN book_id_map AS map ON id_book = map.mid + INNER JOIN book_id_map AS map ON id_book = map.mid WHERE (id_book, page, start_time) NOT IN ( SELECT id_book, page, start_time FROM page_stat_data )