From 1eae55e3bba335d41da0d21dfc383b838d9f0d03 Mon Sep 17 00:00:00 2001 From: Krateng Date: Sun, 26 Jul 2020 18:09:41 +0200 Subject: [PATCH] Fixed race condition in search --- maloja/__pkginfo__.py | 2 +- .../rules/predefined/krateng_kpopgirlgroups.tsv | 6 ++++++ maloja/static/js/search.js | 8 +++++--- maloja/thirdparty/musicbrainz.py | 1 - 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/maloja/__pkginfo__.py b/maloja/__pkginfo__.py index 78c0d3c..888b9c1 100644 --- a/maloja/__pkginfo__.py +++ b/maloja/__pkginfo__.py @@ -5,7 +5,7 @@ author = { "email":"maloja@krateng.dev", "github": "krateng" } -version = 2,6,0 +version = 2,6,1 versionstr = ".".join(str(n) for n in version) links = { "pypi":"malojaserver", diff --git a/maloja/data_files/rules/predefined/krateng_kpopgirlgroups.tsv b/maloja/data_files/rules/predefined/krateng_kpopgirlgroups.tsv index f597e8d..7164e2f 100644 --- a/maloja/data_files/rules/predefined/krateng_kpopgirlgroups.tsv +++ b/maloja/data_files/rules/predefined/krateng_kpopgirlgroups.tsv @@ -145,6 +145,7 @@ replaceartist 여자친구 GFriend GFriend # Girl's Generation replaceartist 소녀시대 Girls' Generation +replaceartist SNSD Girls' Generation # Apink replaceartist A Pink Apink @@ -162,6 +163,11 @@ replacetitle 달라달라 (DALLA DALLA) Dalla Dalla # K/DA belongtogether K/DA +# 2NE1 +countas CL 2NE1 + +# WJSN +replaceartist Cosmic Girls WJSN # Popular Remixes artistintitle Areia Remix Areia diff --git a/maloja/static/js/search.js b/maloja/static/js/search.js index 4aeef8f..4afa5be 100644 --- a/maloja/static/js/search.js +++ b/maloja/static/js/search.js @@ -1,4 +1,4 @@ - +var searches = [] function search(searchfield) { txt = searchfield.value; @@ -7,6 +7,7 @@ function search(searchfield) { } else { xhttp = new XMLHttpRequest(); + searches.push(xhttp) xhttp.onreadystatechange = searchresult xhttp.open("GET","/api/search?max=5&query=" + encodeURIComponent(txt), true); xhttp.send(); @@ -45,8 +46,9 @@ const oneresult = html_to_fragment(resulthtml).firstElementChild; function searchresult() { - if (this.readyState == 4 && this.status == 200 && document.getElementById("searchinput").value != "") { - // checking if field is empty in case we get an old result coming in that would overwrite our cleared result window + if (this.readyState == 4 && this.status == 200 && document.getElementById("searchinput").value != "" && searches.includes(this)) { + // any older searches are now rendered irrelevant + while (searches[0] != this) { searches.splice(0,1) } var result = JSON.parse(this.responseText); var artists = result["artists"].slice(0,5) var tracks = result["tracks"].slice(0,5) diff --git a/maloja/thirdparty/musicbrainz.py b/maloja/thirdparty/musicbrainz.py index f562039..b45e50c 100644 --- a/maloja/thirdparty/musicbrainz.py +++ b/maloja/thirdparty/musicbrainz.py @@ -57,7 +57,6 @@ class MusicBrainz(MetadataInterface): return self.metadata_parse_response_track(data) except: - raise return None finally: time.sleep(2)