Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The using System.Collections.Generic; statement was removed, but this file uses Dictionary<TKey, TValue> and LinkedList<T>, which are defined in that namespace. This will likely cause a compilation error unless System.Collections.Generic is included as a global using for the project. If it's not a global using, this statement should be restored.

using System.Collections.Immutable;
using System.Linq;
using System.Runtime.CompilerServices;
using KGySoft.CoreLibraries;
using StabilityMatrix.Core.Helper.Cache;

namespace StabilityMatrix.Avalonia.Controls.VendorLabs.Cache;

Expand All @@ -23,7 +16,7 @@ public class InMemoryStorage<T>
private readonly LinkedList<InMemoryStorageItem<T>> _lruList = [];

private int _maxItemCount;
private object _settingMaxItemCountLocker = new();
private readonly Lock _settingMaxItemCountLocker = new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The type of _settingMaxItemCountLocker has been changed from object to Lock. However, the Lock type is not defined or imported in this file. The using KGySoft.CoreLibraries; statement, which likely contains this type, was removed in this pull request. This will cause a compilation error. Please revert this to use object or ensure the Lock type is correctly referenced.

    private readonly object _settingMaxItemCountLocker = new();


/// <summary>
/// Gets or sets the maximum count of Items that can be stored in this InMemoryStorage instance.
Expand Down
15 changes: 6 additions & 9 deletions StabilityMatrix.Avalonia/Helpers/EnumHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using StabilityMatrix.Core.Extensions;
using StabilityMatrix.Core.Extensions;
using StabilityMatrix.Core.Models;
using StabilityMatrix.Core.Models.Api;

Expand All @@ -10,22 +7,22 @@ namespace StabilityMatrix.Avalonia.Helpers;
public static class EnumHelpers
{
public static IEnumerable<CivitPeriod> AllCivitPeriods { get; } =
Enum.GetValues(typeof(CivitPeriod)).Cast<CivitPeriod>();
Enum.GetValues<CivitPeriod>().Cast<CivitPeriod>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The call to .Cast<CivitPeriod>() is redundant. Enum.GetValues<CivitPeriod>() already returns a CivitPeriod[], which implements IEnumerable<CivitPeriod>. You can remove the cast for cleaner code.

        Enum.GetValues<CivitPeriod>()


public static IEnumerable<CivitSortMode> AllSortModes { get; } =
Enum.GetValues(typeof(CivitSortMode)).Cast<CivitSortMode>();
Enum.GetValues<CivitSortMode>().Cast<CivitSortMode>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The call to .Cast<CivitSortMode>() is redundant. Enum.GetValues<CivitSortMode>() already returns a CivitSortMode[], which implements IEnumerable<CivitSortMode>. You can remove the cast for cleaner code.

        Enum.GetValues<CivitSortMode>()


public static IEnumerable<CivitModelType> AllCivitModelTypes { get; } =
Enum.GetValues(typeof(CivitModelType))
Enum.GetValues<CivitModelType>()
.Cast<CivitModelType>()
.Where(t => t == CivitModelType.All || t.ConvertTo<SharedFolderType>() > 0)
.OrderBy(t => t.ToString());

public static IEnumerable<CivitModelType> MetadataEditorCivitModelTypes { get; } =
Enum.GetValues(typeof(CivitModelType)).Cast<CivitModelType>().OrderBy(t => t.ToString());
Enum.GetValues<CivitModelType>().Cast<CivitModelType>().OrderBy(t => t.ToString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The call to .Cast<CivitModelType>() is redundant. Enum.GetValues<CivitModelType>() already returns a CivitModelType[], which implements IEnumerable<CivitModelType>. You can remove the cast for cleaner code.

        Enum.GetValues<CivitModelType>().OrderBy(t => t.ToString())


public static IEnumerable<CivitBaseModelType> AllCivitBaseModelTypes { get; } =
Enum.GetValues(typeof(CivitBaseModelType)).Cast<CivitBaseModelType>();
Enum.GetValues<CivitBaseModelType>().Cast<CivitBaseModelType>();
Comment on lines 9 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Enum.GetValues<T>() method already returns an array of the enum type (T[]), which is implicitly convertible to IEnumerable<T>. Therefore, the subsequent calls to .Cast<T>() are redundant and can be removed for cleaner code. This applies to AllCivitPeriods, AllSortModes, AllCivitModelTypes, MetadataEditorCivitModelTypes, and AllCivitBaseModelTypes.

    public static IEnumerable<CivitPeriod> AllCivitPeriods { get; } =
        Enum.GetValues<CivitPeriod>();

    public static IEnumerable<CivitSortMode> AllSortModes { get; } =
        Enum.GetValues<CivitSortMode>();

    public static IEnumerable<CivitModelType> AllCivitModelTypes { get; } =
        Enum.GetValues<CivitModelType>()
            .Where(t => t == CivitModelType.All || t.ConvertTo<SharedFolderType>() > 0)
            .OrderBy(t => t.ToString());

    public static IEnumerable<CivitModelType> MetadataEditorCivitModelTypes { get; } =
        Enum.GetValues<CivitModelType>().OrderBy(t => t.ToString());

    public static IEnumerable<CivitBaseModelType> AllCivitBaseModelTypes { get; } =
        Enum.GetValues<CivitBaseModelType>();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The call to .Cast<CivitBaseModelType>() is redundant. Enum.GetValues<CivitBaseModelType>() already returns a CivitBaseModelType[], which implements IEnumerable<CivitBaseModelType>. You can remove the cast for cleaner code.

        Enum.GetValues<CivitBaseModelType>()


public static IEnumerable<CivitBaseModelType> MetadataEditorCivitBaseModelTypes { get; } =
AllCivitBaseModelTypes.Where(x => x != CivitBaseModelType.All);
Expand Down
3 changes: 1 addition & 2 deletions StabilityMatrix.Avalonia/Helpers/IOCommands.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Input;
using StabilityMatrix.Core.Processes;

namespace StabilityMatrix.Avalonia.Helpers;
Expand Down
9 changes: 2 additions & 7 deletions StabilityMatrix.Avalonia/Helpers/ImageProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SkiaSharp;
using SkiaSharp;
using StabilityMatrix.Core.Extensions;

namespace StabilityMatrix.Avalonia.Helpers;
Expand Down Expand Up @@ -45,9 +42,7 @@ public static SKImage CreateImageGrid(IReadOnlyList<SKImage> images, int spacing
// Draw images
using var canvas = new SKCanvas(output);

foreach (
var (row, column) in Enumerable.Range(0, rows).Product(Enumerable.Range(0, columns))
)
foreach (var (row, column) in Enumerable.Range(0, rows).Product(Enumerable.Range(0, columns)))
{
// Stop if we have drawn all images
var index = row * columns + column;
Expand Down
24 changes: 9 additions & 15 deletions StabilityMatrix.Avalonia/Helpers/ImageSearcher.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using FuzzySharp;
using FuzzySharp;
using FuzzySharp.PreProcess;
using StabilityMatrix.Core.Models.Database;

Expand Down Expand Up @@ -27,8 +26,7 @@ public Func<LocalImageFile, bool> GetPredicate(string? searchQuery)

if (
SearchOptions.HasFlag(ImageSearchOptions.FileName)
&& Fuzz.WeightedRatio(searchQuery, file.FileName, PreprocessMode.Full)
> MinimumFuzzScore
&& Fuzz.WeightedRatio(searchQuery, file.FileName, PreprocessMode.Full) > MinimumFuzzScore
)
{
return true;
Expand All @@ -53,22 +51,18 @@ public Func<LocalImageFile, bool> GetPredicate(string? searchQuery)
) ?? false
)
|| SearchOptions.HasFlag(ImageSearchOptions.Seed)
&& parameters.Seed
.ToString()
&& parameters
.Seed.ToString()
.StartsWith(searchQuery, StringComparison.OrdinalIgnoreCase)
|| SearchOptions.HasFlag(ImageSearchOptions.Sampler)
&& (
parameters.Sampler?.StartsWith(
searchQuery,
StringComparison.OrdinalIgnoreCase
) ?? false
parameters.Sampler?.StartsWith(searchQuery, StringComparison.OrdinalIgnoreCase)
?? false
)
|| SearchOptions.HasFlag(ImageSearchOptions.ModelName)
&& (
parameters.ModelName?.StartsWith(
searchQuery,
StringComparison.OrdinalIgnoreCase
) ?? false
parameters.ModelName?.StartsWith(searchQuery, StringComparison.OrdinalIgnoreCase)
?? false
)
)
{
Expand All @@ -90,6 +84,6 @@ public enum ImageSearchOptions
Seed = 1 << 3,
Sampler = 1 << 4,
ModelName = 1 << 5,
All = int.MaxValue
All = int.MaxValue,
}
}
6 changes: 1 addition & 5 deletions StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text;
using System.Text.Json;
using Force.Crc32;
using StabilityMatrix.Avalonia.Models;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using AutoComplete.Builders;
using AutoComplete.Clients.IndexSearchers;
Expand Down Expand Up @@ -358,12 +354,12 @@ private IEnumerable<ICompletionData> GetCompletionNetworkTypes(string searchTerm
{
(PromptExtraNetworkType.Lora, "lora"),
(PromptExtraNetworkType.LyCORIS, "lyco"),
(PromptExtraNetworkType.Embedding, "embedding")
(PromptExtraNetworkType.Embedding, "embedding"),
};

return availableTypes
.Where(
type => type.Item1.GetStringValue().StartsWith(searchTerm, StringComparison.OrdinalIgnoreCase)
.Where(type =>
type.Item1.GetStringValue().StartsWith(searchTerm, StringComparison.OrdinalIgnoreCase)
)
.Select(type => new ModelTypeCompletionData(type.Item2, type.Item1));
}
Expand All @@ -381,7 +377,7 @@ private IEnumerable<ICompletionData> GetCompletionTags(string searchTerm, int it
{
Term = searchTerm,
MaxItemCount = itemsCount,
SuggestWhenFoundStartsWith = suggest
SuggestWhenFoundStartsWith = suggest,
};

var result = searcher.Search(searchOptions);
Expand Down
4 changes: 2 additions & 2 deletions StabilityMatrix.Avalonia/Services/RunningPackageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ IPyRunner pyRunner
)
{
// Get lock
using var @lock = await packageLocks.LockAsync(installedPackage.Id, cancellationToken);
using var _ = await packageLocks.LockAsync(installedPackage.Id, cancellationToken);

// Ignore if already running after lock
if (RunningPackages.ContainsKey(installedPackage.Id))
Expand Down Expand Up @@ -266,7 +266,7 @@ await basePackage.RunPackage(
public async Task StopPackage(Guid id, CancellationToken cancellationToken = default)
{
// Get lock
using var @lock = await packageLocks.LockAsync(id, cancellationToken);
using var _ = await packageLocks.LockAsync(id, cancellationToken);

// Ignore if not running after lock
if (!RunningPackages.TryGetValue(id, out var vm))
Expand Down
6 changes: 1 addition & 5 deletions StabilityMatrix.Avalonia/ViewModels/ConsoleViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.ComponentModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
using System.Web;
using Avalonia.Threading;
Expand Down
2 changes: 1 addition & 1 deletion StabilityMatrix.Core/Helper/HardwareInfo/HardwareHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static partial class HardwareHelper
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

private static IReadOnlyList<GpuInfo>? cachedGpuInfos;
private static readonly object cachedGpuInfosLock = new();
private static readonly Lock cachedGpuInfosLock = new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The type of cachedGpuInfosLock has been changed from object to Lock. However, the Lock type does not appear to be defined or imported within the project's scope, which will cause a compilation error. Please use a valid and available type for locking, such as object.

    private static readonly object cachedGpuInfosLock = new();


private static readonly Lazy<IHardwareInfo> HardwareInfoLazy = new(() => new Hardware.Info.HardwareInfo()
);
Expand Down
Loading
Loading