Skip to content

Commit

Permalink
feat: use new query to check for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Nov 26, 2023
1 parent d2994f1 commit b890144
Show file tree
Hide file tree
Showing 7 changed files with 737 additions and 897 deletions.
6 changes: 6 additions & 0 deletions Model/Api/GraphQl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ internal static async Task<IReadOnlyList<IGetVersions_Package_Variants>> GetAllV
resp.EnsureNoErrors();
return resp.Data?.Variant ?? throw new MissingVariantException(variantId);
}

internal static async Task<IReadOnlyList<IGetNewestVersionInfoMulti_Variants>> GetNewestVersions(IReadOnlyList<Guid> variantIds) {
var resp = await Plugin.GraphQl.GetNewestVersionInfoMulti.ExecuteAsync(variantIds);
resp.EnsureNoErrors();
return resp.Data?.Variants ?? Array.Empty<IGetNewestVersionInfoMulti_Variants>();
}
}
32 changes: 20 additions & 12 deletions Ui/Tabs/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class Manager : IDisposable {
private Guid _selectedVariant = Guid.Empty;

private readonly Guard<HashSet<Guid>> _openingInstaller = new(new HashSet<Guid>());
private readonly Guard<Dictionary<Guid, IGetNewestVersionInfo_Variant>> _info = new(new Dictionary<Guid, IGetNewestVersionInfo_Variant>());
private readonly Guard<Dictionary<Guid, IVariantInfo>> _info = new(new Dictionary<Guid, IVariantInfo>());
private readonly Guard<Dictionary<Guid, IReadOnlyList<IGetVersions_Package_Variants>>> _versions = new(new Dictionary<Guid, IReadOnlyList<IGetVersions_Package_Variants>>());
private readonly Guard<HashSet<Guid>> _gettingInfo = new(new HashSet<Guid>());

Expand Down Expand Up @@ -88,18 +88,26 @@ internal void Draw() {
}

private async Task GetInfo() {
var tasks = this.Plugin.State.Installed
var ids = this.Plugin.State.Installed
.Values
.SelectMany(pkg => pkg.Variants)
.Select(meta => Task.Run(async () => {
try {
await this.GetInfo(meta.VariantId);
} catch (Exception ex) {
ErrorHelper.Handle(ex, $"Error getting info for {meta.ErrorName}");
}
}));
.Select(meta => meta.VariantId)
.ToArray();

await Task.WhenAll(tasks);
if (this._disposed) {
return;
}

var info = await GraphQl.GetNewestVersions(ids);
if (this._disposed) {
return;
}

// FIXME: what to do about missing variants?
using var guard = await this._info.WaitAsync();
foreach (var variant in info) {
guard.Data[variant.Id] = variant;
}
}

private async Task GetInfo(Guid variantId) {
Expand All @@ -116,7 +124,7 @@ private async Task GetInfo(Guid variantId) {
guard.Data[variantId] = info;
}

private void DrawPackageList(Dictionary<Guid, IGetNewestVersionInfo_Variant> allInfo) {
private void DrawPackageList(Dictionary<Guid, IVariantInfo> allInfo) {
if (ImGuiHelper.IconButton(FontAwesomeIcon.Redo, tooltip: "Refresh")) {
Task.Run(async () => await this.Plugin.State.UpdatePackages());
}
Expand Down Expand Up @@ -569,7 +577,7 @@ private async Task DownloadUpdatesInner(bool useConfig) {
return;
}

List<(HeliosphereMeta meta, IGetNewestVersionInfo_Variant? info)> withUpdates;
List<(HeliosphereMeta meta, IVariantInfo? info)> withUpdates;
using (var guard = await this._info.WaitAsync()) {
withUpdates = this.Plugin.State.Installed.Values
.SelectMany(pkg => pkg.Variants)
Expand Down
Loading

0 comments on commit b890144

Please sign in to comment.