From fa72e4952344c85b34cfe8eabe5c51b9f7090e69 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 12 Nov 2019 16:51:11 +0000 Subject: Don't assume packages and categories are present They might be missing because caching --- gentoobrowse/src/packages.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/gentoobrowse/src/packages.cpp b/gentoobrowse/src/packages.cpp index c6e01fb..3ef592d 100644 --- a/gentoobrowse/src/packages.cpp +++ b/gentoobrowse/src/packages.cpp @@ -58,21 +58,25 @@ namespace GentooBrowse { if (_responseModel->user) { _ar_t = prx1->trackedAsync(_responseModel->user->userid); } - auto ebuilds = _ar_ebuilds.get(); - auto packages = GentooBrowse::makeMap(_ar_packages.get(), [](auto p){ return p->packageid; }); - auto categories = GentooBrowse::makeMap(_ar_categories.get(), [](auto c){ return c->categoryid; }); + const auto ebuilds = _ar_ebuilds.get(); + const auto packages = GentooBrowse::makeMap(_ar_packages.get(), [](auto p){ return p->packageid; }); + const auto categories = GentooBrowse::makeMap(_ar_categories.get(), [](auto c){ return c->categoryid; }); ::Gentoo::PackageIds tracked; if (_responseModel->user) { tracked = _ar_t.get(); } for(const auto & ebuild : ebuilds) { - auto & p = packages[ebuild->packageid]; - auto & c = categories[p->categoryid]; - auto & s = _responseModel->syncs[ebuild->firstseen.substr(0, 10)]; - bool isTracked = std::find(tracked.begin(), tracked.end(), p->packageid) != tracked.end(); - auto & pw = s[{ isTracked, c->name }][{ isTracked, p->name }]; - if (!pw.detail) pw.detail = p; - pw.ebuilds.push_back(ebuild); + if (auto pi = packages.find(ebuild->packageid); pi != packages.end()) { + auto & p = pi->second; + if (auto ci = categories.find(p->categoryid); ci != categories.end()) { + auto & c = ci->second; + auto & s = _responseModel->syncs[ebuild->firstseen.substr(0, 10)]; + bool isTracked = std::find(tracked.begin(), tracked.end(), p->packageid) != tracked.end(); + auto & pw = s[{ isTracked, c->name }][{ isTracked, p->name }]; + if (!pw.detail) pw.detail = p; + pw.ebuilds.push_back(ebuild); + } + } } request->response(this, _responseModel); } -- cgit v1.2.3