mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
Revert "Improving performance of Adding and Removing Packaged Apps" (#4898)
* Revert "Adding newline to end of file for IProgramRepository" This reverts commitd55cac80bf. * Revert "Fixing comments" This reverts commita1ecdc9bfa. * Revert "Restoring checks for invalid uwp apps based on PR feedback. This was accidentally removed when moving the initialize outside the constructor." This reverts commit0e8c1cb0fd. * Revert "Removing unecessary implementation of IRepository interface as this is implemented by the base class." This reverts commit1c724280f5. * Revert "Fixing potential race condition in ListRepository. Now internally implemented as a concurrent dictionary." This reverts commit9ff8246a9d. * Revert "Updating packagerepository comment based on pr feedback" This reverts commit2c45956030. * Revert "Changing test structure. Need to add unit tests." This reverts commit1c267a55d5. * Revert "Fixing message format for exception" This reverts commitf60bdc3dd4. * Revert "Merging in Theme changes and moving win32Tests to Microsoft.Plugin.Program.UnitTests" This reverts commit030dfc2370.
This commit is contained in:
committed by
GitHub
parent
b13e719ab3
commit
12d9d59d85
@@ -12,7 +12,7 @@ namespace Wox.Infrastructure.Storage
|
||||
/// Storage object using binary data
|
||||
/// Normally, it has better performance, but not readable
|
||||
/// </summary>
|
||||
public class BinaryStorage<T> : IStorage<T>
|
||||
public class BinaryStorage<T>
|
||||
{
|
||||
// This storage helper returns whether or not to delete the binary storage items
|
||||
private static readonly int BINARY_STORAGE = 0;
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wox.Infrastructure.Storage
|
||||
{
|
||||
public interface IRepository<T>
|
||||
{
|
||||
void Add(T insertedItem);
|
||||
void Remove(T removedItem);
|
||||
bool Contains(T item);
|
||||
void Set(IList<T> list);
|
||||
bool Any();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wox.Infrastructure.Storage
|
||||
{
|
||||
public interface IStorage<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Saves the data
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
void Save(T data);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to load data, otherwise it will return the default provided
|
||||
/// </summary>
|
||||
/// <param name="defaultData"></param>
|
||||
/// <returns>The loaded data or default</returns>
|
||||
T TryLoad(T defaultData);
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
using NLog.Filters;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Logger;
|
||||
|
||||
namespace Wox.Infrastructure.Storage
|
||||
{
|
||||
/// <summary>
|
||||
/// The intent of this class is to provide a basic subset of 'list' like operations, without exposing callers to the internal representation
|
||||
/// of the data structure. Currently this is implemented as a list for it's simplicity.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class ListRepository<T> : IRepository<T>, IEnumerable<T>
|
||||
{
|
||||
public IList<T> Items { get { return _items.Values.ToList(); } }
|
||||
|
||||
private ConcurrentDictionary<int, T> _items = new ConcurrentDictionary<int, T>();
|
||||
|
||||
public ListRepository()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Set(IList<T> items)
|
||||
{
|
||||
//enforce that internal representation
|
||||
_items = new ConcurrentDictionary<int, T>(items.ToDictionary( i => i.GetHashCode()));
|
||||
}
|
||||
|
||||
public bool Any()
|
||||
{
|
||||
return _items.Any();
|
||||
}
|
||||
|
||||
public void Add(T insertedItem)
|
||||
{
|
||||
if (!_items.TryAdd(insertedItem.GetHashCode(), insertedItem))
|
||||
{
|
||||
Log.Error($"|ListRepository.Add| Item Already Exists <{insertedItem}>");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Remove(T removedItem)
|
||||
{
|
||||
|
||||
if (!_items.TryRemove(removedItem.GetHashCode(), out _))
|
||||
{
|
||||
Log.Error($"|ListRepository.Remove| Item Not Found <{removedItem}>");
|
||||
}
|
||||
}
|
||||
|
||||
public ParallelQuery<T> AsParallel()
|
||||
{
|
||||
return _items.Values.AsParallel();
|
||||
}
|
||||
|
||||
public bool Contains(T item)
|
||||
{
|
||||
return _items.ContainsKey(item.GetHashCode());
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
return _items.Values.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return _items.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user