Skip to content

Commit

Permalink
Delete all async function in SQLite. Add transaction to improve the p…
Browse files Browse the repository at this point in the history
…erformance
  • Loading branch information
zhuxb711 committed May 17, 2021
1 parent b755ef1 commit 7053edb
Show file tree
Hide file tree
Showing 18 changed files with 434 additions and 451 deletions.
94 changes: 61 additions & 33 deletions RX_Explorer/Class/CommonAccessCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
using Windows.Devices.Portable;
using Windows.Storage;
using Windows.Storage.Search;
using Windows.Storage.Streams;
using Windows.System;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media.Imaging;

namespace RX_Explorer.Class
{
Expand Down Expand Up @@ -58,15 +60,41 @@ public static async Task LoadQuickStartItemsAsync()
{
IsQuickStartLoaded = true;

foreach (KeyValuePair<QuickStartType, QuickStartItem> Item in await SQLite.Current.GetQuickStartItemAsync())
foreach ((string Name, string IconPath, string Protocal, string Type) in SQLite.Current.GetQuickStartItem())
{
if (Item.Key == QuickStartType.Application)
StorageFile ImageFile = null;

try
{
QuickStartList.Add(Item.Value);
ImageFile = IconPath.StartsWith("ms-appx") ? await StorageFile.GetFileFromApplicationUriAsync(new Uri(IconPath))
: await StorageFile.GetFileFromPathAsync(Path.Combine(ApplicationData.Current.LocalFolder.Path, IconPath));

BitmapImage Bitmap = new BitmapImage();

using (IRandomAccessStream Stream = await ImageFile.OpenAsync(FileAccessMode.Read))
{
await Bitmap.SetSourceAsync(Stream);
}

if (Enum.Parse<QuickStartType>(Type) == QuickStartType.Application)
{
QuickStartList.Add(new QuickStartItem(QuickStartType.Application, Bitmap, Protocal, IconPath, Name));
}
else
{
WebLinkList.Add(new QuickStartItem(QuickStartType.WebSite, Bitmap, Protocal, IconPath, Name));
}
}
else
catch (Exception ex)
{
WebLinkList.Add(Item.Value);
LogTracer.Log(ex, $"Could not load QuickStart item, Name: {Name}");

SQLite.Current.DeleteQuickStartItem(Name, Protocal, IconPath, Type);

if (ImageFile != null)
{
await ImageFile.DeleteAsync(StorageDeleteOption.PermanentDelete);
}
}
}

Expand Down Expand Up @@ -108,37 +136,37 @@ public static async Task LoadLibraryFoldersAsync()
{
if (!string.IsNullOrEmpty(DataPath.Downloads))
{
await SQLite.Current.SetLibraryPathAsync(DataPath.Downloads, LibraryType.Downloads);
SQLite.Current.SetLibraryPath(DataPath.Downloads, LibraryType.Downloads);
}

if (!string.IsNullOrEmpty(DataPath.Desktop))
{
await SQLite.Current.SetLibraryPathAsync(DataPath.Desktop, LibraryType.Desktop);
SQLite.Current.SetLibraryPath(DataPath.Desktop, LibraryType.Desktop);
}

if (!string.IsNullOrEmpty(DataPath.Videos))
{
await SQLite.Current.SetLibraryPathAsync(DataPath.Videos, LibraryType.Videos);
SQLite.Current.SetLibraryPath(DataPath.Videos, LibraryType.Videos);
}

if (!string.IsNullOrEmpty(DataPath.Pictures))
{
await SQLite.Current.SetLibraryPathAsync(DataPath.Pictures, LibraryType.Pictures);
SQLite.Current.SetLibraryPath(DataPath.Pictures, LibraryType.Pictures);
}

if (!string.IsNullOrEmpty(DataPath.Documents))
{
await SQLite.Current.SetLibraryPathAsync(DataPath.Documents, LibraryType.Document);
SQLite.Current.SetLibraryPath(DataPath.Documents, LibraryType.Document);
}

if (!string.IsNullOrEmpty(DataPath.Music))
{
await SQLite.Current.SetLibraryPathAsync(DataPath.Music, LibraryType.Music);
SQLite.Current.SetLibraryPath(DataPath.Music, LibraryType.Music);
}

if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("OneDrive")))
{
await SQLite.Current.SetLibraryPathAsync(Environment.GetEnvironmentVariable("OneDrive"), LibraryType.OneDrive);
SQLite.Current.SetLibraryPath(Environment.GetEnvironmentVariable("OneDrive"), LibraryType.OneDrive);
}
}
catch (Exception ex)
Expand All @@ -153,37 +181,37 @@ public static async Task LoadLibraryFoldersAsync()
string DesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
if (!string.IsNullOrEmpty(DesktopPath))
{
await SQLite.Current.SetLibraryPathAsync(DesktopPath, LibraryType.Desktop);
SQLite.Current.SetLibraryPath(DesktopPath, LibraryType.Desktop);
}

string VideoPath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);
if (!string.IsNullOrEmpty(VideoPath))
{
await SQLite.Current.SetLibraryPathAsync(VideoPath, LibraryType.Videos);
SQLite.Current.SetLibraryPath(VideoPath, LibraryType.Videos);
}

string PicturesPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
if (!string.IsNullOrEmpty(PicturesPath))
{
await SQLite.Current.SetLibraryPathAsync(PicturesPath, LibraryType.Pictures);
SQLite.Current.SetLibraryPath(PicturesPath, LibraryType.Pictures);
}

string DocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
if (!string.IsNullOrEmpty(DocumentsPath))
{
await SQLite.Current.SetLibraryPathAsync(DocumentsPath, LibraryType.Document);
SQLite.Current.SetLibraryPath(DocumentsPath, LibraryType.Document);
}

string MusicPath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
if (!string.IsNullOrEmpty(MusicPath))
{
await SQLite.Current.SetLibraryPathAsync(MusicPath, LibraryType.Music);
SQLite.Current.SetLibraryPath(MusicPath, LibraryType.Music);
}

string OneDrivePath = Environment.GetEnvironmentVariable("OneDrive");
if (!string.IsNullOrEmpty(OneDrivePath))
{
await SQLite.Current.SetLibraryPathAsync(OneDrivePath, LibraryType.OneDrive);
SQLite.Current.SetLibraryPath(OneDrivePath, LibraryType.OneDrive);
}
}
finally
Expand All @@ -204,37 +232,37 @@ public static async Task LoadLibraryFoldersAsync()
{
if (!string.IsNullOrEmpty(DataPath.Downloads))
{
await SQLite.Current.UpdateLibraryAsync(DataPath.Downloads, LibraryType.Downloads);
SQLite.Current.UpdateLibrary(DataPath.Downloads, LibraryType.Downloads);
}

if (!string.IsNullOrEmpty(DataPath.Desktop))
{
await SQLite.Current.UpdateLibraryAsync(DataPath.Desktop, LibraryType.Desktop);
SQLite.Current.UpdateLibrary(DataPath.Desktop, LibraryType.Desktop);
}

if (!string.IsNullOrEmpty(DataPath.Videos))
{
await SQLite.Current.UpdateLibraryAsync(DataPath.Videos, LibraryType.Videos);
SQLite.Current.UpdateLibrary(DataPath.Videos, LibraryType.Videos);
}

if (!string.IsNullOrEmpty(DataPath.Pictures))
{
await SQLite.Current.UpdateLibraryAsync(DataPath.Pictures, LibraryType.Pictures);
SQLite.Current.UpdateLibrary(DataPath.Pictures, LibraryType.Pictures);
}

if (!string.IsNullOrEmpty(DataPath.Documents))
{
await SQLite.Current.UpdateLibraryAsync(DataPath.Documents, LibraryType.Document);
SQLite.Current.UpdateLibrary(DataPath.Documents, LibraryType.Document);
}

if (!string.IsNullOrEmpty(DataPath.Music))
{
await SQLite.Current.UpdateLibraryAsync(DataPath.Music, LibraryType.Music);
SQLite.Current.UpdateLibrary(DataPath.Music, LibraryType.Music);
}

if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("OneDrive")))
{
await SQLite.Current.UpdateLibraryAsync(Environment.GetEnvironmentVariable("OneDrive"), LibraryType.OneDrive);
SQLite.Current.UpdateLibrary(Environment.GetEnvironmentVariable("OneDrive"), LibraryType.OneDrive);
}
}
catch (Exception ex)
Expand All @@ -249,44 +277,44 @@ public static async Task LoadLibraryFoldersAsync()
string DesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
if (!string.IsNullOrEmpty(DesktopPath))
{
await SQLite.Current.UpdateLibraryAsync(DesktopPath, LibraryType.Desktop);
SQLite.Current.UpdateLibrary(DesktopPath, LibraryType.Desktop);
}

string VideoPath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);
if (!string.IsNullOrEmpty(VideoPath))
{
await SQLite.Current.UpdateLibraryAsync(VideoPath, LibraryType.Videos);
SQLite.Current.UpdateLibrary(VideoPath, LibraryType.Videos);
}

string PicturesPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
if (!string.IsNullOrEmpty(PicturesPath))
{
await SQLite.Current.UpdateLibraryAsync(PicturesPath, LibraryType.Pictures);
SQLite.Current.UpdateLibrary(PicturesPath, LibraryType.Pictures);
}

string DocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
if (!string.IsNullOrEmpty(DocumentsPath))
{
await SQLite.Current.UpdateLibraryAsync(DocumentsPath, LibraryType.Document);
SQLite.Current.UpdateLibrary(DocumentsPath, LibraryType.Document);
}

string MusicPath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
if (!string.IsNullOrEmpty(MusicPath))
{
await SQLite.Current.UpdateLibraryAsync(MusicPath, LibraryType.Music);
SQLite.Current.UpdateLibrary(MusicPath, LibraryType.Music);
}

string OneDrivePath = Environment.GetEnvironmentVariable("OneDrive");
if (!string.IsNullOrEmpty(OneDrivePath))
{
await SQLite.Current.UpdateLibraryAsync(OneDrivePath, LibraryType.OneDrive);
SQLite.Current.UpdateLibrary(OneDrivePath, LibraryType.OneDrive);
}
}
}

Queue<string> ErrorList = new Queue<string>();

foreach ((string, LibraryType) Library in await SQLite.Current.GetLibraryPathAsync())
foreach ((string, LibraryType) Library in SQLite.Current.GetLibraryPath())
{
try
{
Expand All @@ -295,7 +323,7 @@ public static async Task LoadLibraryFoldersAsync()
catch (Exception)
{
ErrorList.Enqueue(Library.Item1);
await SQLite.Current.DeleteLibraryAsync(Library.Item1);
SQLite.Current.DeleteLibrary(Library.Item1);
}
}

Expand Down
6 changes: 3 additions & 3 deletions RX_Explorer/Class/FileSystemStorageItemBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,13 @@ public async Task LoadMorePropertiesAsync()
});
}

await LoadForegroundConfiguration();
LoadForegroundConfiguration();
}
}

private async Task LoadForegroundConfiguration()
private void LoadForegroundConfiguration()
{
string ColorString = await SQLite.Current.GetFileColorAsync(Path);
string ColorString = SQLite.Current.GetFileColor(Path);

if (!string.IsNullOrEmpty(ColorString))
{
Expand Down
6 changes: 3 additions & 3 deletions RX_Explorer/Class/GroupCollectionGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public static class GroupCollectionGenerator
{
public static event EventHandler<GroupStateChangedEventArgs> GroupStateChanged;

public static async Task SavePathGroupStateAsync(string Path, GroupTarget Target, GroupDirection Direction)
public static void SavePathGroupState(string Path, GroupTarget Target, GroupDirection Direction)
{
PathConfiguration CurrentConfiguration = await SQLite.Current.GetPathConfigurationAsync(Path);
PathConfiguration CurrentConfiguration = SQLite.Current.GetPathConfiguration(Path);

if (CurrentConfiguration.GroupTarget != Target || CurrentConfiguration.GroupDirection != Direction)
{
await SQLite.Current.SetPathConfigurationAsync(new PathConfiguration(Path, Target, Direction));
SQLite.Current.SetPathConfiguration(new PathConfiguration(Path, Target, Direction));
GroupStateChanged?.Invoke(null, new GroupStateChangedEventArgs(Path, Target, Direction));
}
}
Expand Down
12 changes: 6 additions & 6 deletions RX_Explorer/Class/QuickStartItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed class QuickStartItem : INotifyPropertyChanged
/// <summary>
/// 图标位置
/// </summary>
public string RelativePath { get; private set; }
public string IconPath { get; private set; }

/// <summary>
/// 快速启动项类型
Expand Down Expand Up @@ -52,7 +52,7 @@ public void Update(BitmapImage Image, string Protocol, string RelativePath, stri

if (RelativePath != null)
{
this.RelativePath = RelativePath;
this.IconPath = RelativePath;
}

OnPropertyChanged(nameof(DisplayName));
Expand All @@ -68,18 +68,18 @@ private void OnPropertyChanged(string name)
/// 初始化QuickStartItem对象
/// </summary>
/// <param name="Image">图标</param>
/// <param name="Uri">协议</param>
/// <param name="Protocol">协议</param>
/// <param name="Type">类型</param>
/// <param name="RelativePath">图标位置</param>
/// <param name="IconPath">图标位置</param>
/// <param name="DisplayName">显示名称</param>
public QuickStartItem(BitmapImage Image, string Protocol, QuickStartType Type, string RelativePath, string DisplayName = null)
public QuickStartItem(QuickStartType Type, BitmapImage Image, string Protocol, string IconPath, string DisplayName = null)
{
this.Image = Image;
this.Protocol = Protocol;
this.Type = Type;

this.DisplayName = DisplayName;
this.RelativePath = RelativePath;
this.IconPath = IconPath;
}

public QuickStartItem()
Expand Down

0 comments on commit 7053edb

Please sign in to comment.