1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-17 03:45:56 +01:00

Don't allow providers to return more than 100 results at a time.

This commit is contained in:
David Sansome 2011-11-08 21:49:20 +00:00
parent d7720223ec
commit 3d8c0046a8
2 changed files with 11 additions and 0 deletions

View File

@ -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);

View File

@ -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