Skip to content

Commit

Permalink
Purge unused info and covers after full library updates
Browse files Browse the repository at this point in the history
  • Loading branch information
luisangelsm committed Nov 3, 2024
1 parent 72535ff commit dc4010a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
40 changes: 37 additions & 3 deletions YACReaderLibrary/library_creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,13 @@ void LibraryCreator::run()
if (partialUpdate) {
auto folder = DBHelper::updateChildrenInfo(folderDestinationModelIndex.data(FolderModel::IdRole).toULongLong(), _database);
DBHelper::propagateFolderUpdatesToParent(folder, _database);
} else
} else {
DBHelper::updateChildrenInfo(_database);

_database.commit();
cleanup(_database, _target);
}
}

_database.commit();
_database.close();
}

Expand Down Expand Up @@ -270,6 +272,38 @@ void LibraryCreator::cancel()
stopRunning = true;
}

void LibraryCreator::cleanup(QSqlDatabase &db, const QString &target)
{
QDir coversDir(target + "/covers/");
if (!coversDir.exists()) {
return;
}

// delete from comic_info all the comics that don't have a comic associated from the comic table
QSqlQuery infoToDeleteQuery(db);
infoToDeleteQuery.prepare("SELECT ci.id, ci.hash FROM comic_info ci WHERE ci.id NOT IN (SELECT c.comicInfoId FROM comic c)");

if (!infoToDeleteQuery.exec()) {
QLOG_ERROR() << "Error getting comics to delete";
return;
}

while (infoToDeleteQuery.next()) {
QString hash = infoToDeleteQuery.value(1).toString();
QString cover = hash + ".jpg";

auto fullPath = coversDir.absoluteFilePath(cover);
QFile::remove(fullPath);
}

QSqlQuery deleteQuery(db);
deleteQuery.prepare("DELETE FROM comic_info WHERE id NOT IN (SELECT comicInfoId FROM comic)");
if (!deleteQuery.exec()) {
QLOG_ERROR() << "Error purging info from comic_info";
return;
}
}

// retorna el id del ultimo de los folders
qulonglong LibraryCreator::insertFolders()
{
Expand Down
1 change: 1 addition & 0 deletions YACReaderLibrary/library_creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class LibraryCreator : public QThread
QModelIndex folderDestinationModelIndex;
QSettings *settings;
bool checkModifiedDatesOnUpdate;
void cleanup(QSqlDatabase &db, const QString &target);

signals:
void finished();
Expand Down

0 comments on commit dc4010a

Please sign in to comment.