From 49f53c07bbc3148543e3141c54ca788d7a981df1 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Sun, 22 Jun 2014 13:48:35 +0200 Subject: [PATCH] Use list in media library when listallinfo is overkill When the media library is not sorted by mtime and not in two column mode, there is no reason to use listallinfo/GetDirectoryRecursive, instead of list/GetList. Using list instead of listallinfo is desired because listallinfo may be slow, fetches a lot more data than necessary in this case and because the MPD reference says this about listallinfo: Do not use this command. Do not manage a client-side copy of MPD's database. That is fragile and adds huge overhead. It will break with large databases. Instead, query MPD whenever you need something. --- src/media_library.cpp | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/media_library.cpp b/src/media_library.cpp index 54775646..9e9fd2d8 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -297,19 +297,28 @@ void MediaLibrary::update() Tags.clearSearchResults(); m_tags_update_request = false; std::map tags; - Mpd.GetDirectoryRecursive("/", [&tags](MPD::Song s) { - unsigned idx = 0; - std::string tag = s.get(Config.media_lib_primary_tag, idx); - do - { - auto it = tags.find(tag); - if (it == tags.end()) - tags[tag] = s.getMTime(); - else - it->second = std::max(it->second, s.getMTime()); - } - while (!(tag = s.get(Config.media_lib_primary_tag, ++idx)).empty()); - }); + if (Config.media_library_sort_by_mtime) + { + Mpd.GetDirectoryRecursive("/", [&tags](MPD::Song s) { + unsigned idx = 0; + std::string tag = s.get(Config.media_lib_primary_tag, idx); + do + { + auto it = tags.find(tag); + if (it == tags.end()) + tags[tag] = s.getMTime(); + else + it->second = std::max(it->second, s.getMTime()); + } + while (!(tag = s.get(Config.media_lib_primary_tag, ++idx)).empty()); + }); + } + else + { + Mpd.GetList(Config.media_lib_primary_tag, [&tags](std::string tag) { + tags[tag] = 0; + }); + } withUnfilteredMenuReapplyFilter(Tags, [this, &tags]() { size_t idx = 0; for (auto it = tags.begin(); it != tags.end(); ++it, ++idx) @@ -901,8 +910,7 @@ void MediaLibrary::toggleSortMode() } else { - std::sort(Tags.beginV(), Tags.endV(), SortPrimaryTags()); - Tags.refresh(); + Tags.clear(); Albums.clear(); Songs.clear(); }