Small RemoteLibrary async query race condition fix, and tweaked a couple

other minor things to improve TrackListView redraws.
This commit is contained in:
Casey Langen 2020-10-27 18:27:08 -07:00
parent 38c5e5c9fd
commit 10072762e1
5 changed files with 21 additions and 8 deletions

View File

@ -46,7 +46,6 @@
static const std::string TAG = "LocalLibrary";
static bool scheduleSyncDueToDbUpgrade = false;
static int kWaitIndefinite = std::numeric_limits<int64_t>::max();
using namespace musik::core;
using namespace musik::core::library;

View File

@ -275,6 +275,7 @@ void RemoteLibrary::OnQueryCompleted(const std::string& messageId, Query query)
}
void RemoteLibrary::RunQuery(QueryContextPtr context) {
std::unique_lock<std::recursive_mutex> lock(this->queueMutex);
#if 0
this->RunQueryOnLoopback(context);
#else
@ -315,7 +316,6 @@ void RemoteLibrary::RunQueryOnLoopback(QueryContextPtr context) {
void RemoteLibrary::RunQueryOnWebSocketClient(QueryContextPtr context) {
if (context->query) {
std::unique_lock<std::recursive_mutex> lock(this->queueMutex);
const std::string messageId = wsc.EnqueueQuery(context->query);
if (messageId.size()) {
queriesInFlight[messageId] = context;

View File

@ -277,23 +277,33 @@ void TrackList::CacheWindow(size_t from, size_t to, bool async) const {
if (async) {
currentWindow.Set(from, to);
auto shared = shared_from_this(); /* ensure we remain alive for the duration of the query */
this->library->EnqueueAndWait(query, 50LL, [this, shared, from, to, query](auto q) {
bool completionFinished = false;
auto completion = [this, &completionFinished, shared, from, to, query](auto q) {
if (completionFinished) {
return;
}
if (query->GetStatus() == IQuery::Finished) {
auto& result = query->Result();
for (auto& kv : result) {
this->AddToCache(kv.first, kv.second);
}
}
this->currentWindow.Reset();
if (this->nextWindow.Valid()) {
size_t from = nextWindow.from, to = nextWindow.to;
nextWindow.Reset();
this->CacheWindow(from, to, true);
}
this->WindowCached(const_cast<TrackList*>(this), from, to);
});
completionFinished = true;
};
this->library->EnqueueAndWait(query, 75LL, completion);
auto status = query->GetStatus();
if (status != IQuery::Idle && status != IQuery::Running) {
completion(query);
}
}
else {
this->library->EnqueueAndWait(query);

View File

@ -54,7 +54,7 @@ using namespace cursespp;
#define DIGITS(x) (x > 9 ? (int) log10((double) x) + 1 : 1)
static const bool kEnableSkeletonRows = true;
static const std::string kSkeletonChar = "";
static const std::string kSkeletonChar = "-"; // "░";
static const int kDurationColWidth = 5; /* 00:00 */
static const int kRatingBreakpointWidth = 90;

View File

@ -51,6 +51,7 @@
#include <app/overlay/TrackOverlays.h>
#define WINDOW_MESSAGE_SCROLL_TO_PLAYING 1003
#define WINDOW_MESSAGE_TRACK_LIST_WINDOW_CACHED 1004
/* this is pretty gross, but i think we'll eventually settle on one versus the other
and i don't want to bother adding a bunch of annoying infrastructure to more
@ -123,7 +124,7 @@ void TrackListView::SetRowRenderer(TrackRowRenderers::Renderer renderer) {
}
void TrackListView::OnTrackListWindowCached(const musik::core::TrackList* track, size_t from, size_t to) {
this->Redraw();
this->Debounce(WINDOW_MESSAGE_TRACK_LIST_WINDOW_CACHED, 0, 0, 50);
}
void TrackListView::OnQueryCompleted(IQuery* query) {
@ -243,6 +244,9 @@ void TrackListView::ProcessMessage(IMessage &message) {
if (message.Type() == WINDOW_MESSAGE_SCROLL_TO_PLAYING) {
this->ScrollToPlaying();
}
else if (message.Type() == WINDOW_MESSAGE_TRACK_LIST_WINDOW_CACHED) {
this->Redraw();
}
else {
ListWindow::ProcessMessage(message);
}