From f0bfa7a43bbce93be16df7d47a2b70481350dcf4 Mon Sep 17 00:00:00 2001 From: Mike Colagrosso Date: Tue, 31 Dec 2024 13:39:48 -0700 Subject: [PATCH] Rewrite DeleteUnused() queries using new indices --- lib/Collection.php | 8 ++++---- lib/EbookTag.php | 10 +++++----- lib/LocSubject.php | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/Collection.php b/lib/Collection.php index 9763d4ac..d50e26be 100644 --- a/lib/Collection.php +++ b/lib/Collection.php @@ -104,10 +104,10 @@ class Collection{ */ public static function DeleteUnused(): void{ Db::Query(' - DELETE - from Collections - where CollectionId not in - (select distinct CollectionId from CollectionEbooks) + DELETE c + from Collections c + left join CollectionEbooks ce using (CollectionId) + where ce.CollectionId is null '); } diff --git a/lib/EbookTag.php b/lib/EbookTag.php index bfa6fcaf..138a3184 100644 --- a/lib/EbookTag.php +++ b/lib/EbookTag.php @@ -113,11 +113,11 @@ class EbookTag extends Tag{ */ public static function DeleteUnused(): void{ Db::Query(' - DELETE - from Tags - where Type = ? - and TagId not in - (select distinct TagId from EbookTags) + DELETE t + from Tags t + left join EbookTags et using (TagId) + where t.Type = ? + and et.TagId is null ', [Enums\TagType::Ebook]); } } diff --git a/lib/LocSubject.php b/lib/LocSubject.php index 880fb3a1..36d4bf07 100644 --- a/lib/LocSubject.php +++ b/lib/LocSubject.php @@ -70,10 +70,10 @@ class LocSubject{ */ public static function DeleteUnused(): void{ Db::Query(' - DELETE - from LocSubjects - where LocSubjectId not in - (select distinct LocSubjectId from EbookLocSubjects) + DELETE ls + from LocSubjects ls + left join EbookLocSubjects els using (LocSubjectId) + where els.LocSubjectId is null '); } }