mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Introduce concurrent directionary for topmost record
This commit is contained in:
parent
0720779c6b
commit
b95bbb3e6a
1 changed files with 7 additions and 9 deletions
|
|
@ -1,18 +1,18 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using Flow.Launcher.Plugin;
|
||||
|
||||
namespace Flow.Launcher.Storage
|
||||
{
|
||||
// todo this class is not thread safe.... but used from multiple threads.
|
||||
public class TopMostRecord
|
||||
{
|
||||
[JsonInclude]
|
||||
public Dictionary<string, Record> records { get; private set; } = new Dictionary<string, Record>();
|
||||
public ConcurrentDictionary<string, Record> records { get; private set; } = new ConcurrentDictionary<string, Record>();
|
||||
|
||||
internal bool IsTopMost(Result result)
|
||||
{
|
||||
if (records.Count == 0 || (result.OriginQuery != null && !records.ContainsKey(result.OriginQuery.RawQuery)))
|
||||
if (records.IsEmpty || (result.OriginQuery != null && !records.ContainsKey(result.OriginQuery.RawQuery)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ namespace Flow.Launcher.Storage
|
|||
|
||||
internal void Remove(Result result)
|
||||
{
|
||||
records.Remove(result.OriginQuery.RawQuery);
|
||||
records.Remove(result.OriginQuery.RawQuery, out _);
|
||||
}
|
||||
|
||||
internal void AddOrUpdate(Result result)
|
||||
|
|
@ -34,17 +34,15 @@ namespace Flow.Launcher.Storage
|
|||
Title = result.Title,
|
||||
SubTitle = result.SubTitle
|
||||
};
|
||||
records[result.OriginQuery.RawQuery] = record;
|
||||
|
||||
records.AddOrUpdate(result.OriginQuery.RawQuery, record, (key, oldValue) => record);
|
||||
}
|
||||
|
||||
public void Load(Dictionary<string, Record> dictionary)
|
||||
{
|
||||
records = dictionary;
|
||||
records = new ConcurrentDictionary<string, Record>(dictionary);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class Record
|
||||
{
|
||||
public string Title { get; set; }
|
||||
|
|
|
|||
Loading…
Reference in a new issue