reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 3449d6106f42b6ed763e1c2b32da76092a117db5
parent c0150c4548bbe7705cc3481faadc39722e0dc9ba
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Thu, 14 Sep 2017 20:57:14 -0400

browser: reuse the transaction's database instead of reopening it

Diffstat:
Msrc/browser.cpp | 47++++++++++++++++++-----------------------------
Msrc/browser.hpp | 3++-
2 files changed, 20 insertions(+), 30 deletions(-)

diff --git a/src/browser.cpp b/src/browser.cpp @@ -410,7 +410,8 @@ void Browser::refresh(const bool stale) "Browse packages", MB_OK); } - populate({}); + // Clear the list if it were previously filled. + populate({}, nullptr); return; } @@ -421,7 +422,7 @@ void Browser::refresh(const bool stale) tx->fetchIndexes(remotes, stale); tx->onFinish([=] { if(isFirstLoad || isVisible()) { - populate(tx->getIndexes(remotes)); + populate(tx->getIndexes(remotes), tx->registry()); // Ignore the next call to refreshBrowser() if we know we'll be // requested to handle the very same transaction. @@ -439,40 +440,28 @@ void Browser::refresh(const bool stale) } } -void Browser::populate(const vector<IndexPtr> &indexes) +void Browser::populate(const vector<IndexPtr> &indexes, const Registry *reg) { - try { - Registry reg(Path::REGISTRY.prependRoot()); + // keep previous entries in memory a bit longer for #transferActions + vector<Entry> oldEntries; + swap(m_entries, oldEntries); - // keep previous entries in memory a bit longer for #transferActions - vector<Entry> oldEntries; - swap(m_entries, oldEntries); + m_currentIndex = -1; - m_currentIndex = -1; + for(const IndexPtr &index : indexes) { + for(const Package *pkg : index->packages()) + m_entries.push_back({pkg, reg->getEntry(pkg), index}); - for(const IndexPtr &index : indexes) { - for(const Package *pkg : index->packages()) - m_entries.push_back({pkg, reg.getEntry(pkg), index}); - - // obsolete packages - for(const Registry::Entry &regEntry : reg.getEntries(index->name())) { - if(!index->find(regEntry.category, regEntry.package)) - m_entries.push_back({regEntry, index}); - } + // obsolete packages + for(const Registry::Entry &regEntry : reg->getEntries(index->name())) { + if(!index->find(regEntry.category, regEntry.package)) + m_entries.push_back({regEntry, index}); } - - transferActions(); - fillList(); - } - catch(const reapack_error &e) { - char msg[255]; - snprintf(msg, sizeof(msg), - "ReaPack could not read from the local package registry.\n" - "Retry later once all installation task are completed.\n\n" - "Error description: %s", e.what()); - Win32::messageBox(handle(), msg, "ReaPack", MB_OK); } + transferActions(); + fillList(); + if(!isVisible()) show(); } diff --git a/src/browser.hpp b/src/browser.hpp @@ -33,6 +33,7 @@ class Index; class ListView; class Menu; +class Registry; class Version; typedef std::shared_ptr<const Index> IndexPtr; @@ -88,7 +89,7 @@ private: void onSelection(); bool fillContextMenu(Menu &, int index); - void populate(const std::vector<IndexPtr> &); + void populate(const std::vector<IndexPtr> &, const Registry *); void transferActions(); bool match(const Entry &) const; void updateFilter();