From 3d8c0046a8132e47a5688bb0045e7e5757d6cbcf Mon Sep 17 00:00:00 2001 From: David Sansome Date: Tue, 8 Nov 2011 21:49:20 +0000 Subject: [PATCH] Don't allow providers to return more than 100 results at a time. --- src/globalsearch/globalsearch.cpp | 10 ++++++++++ src/globalsearch/globalsearch.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/globalsearch/globalsearch.cpp b/src/globalsearch/globalsearch.cpp index 32e5af31a..b104d2f20 100644 --- a/src/globalsearch/globalsearch.cpp +++ b/src/globalsearch/globalsearch.cpp @@ -26,6 +26,7 @@ const int GlobalSearch::kDelayedSearchTimeoutMs = 200; const char* GlobalSearch::kSettingsGroup = "GlobalSearch"; +const int GlobalSearch::kMaxResultsPerEmission = 100; GlobalSearch::GlobalSearch(QObject* parent) @@ -126,6 +127,15 @@ void GlobalSearch::ResultsAvailableSlot(int id, SearchProvider::ResultList resul if (results.isEmpty()) return; + // Limit the number of results that are used from each emission. + // Just a sanity check to stop some providers (Jamendo) returning thousands + // of results. + if (results.count() > kMaxResultsPerEmission) { + SearchProvider::ResultList::iterator begin = results.begin(); + std::advance(begin, kMaxResultsPerEmission); + results.erase(begin, results.end()); + } + // Load cached pixmaps into the results for (SearchProvider::ResultList::iterator it = results.begin() ; it != results.end() ; ++it) { it->pixmap_cache_key_ = PixmapCacheKey(*it); diff --git a/src/globalsearch/globalsearch.h b/src/globalsearch/globalsearch.h index 6f589bfc9..781ea4d84 100644 --- a/src/globalsearch/globalsearch.h +++ b/src/globalsearch/globalsearch.h @@ -35,6 +35,7 @@ public: static const int kDelayedSearchTimeoutMs; static const char* kSettingsGroup; + static const int kMaxResultsPerEmission; void AddProvider(SearchProvider* provider, bool enable_by_default = true); // Try to change provider state. Returns false if we can't (e.g. we can't