mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Merge branch 'folder_covers_propagation' into develop
This commit is contained in:
commit
cf400e39cf
@ -547,7 +547,8 @@ void FolderModel::deleteFolder(const QModelIndex &mi)
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
DBHelper::removeFromDB(&f, db);
|
||||
DBHelper::updateChildrenInfo(item->parent()->id, db);
|
||||
auto folder = DBHelper::updateChildrenInfo(item->parent()->id, db);
|
||||
DBHelper::propagateFolderUpdatesToParent(folder, db);
|
||||
connectionName = db.connectionName();
|
||||
}
|
||||
QSqlDatabase::removeDatabase(connectionName);
|
||||
@ -560,7 +561,8 @@ void FolderModel::updateFolderChildrenInfo(qulonglong folderId)
|
||||
QString connectionName = "";
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
DBHelper::updateChildrenInfo(folderId, db);
|
||||
auto folder = DBHelper::updateChildrenInfo(folderId, db);
|
||||
DBHelper::propagateFolderUpdatesToParent(folder, db);
|
||||
connectionName = db.connectionName();
|
||||
}
|
||||
QSqlDatabase::removeDatabase(connectionName);
|
||||
|
@ -727,8 +727,57 @@ void DBHelper::update(const Folder &folder, QSqlDatabase &db)
|
||||
updateFolderInfo.exec();
|
||||
}
|
||||
|
||||
void DBHelper::updateChildrenInfo(const Folder &folder, QSqlDatabase &db)
|
||||
void DBHelper::propagateFolderUpdatesToParent(const Folder &folder, QSqlDatabase &db)
|
||||
{
|
||||
auto currentParentId = folder.parentId;
|
||||
auto currentId = folder.id;
|
||||
while (currentParentId != 1) {
|
||||
auto f = loadFolder(currentParentId, db);
|
||||
currentParentId = f.parentId;
|
||||
currentId = f.id;
|
||||
}
|
||||
|
||||
if (currentId != folder.id) {
|
||||
updateChildrenInfo(currentId, db);
|
||||
}
|
||||
}
|
||||
|
||||
Folder DBHelper::updateChildrenInfo(qulonglong folderId, QSqlDatabase &db)
|
||||
{
|
||||
auto folder = loadFolder(folderId, db);
|
||||
QList<LibraryItem *> subitems;
|
||||
QList<LibraryItem *> subfolders = DBHelper::getFoldersFromParent(folderId, db, false);
|
||||
QList<LibraryItem *> comics = DBHelper::getComicsFromParent(folderId, db, false);
|
||||
|
||||
QList<LibraryItem *> updatedSubfolders;
|
||||
for (auto sf : subfolders) {
|
||||
updatedSubfolders.append(new Folder(updateChildrenInfo(static_cast<Folder *>(sf)->id, db)));
|
||||
}
|
||||
|
||||
subitems.append(updatedSubfolders);
|
||||
subitems.append(comics);
|
||||
|
||||
std::sort(subitems.begin(), subitems.end(), naturalSortLessThanCILibraryItem);
|
||||
|
||||
QString coverHash = "";
|
||||
for (auto item : subitems) {
|
||||
if (item->isDir()) {
|
||||
auto f = static_cast<Folder *>(item);
|
||||
auto firstChildHash = f->getFirstChildHash();
|
||||
if (!firstChildHash.isEmpty()) {
|
||||
coverHash = firstChildHash;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
auto c = static_cast<ComicDB *>(item);
|
||||
coverHash = c->info.hash;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
folder.setNumChildren(subfolders.count() + comics.count());
|
||||
folder.setFirstChildHash(coverHash);
|
||||
|
||||
QSqlQuery updateFolderInfo(db);
|
||||
updateFolderInfo.prepare("UPDATE folder SET "
|
||||
"numChildren = :numChildren, "
|
||||
@ -736,39 +785,30 @@ void DBHelper::updateChildrenInfo(const Folder &folder, QSqlDatabase &db)
|
||||
"WHERE id = :id ");
|
||||
updateFolderInfo.bindValue(":numChildren", folder.getNumChildren());
|
||||
updateFolderInfo.bindValue(":firstChildHash", folder.getFirstChildHash());
|
||||
updateFolderInfo.bindValue(":id", folder.id);
|
||||
updateFolderInfo.exec();
|
||||
}
|
||||
|
||||
void DBHelper::updateChildrenInfo(qulonglong folderId, QSqlDatabase &db)
|
||||
{
|
||||
QList<LibraryItem *> subfolders = DBHelper::getFoldersFromParent(folderId, db, false);
|
||||
QList<LibraryItem *> comics = DBHelper::getComicsFromParent(folderId, db, true);
|
||||
|
||||
ComicDB *firstComic = NULL;
|
||||
if (comics.count() > 0)
|
||||
firstComic = static_cast<ComicDB *>(comics.first());
|
||||
|
||||
QSqlQuery updateFolderInfo(db);
|
||||
updateFolderInfo.prepare("UPDATE folder SET "
|
||||
"numChildren = :numChildren, "
|
||||
"firstChildHash = :firstChildHash "
|
||||
"WHERE id = :id ");
|
||||
updateFolderInfo.bindValue(":numChildren", subfolders.count() + comics.count());
|
||||
updateFolderInfo.bindValue(":firstChildHash", firstComic != NULL ? firstComic->info.hash : "");
|
||||
updateFolderInfo.bindValue(":id", folderId);
|
||||
updateFolderInfo.exec();
|
||||
|
||||
qDeleteAll(subfolders);
|
||||
qDeleteAll(updatedSubfolders);
|
||||
qDeleteAll(comics);
|
||||
|
||||
return folder;
|
||||
}
|
||||
|
||||
void DBHelper::updateChildrenInfo(QSqlDatabase &db)
|
||||
{
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
|
||||
QSqlQuery selectQuery(db); // TODO check
|
||||
selectQuery.prepare("SELECT id FROM folder");
|
||||
selectQuery.prepare("SELECT id FROM folder f WHERE f.parentId = 1");
|
||||
selectQuery.exec();
|
||||
|
||||
while (selectQuery.next()) {
|
||||
DBHelper::updateChildrenInfo(selectQuery.value(0).toULongLong(), db);
|
||||
}
|
||||
|
||||
qDebug() << timer.elapsed();
|
||||
}
|
||||
|
||||
void DBHelper::updateProgress(qulonglong libraryId, const ComicInfo &comicInfo)
|
||||
|
@ -66,8 +66,8 @@ public:
|
||||
static void update(ComicInfo *comicInfo, QSqlDatabase &db);
|
||||
static void updateRead(ComicInfo *comicInfo, QSqlDatabase &db);
|
||||
static void update(const Folder &folder, QSqlDatabase &db);
|
||||
static void updateChildrenInfo(const Folder &folder, QSqlDatabase &db);
|
||||
static void updateChildrenInfo(qulonglong folderId, QSqlDatabase &db);
|
||||
static void propagateFolderUpdatesToParent(const Folder &folder, QSqlDatabase &db);
|
||||
static Folder updateChildrenInfo(qulonglong folderId, QSqlDatabase &db);
|
||||
static void updateChildrenInfo(QSqlDatabase &db);
|
||||
static void updateProgress(qulonglong libraryId, const ComicInfo &comicInfo);
|
||||
static void setComicAsReading(qulonglong libraryId, const ComicInfo &comicInfo);
|
||||
|
@ -185,9 +185,10 @@ void LibraryCreator::run()
|
||||
update(QDir(_source));
|
||||
}
|
||||
|
||||
if (partialUpdate)
|
||||
DBHelper::updateChildrenInfo(folderDestinationModelIndex.data(FolderModel::IdRole).toULongLong(), _database);
|
||||
else
|
||||
if (partialUpdate) {
|
||||
auto folder = DBHelper::updateChildrenInfo(folderDestinationModelIndex.data(FolderModel::IdRole).toULongLong(), _database);
|
||||
DBHelper::propagateFolderUpdatesToParent(folder, _database);
|
||||
} else
|
||||
DBHelper::updateChildrenInfo(_database);
|
||||
|
||||
_database.commit();
|
||||
@ -199,9 +200,9 @@ void LibraryCreator::run()
|
||||
// si estabamos en modo creación, se está añadiendo una librería que ya existía y se ha actualizado antes de añadirse.
|
||||
if (!partialUpdate) {
|
||||
if (!creation) {
|
||||
emit(updated());
|
||||
emit updated();
|
||||
} else {
|
||||
emit(created());
|
||||
emit created();
|
||||
}
|
||||
}
|
||||
QLOG_INFO() << "Update library END";
|
||||
@ -377,16 +378,20 @@ void LibraryCreator::update(QDir dirS)
|
||||
bool updated;
|
||||
int i, j;
|
||||
for (i = 0, j = 0; (i < lenghtS) || (j < lenghtD);) {
|
||||
if (stopRunning)
|
||||
if (stopRunning) {
|
||||
qDeleteAll(listD);
|
||||
return;
|
||||
}
|
||||
updated = false;
|
||||
if (i >= lenghtS) // finished source files/dirs
|
||||
{
|
||||
// QLOG_WARN() << "finished source files/dirs" << dirS.absolutePath();
|
||||
// delete listD //from j
|
||||
for (; j < lenghtD; j++) {
|
||||
if (stopRunning)
|
||||
if (stopRunning) {
|
||||
qDeleteAll(listD);
|
||||
return;
|
||||
}
|
||||
DBHelper::removeFromDB(listD.at(j), (_database));
|
||||
}
|
||||
updated = true;
|
||||
@ -396,8 +401,10 @@ void LibraryCreator::update(QDir dirS)
|
||||
// QLOG_WARN() << "finished library files/dirs" << dirS.absolutePath();
|
||||
// create listS //from i
|
||||
for (; i < lenghtS; i++) {
|
||||
if (stopRunning)
|
||||
if (stopRunning) {
|
||||
qDeleteAll(listD);
|
||||
return;
|
||||
}
|
||||
QFileInfo fileInfoS = listS.at(i);
|
||||
if (fileInfoS.isDir()) // create folder
|
||||
{
|
||||
@ -548,4 +555,6 @@ void LibraryCreator::update(QDir dirS)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qDeleteAll(listD);
|
||||
}
|
||||
|
@ -308,5 +308,7 @@ void FolderController::service(HttpRequest &request, HttpResponse &response)
|
||||
t.setVariable("page", QString("%1").arg(page + 1));
|
||||
t.setVariable("pages", QString("%1").arg(numPages));
|
||||
|
||||
qDeleteAll(folderContent);
|
||||
|
||||
response.write(t.toUtf8(), true);
|
||||
}
|
||||
|
@ -63,6 +63,8 @@ void FolderContentControllerV2::serviceContent(const int &library, const qulongl
|
||||
}
|
||||
}
|
||||
|
||||
qDeleteAll(folderContent);
|
||||
|
||||
QJsonDocument output(items);
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));
|
||||
|
@ -34,6 +34,9 @@ Folder &Folder::operator=(const Folder &other)
|
||||
this->finished = other.finished;
|
||||
this->completed = other.completed;
|
||||
this->manga = other.manga;
|
||||
this->numChildren = other.numChildren;
|
||||
this->firstChildHash = other.firstChildHash;
|
||||
this->customImage = other.customImage;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user