Rewrite DeleteUnused() queries using new indices

This commit is contained in:
Mike Colagrosso 2024-12-31 13:39:48 -07:00 committed by Alex Cabal
parent 5c8315e6ff
commit f0bfa7a43b
3 changed files with 13 additions and 13 deletions

View file

@ -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
');
}

View file

@ -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]);
}
}

View file

@ -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
');
}
}