From c90dd0e818201131bf578f6f904c4c8a59113b90 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Tue, 3 Dec 2019 23:02:24 +0200 Subject: [PATCH 1/4] updated top most record --- Wox.Infrastructure/Storage/WoxJsonStorage.cs | 4 +- Wox.Plugin/Result.cs | 2 +- Wox/Storage/TopMostRecord.cs | 49 +++++++++++--------- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/Wox.Infrastructure/Storage/WoxJsonStorage.cs b/Wox.Infrastructure/Storage/WoxJsonStorage.cs index f117aee22..da0dbd073 100644 --- a/Wox.Infrastructure/Storage/WoxJsonStorage.cs +++ b/Wox.Infrastructure/Storage/WoxJsonStorage.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Wox.Infrastructure.Storage { - class WoxJsonStorage : JsonStrorage where T : new() + public class WoxJsonStorage : JsonStrorage where T : new() { public WoxJsonStorage() { @@ -18,4 +18,4 @@ namespace Wox.Infrastructure.Storage FilePath = Path.Combine(directoryPath, $"{filename}{FileSuffix}"); } } -} +} \ No newline at end of file diff --git a/Wox.Plugin/Result.cs b/Wox.Plugin/Result.cs index 2f7459170..592bcac5c 100644 --- a/Wox.Plugin/Result.cs +++ b/Wox.Plugin/Result.cs @@ -108,7 +108,7 @@ namespace Wox.Plugin public object ContextData { get; set; } /// - /// Plugin ID that generate this result + /// Plugin ID that generated this result /// public string PluginID { get; internal set; } } diff --git a/Wox/Storage/TopMostRecord.cs b/Wox/Storage/TopMostRecord.cs index 4d33f91eb..38cfbab8e 100644 --- a/Wox/Storage/TopMostRecord.cs +++ b/Wox/Storage/TopMostRecord.cs @@ -1,47 +1,52 @@ using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; +using Newtonsoft.Json; using Wox.Infrastructure.Storage; using Wox.Plugin; namespace Wox.Storage { + // todo this class is not thread safe.... but used from multiple threads. public class TopMostRecord { - public Dictionary records = new Dictionary(); + [JsonProperty] + private Dictionary records = new Dictionary(); internal bool IsTopMost(Result result) { + if (records.Count == 0) + { + return false; + } + + // since this dictionary should be very small (or empty) going over it should be pretty fast. return records.Any(o => o.Value.Title == result.Title - && o.Value.SubTitle == result.SubTitle - && o.Value.PluginID == result.PluginID - && o.Key == result.OriginQuery.RawQuery); + && o.Value.SubTitle == result.SubTitle + && o.Value.PluginID == result.PluginID + && o.Key == result.OriginQuery.RawQuery); } internal void Remove(Result result) { - if (records.ContainsKey(result.OriginQuery.RawQuery)) - { - records.Remove(result.OriginQuery.RawQuery); - } + records.Remove(result.OriginQuery.RawQuery); } internal void AddOrUpdate(Result result) { - if (records.ContainsKey(result.OriginQuery.RawQuery)) + var record = new Record { - records[result.OriginQuery.RawQuery].Title = result.Title; - records[result.OriginQuery.RawQuery].SubTitle = result.SubTitle; - records[result.OriginQuery.RawQuery].PluginID = result.PluginID; - } - else - { - records.Add(result.OriginQuery.RawQuery, new Record - { - PluginID = result.PluginID, - Title = result.Title, - SubTitle = result.SubTitle - }); - } + PluginID = result.PluginID, + Title = result.Title, + SubTitle = result.SubTitle + }; + records[result.OriginQuery.RawQuery] = record; + + } + + public void Load(Dictionary dictionary) + { + records = dictionary; } } From b3fdc4bb9602881fe908a27d479d385b0ff0cab6 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Tue, 3 Dec 2019 23:37:55 +0200 Subject: [PATCH 2/4] updated user selected record --- Wox/Storage/UserSelectedRecord.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Wox/Storage/UserSelectedRecord.cs b/Wox/Storage/UserSelectedRecord.cs index 900559041..ef8bf7f8e 100644 --- a/Wox/Storage/UserSelectedRecord.cs +++ b/Wox/Storage/UserSelectedRecord.cs @@ -12,21 +12,23 @@ namespace Wox.Storage public void Add(Result result) { - if (records.ContainsKey(result.ToString())) + var key = result.ToString(); + if (records.TryGetValue(key, out int value)) { - records[result.ToString()] += 1; + records[key] = value + 1; } else { - records.Add(result.ToString(), 1); + records.Add(key, 1); + } } public int GetSelectedCount(Result result) { - if (records.ContainsKey(result.ToString())) + if (records.TryGetValue(result.ToString(), out int value)) { - return records[result.ToString()]; + return value; } return 0; } From 02511b77852ff29f4f4e9c4306b1949e0a18eaf6 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Wed, 4 Dec 2019 00:15:46 +0200 Subject: [PATCH 3/4] some more --- Wox/ViewModel/MainViewModel.cs | 8 +++++--- Wox/ViewModel/ResultsViewModel.cs | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs index 1a12d6c8c..153caa55d 100644 --- a/Wox/ViewModel/MainViewModel.cs +++ b/Wox/ViewModel/MainViewModel.cs @@ -419,6 +419,11 @@ namespace Wox.ViewModel UpdateResultView(results, plugin.Metadata, query); } }); + + // this should happen once after all queries are done so progress bar should continue + // until the end of all querying + _queryHasReturn = true; + ProgressBarVisibility = Visibility.Hidden; }, _updateToken); } } @@ -627,9 +632,6 @@ namespace Wox.ViewModel /// public void UpdateResultView(List list, PluginMetadata metadata, Query originQuery) { - _queryHasReturn = true; - ProgressBarVisibility = Visibility.Hidden; - foreach (var result in list) { if (_topMostRecord.IsTopMost(result)) diff --git a/Wox/ViewModel/ResultsViewModel.cs b/Wox/ViewModel/ResultsViewModel.cs index 674923228..1175cd8c3 100644 --- a/Wox/ViewModel/ResultsViewModel.cs +++ b/Wox/ViewModel/ResultsViewModel.cs @@ -155,7 +155,6 @@ namespace Wox.ViewModel // Find the same results in A (old results) and B (new newResults) var sameResults = oldResults .Where(t1 => newResults.Any(x => x.Result.Equals(t1.Result))) - .Select(t1 => t1) .ToList(); // remove result of relative complement of B in A From a2d685815fd8775c1996d1bb6040c98b9607f3b7 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Fri, 6 Dec 2019 22:36:00 +0200 Subject: [PATCH 4/4] updated --- Wox/Storage/TopMostRecord.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Wox/Storage/TopMostRecord.cs b/Wox/Storage/TopMostRecord.cs index 38cfbab8e..5f940f218 100644 --- a/Wox/Storage/TopMostRecord.cs +++ b/Wox/Storage/TopMostRecord.cs @@ -1,8 +1,6 @@ using System.Collections.Generic; using System.Linq; -using System.Runtime.InteropServices; using Newtonsoft.Json; -using Wox.Infrastructure.Storage; using Wox.Plugin; namespace Wox.Storage