mirror of
https://github.com/YACReader/yacreader
synced 2025-07-18 04:54:29 -04:00
updating folders' children info for every insert/delete in the db causes big performance issues, so that info is going to be updated explicitly
This commit is contained in:
@ -172,11 +172,12 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const
|
||||
if(role == FolderModel::FinishedRole)
|
||||
return item->data(FolderModel::Finished);
|
||||
|
||||
if(role == FolderModel::IdRole)
|
||||
return item->id;
|
||||
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
|
||||
|
||||
return item->data(index.column());
|
||||
}
|
||||
//! [3]
|
||||
@ -305,7 +306,7 @@ void FolderModel::setupModelData(QSqlQuery &sqlquery, FolderItem *parent)
|
||||
//el diccionario permitir<69> encontrar cualquier nodo del <20>rbol r<>pidamente, de forma que a<>adir un hijo a un padre sea O(1)
|
||||
items.clear();
|
||||
//se a<>ade el nodo 0
|
||||
items.insert(parent->id,parent);
|
||||
items.insert(parent->id,parent);
|
||||
|
||||
while (sqlquery.next()) {
|
||||
QList<QVariant> data;
|
||||
@ -535,6 +536,7 @@ QModelIndex FolderModel::addFolderAtParent(const QString &folderName, const QMod
|
||||
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
newFolder.id = DBHelper::insert(&newFolder, db);
|
||||
DBHelper::updateChildrenInfo(parentItem->id, db);
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
|
||||
int destRow = 0;
|
||||
@ -573,11 +575,18 @@ void FolderModel::deleteFolder(const QModelIndex &mi)
|
||||
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
DBHelper::removeFromDB(&f,db);
|
||||
DBHelper::updateChildrenInfo(item->parent()->id, db);
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void FolderModel::updateFolderChildrenInfo(qulonglong folderId)
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
DBHelper::updateChildrenInfo(folderId, db);
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
}
|
||||
|
||||
//PROXY
|
||||
|
||||
|
Reference in New Issue
Block a user