From 48ef2257966b75509e4e132ce6ee9e30f31e046f Mon Sep 17 00:00:00 2001 From: cmitu <31816814+cmitu@users.noreply.github.com> Date: Mon, 8 Aug 2022 18:07:46 +0100 Subject: [PATCH] ViewController: improve bulk removal of entries Added an extra parameter for the `remove` call, hinting that a refresh of the View is not desired. This skips any `onFileChanged` event called at the end of `remove`, leaving it to the caller to explicitely call the `onFileChanged` method. The skip decreases the time spent in `remove`. The sole usage - right now - is during the initial built-in collections creation, when the `recent` collection trimming can take a long time when it has >>50 entries. --- es-app/src/CollectionSystemManager.cpp | 9 +++++---- es-app/src/guis/GuiGamelistOptions.cpp | 2 +- es-app/src/views/gamelist/BasicGameListView.cpp | 5 +++-- es-app/src/views/gamelist/BasicGameListView.h | 2 +- es-app/src/views/gamelist/GridGameListView.cpp | 6 ++++-- es-app/src/views/gamelist/GridGameListView.h | 2 +- es-app/src/views/gamelist/IGameListView.h | 2 +- 7 files changed, 16 insertions(+), 12 deletions(-) diff --git a/es-app/src/CollectionSystemManager.cpp b/es-app/src/CollectionSystemManager.cpp index 372c64bf41..458f0e400a 100644 --- a/es-app/src/CollectionSystemManager.cpp +++ b/es-app/src/CollectionSystemManager.cpp @@ -260,7 +260,7 @@ void CollectionSystemManager::updateCollectionSystem(FileData* file, CollectionS // found and we are removing if (name == "favorites" && file->metadata.get("favorite") == "false") { // need to check if still marked as favorite, if not remove - ViewController::get()->getGameListView(curSys).get()->remove(collectionEntry, false); + ViewController::get()->getGameListView(curSys).get()->remove(collectionEntry, false, true); } else { @@ -298,8 +298,9 @@ void CollectionSystemManager::trimCollectionCount(FileData* rootFolder, int limi while ((int)rootFolder->getChildrenListToDisplay().size() > limit) { CollectionFileData* gameToRemove = (CollectionFileData*)rootFolder->getChildrenListToDisplay().back(); - ViewController::get()->getGameListView(curSys).get()->remove(gameToRemove, false); + ViewController::get()->getGameListView(curSys).get()->remove(gameToRemove, false, false); } + ViewController::get()->onFileChanged(rootFolder, FILE_REMOVED); } // deletes all collection files from collection systems related to the source file @@ -323,7 +324,7 @@ void CollectionSystemManager::deleteCollectionFiles(FileData* file) sysDataIt->second.needsSave = true; FileData* collectionEntry = children.at(key); SystemData* systemViewToUpdate = getSystemToView(sysDataIt->second.system); - ViewController::get()->getGameListView(systemViewToUpdate).get()->remove(collectionEntry, false); + ViewController::get()->getGameListView(systemViewToUpdate).get()->remove(collectionEntry, false, true); } } } @@ -495,7 +496,7 @@ bool CollectionSystemManager::toggleGameInCollection(FileData* file, int pressco { systemViewToUpdate->getIndex()->removeFromIndex(collectionEntry); } - ViewController::get()->getGameListView(systemViewToUpdate).get()->remove(collectionEntry, false); + ViewController::get()->getGameListView(systemViewToUpdate).get()->remove(collectionEntry, false, true); } else { diff --git a/es-app/src/guis/GuiGamelistOptions.cpp b/es-app/src/guis/GuiGamelistOptions.cpp index 60cddcf6ed..d7127731ee 100644 --- a/es-app/src/guis/GuiGamelistOptions.cpp +++ b/es-app/src/guis/GuiGamelistOptions.cpp @@ -194,7 +194,7 @@ void GuiGamelistOptions::openMetaDataEd() { deleteBtnFunc = [this, file] { CollectionSystemManager::get()->deleteCollectionFiles(file); - ViewController::get()->getGameListView(file->getSystem()).get()->remove(file, true); + ViewController::get()->getGameListView(file->getSystem()).get()->remove(file, true, true); }; } diff --git a/es-app/src/views/gamelist/BasicGameListView.cpp b/es-app/src/views/gamelist/BasicGameListView.cpp index 4e83adac56..e453b86dad 100644 --- a/es-app/src/views/gamelist/BasicGameListView.cpp +++ b/es-app/src/views/gamelist/BasicGameListView.cpp @@ -112,7 +112,7 @@ void BasicGameListView::launch(FileData* game) ViewController::get()->launch(game); } -void BasicGameListView::remove(FileData *game, bool deleteFile) +void BasicGameListView::remove(FileData *game, bool deleteFile, bool refreshView) { if (deleteFile) { @@ -184,7 +184,8 @@ void BasicGameListView::remove(FileData *game, bool deleteFile) addPlaceholder(); } delete game; // remove before repopulating (removes from parent) - onFileChanged(parent, FILE_REMOVED); // update the view, with game removed + if(refreshView) + onFileChanged(parent, FILE_REMOVED); // update the view, with game removed } std::vector BasicGameListView::getHelpPrompts() diff --git a/es-app/src/views/gamelist/BasicGameListView.h b/es-app/src/views/gamelist/BasicGameListView.h index 305e6feeb3..c2387d83db 100644 --- a/es-app/src/views/gamelist/BasicGameListView.h +++ b/es-app/src/views/gamelist/BasicGameListView.h @@ -29,7 +29,7 @@ class BasicGameListView : public ISimpleGameListView virtual std::string getQuickSystemSelectRightButton() override; virtual std::string getQuickSystemSelectLeftButton() override; virtual void populateList(const std::vector& files) override; - virtual void remove(FileData* game, bool deleteFile) override; + virtual void remove(FileData* game, bool deleteFile, bool refreshView=true) override; virtual void addPlaceholder(); TextListComponent mList; diff --git a/es-app/src/views/gamelist/GridGameListView.cpp b/es-app/src/views/gamelist/GridGameListView.cpp index 30078d51e4..f44cdf1a5e 100644 --- a/es-app/src/views/gamelist/GridGameListView.cpp +++ b/es-app/src/views/gamelist/GridGameListView.cpp @@ -411,7 +411,7 @@ void GridGameListView::launch(FileData* game) } -void GridGameListView::remove(FileData *game, bool deleteFile) +void GridGameListView::remove(FileData *game, bool deleteFile, bool refreshView) { if (deleteFile) Utils::FileSystem::removeFile(game->getPath()); // actually delete the file on the filesystem @@ -437,7 +437,9 @@ void GridGameListView::remove(FileData *game, bool deleteFile) addPlaceholder(); } delete game; // remove before repopulating (removes from parent) - onFileChanged(parent, FILE_REMOVED); // update the view, with game removed + + if(refreshView) + onFileChanged(parent, FILE_REMOVED); // update the view, with game removed } std::vector GridGameListView::getMDLabels() diff --git a/es-app/src/views/gamelist/GridGameListView.h b/es-app/src/views/gamelist/GridGameListView.h index 4012ab4a64..e0f55e78d4 100644 --- a/es-app/src/views/gamelist/GridGameListView.h +++ b/es-app/src/views/gamelist/GridGameListView.h @@ -36,7 +36,7 @@ class GridGameListView : public ISimpleGameListView virtual std::string getQuickSystemSelectRightButton() override; virtual std::string getQuickSystemSelectLeftButton() override; virtual void populateList(const std::vector& files) override; - virtual void remove(FileData* game, bool deleteFile) override; + virtual void remove(FileData* game, bool deleteFile, bool refreshView=true) override; virtual void addPlaceholder(); ImageGridComponent mGrid; diff --git a/es-app/src/views/gamelist/IGameListView.h b/es-app/src/views/gamelist/IGameListView.h index da6299d274..f4c1eed42b 100644 --- a/es-app/src/views/gamelist/IGameListView.h +++ b/es-app/src/views/gamelist/IGameListView.h @@ -33,7 +33,7 @@ class IGameListView : public GuiComponent virtual void setCursor(FileData*) = 0; virtual bool input(InputConfig* config, Input input) override; - virtual void remove(FileData* game, bool deleteFile) = 0; + virtual void remove(FileData* game, bool deleteFile, bool refreshView=true) = 0; virtual const char* getName() const = 0; virtual void launch(FileData* game) = 0;