From c49b3b7cba86ffadaec56e748751041f5e5c47c1 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 1 May 2025 13:42:54 +0800 Subject: [PATCH] Fix TryTake may remove the wrong element --- Flow.Launcher/Storage/TopMostRecord.cs | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/Flow.Launcher/Storage/TopMostRecord.cs b/Flow.Launcher/Storage/TopMostRecord.cs index 7c45bcf66..0a9921f73 100644 --- a/Flow.Launcher/Storage/TopMostRecord.cs +++ b/Flow.Launcher/Storage/TopMostRecord.cs @@ -189,11 +189,8 @@ namespace Flow.Launcher.Storage } // remove the record from the bag - var recordToRemove = value.FirstOrDefault(r => r.Equals(result)); - if (recordToRemove != null) - { - value.TryTake(out recordToRemove); - } + var bag = new ConcurrentQueue(value.Where(r => !r.Equals(result))); + records[result.OriginQuery.RawQuery] = new ConcurrentBag(bag); // if the bag is empty, remove the bag from the dictionary if (value.IsEmpty) @@ -230,21 +227,9 @@ namespace Flow.Launcher.Storage else { // add or update the record in the bag - if (value.Any(r => r.Equals(result))) - { - // update the record - var recordToUpdate = value.FirstOrDefault(r => r.Equals(result)); - if (recordToUpdate != null) - { - value.TryTake(out recordToUpdate); - value.Add(record); - } - } - else - { - // add the record - value.Add(record); - } + var bag = new ConcurrentQueue(value.Where(r => !r.Equals(result))); // make sure we don't have duplicates + bag.Enqueue(record); + records[result.OriginQuery.RawQuery] = new ConcurrentBag(bag); } } }