Skip to content

Commit 7470f7b

Browse files
committed
perf(GithubRelease): Use the new .NET 6.0 compiler generated JsonType for releases parsing from github.
Should improve the speed at which the releases are parsed from the JSON to the POCO.
1 parent 4d1fb42 commit 7470f7b

12 files changed

+322
-89
lines changed

SoundSwitch/Framework/Updater/AutoUpdater.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Windows.Forms;
1919
using Serilog;
2020
using SoundSwitch.Framework.Updater.Installer;
21+
using SoundSwitch.Framework.Updater.Releases;
2122
using SoundSwitch.Localization;
2223

2324
namespace SoundSwitch.Framework.Updater
@@ -42,10 +43,10 @@ public AutoUpdater(string installerParameters, string filePath)
4243
InstallerFilePath = Path.Combine(filePath, "SoundSwitch_Update.exe");
4344
}
4445

45-
public void Update(Release release, bool closeApp)
46+
public void Update(AppRelease appRelease, bool closeApp)
4647
{
4748

48-
var file = new WebFile(new Uri(release.Asset.browser_download_url), InstallerFilePath);
49+
var file = new WebFile(new Uri(appRelease.Asset.BrowserDownloadUrl), InstallerFilePath);
4950
file.Downloaded += (sender, args) =>
5051
{
5152
Log.Information("Update downloaded: {File}", file);

SoundSwitch/Framework/Updater/GitHubRelease.cs

-38
This file was deleted.

SoundSwitch/Framework/Updater/Release.cs renamed to SoundSwitch/Framework/Updater/Releases/AppRelease.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@
1414

1515
using System;
1616
using System.Collections.Generic;
17+
using SoundSwitch.Framework.Updater.Releases.Models;
1718

18-
namespace SoundSwitch.Framework.Updater
19+
namespace SoundSwitch.Framework.Updater.Releases
1920
{
20-
public class Release
21+
public class AppRelease
2122
{
22-
public Release(Version releaseVersion, GitHubRelease.Asset asset, string name)
23+
public AppRelease(Version releaseVersion, Asset asset, string name)
2324
{
2425
ReleaseVersion = releaseVersion;
2526
Asset = asset;
2627
Name = name;
2728
}
2829

2930
public Version ReleaseVersion { get; private set; }
30-
public GitHubRelease.Asset Asset { get; private set; }
31+
public Asset Asset { get; }
3132
public List<string> Changelog { get; } = new List<string>();
3233
public string Name { get; private set; }
3334

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace SoundSwitch.Framework.Updater.Releases;
4+
5+
[JsonSerializable(typeof(Models.Release[]))]
6+
internal partial class GithubReleasesJsonContext : JsonSerializerContext
7+
{
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text.Json.Serialization;
4+
5+
namespace SoundSwitch.Framework.Updater.Releases.Models;
6+
7+
public class Author
8+
{
9+
[JsonPropertyName("login")]
10+
public string Login { get; set; }
11+
12+
[JsonPropertyName("id")]
13+
public int Id { get; set; }
14+
15+
[JsonPropertyName("node_id")]
16+
public string NodeId { get; set; }
17+
18+
[JsonPropertyName("avatar_url")]
19+
public string AvatarUrl { get; set; }
20+
21+
[JsonPropertyName("gravatar_id")]
22+
public string GravatarId { get; set; }
23+
24+
[JsonPropertyName("url")]
25+
public string Url { get; set; }
26+
27+
[JsonPropertyName("html_url")]
28+
public string HtmlUrl { get; set; }
29+
30+
[JsonPropertyName("followers_url")]
31+
public string FollowersUrl { get; set; }
32+
33+
[JsonPropertyName("following_url")]
34+
public string FollowingUrl { get; set; }
35+
36+
[JsonPropertyName("gists_url")]
37+
public string GistsUrl { get; set; }
38+
39+
[JsonPropertyName("starred_url")]
40+
public string StarredUrl { get; set; }
41+
42+
[JsonPropertyName("subscriptions_url")]
43+
public string SubscriptionsUrl { get; set; }
44+
45+
[JsonPropertyName("organizations_url")]
46+
public string OrganizationsUrl { get; set; }
47+
48+
[JsonPropertyName("repos_url")]
49+
public string ReposUrl { get; set; }
50+
51+
[JsonPropertyName("events_url")]
52+
public string EventsUrl { get; set; }
53+
54+
[JsonPropertyName("received_events_url")]
55+
public string ReceivedEventsUrl { get; set; }
56+
57+
[JsonPropertyName("type")]
58+
public string Type { get; set; }
59+
60+
[JsonPropertyName("site_admin")]
61+
public bool SiteAdmin { get; set; }
62+
}
63+
64+
public class Uploader
65+
{
66+
[JsonPropertyName("login")]
67+
public string Login { get; set; }
68+
69+
[JsonPropertyName("id")]
70+
public int Id { get; set; }
71+
72+
[JsonPropertyName("node_id")]
73+
public string NodeId { get; set; }
74+
75+
[JsonPropertyName("avatar_url")]
76+
public string AvatarUrl { get; set; }
77+
78+
[JsonPropertyName("gravatar_id")]
79+
public string GravatarId { get; set; }
80+
81+
[JsonPropertyName("url")]
82+
public string Url { get; set; }
83+
84+
[JsonPropertyName("html_url")]
85+
public string HtmlUrl { get; set; }
86+
87+
[JsonPropertyName("followers_url")]
88+
public string FollowersUrl { get; set; }
89+
90+
[JsonPropertyName("following_url")]
91+
public string FollowingUrl { get; set; }
92+
93+
[JsonPropertyName("gists_url")]
94+
public string GistsUrl { get; set; }
95+
96+
[JsonPropertyName("starred_url")]
97+
public string StarredUrl { get; set; }
98+
99+
[JsonPropertyName("subscriptions_url")]
100+
public string SubscriptionsUrl { get; set; }
101+
102+
[JsonPropertyName("organizations_url")]
103+
public string OrganizationsUrl { get; set; }
104+
105+
[JsonPropertyName("repos_url")]
106+
public string ReposUrl { get; set; }
107+
108+
[JsonPropertyName("events_url")]
109+
public string EventsUrl { get; set; }
110+
111+
[JsonPropertyName("received_events_url")]
112+
public string ReceivedEventsUrl { get; set; }
113+
114+
[JsonPropertyName("type")]
115+
public string Type { get; set; }
116+
117+
[JsonPropertyName("site_admin")]
118+
public bool SiteAdmin { get; set; }
119+
}
120+
121+
public class Asset
122+
{
123+
[JsonPropertyName("url")]
124+
public string Url { get; set; }
125+
126+
[JsonPropertyName("id")]
127+
public int Id { get; set; }
128+
129+
[JsonPropertyName("node_id")]
130+
public string NodeId { get; set; }
131+
132+
[JsonPropertyName("name")]
133+
public string Name { get; set; }
134+
135+
[JsonPropertyName("label")]
136+
public object Label { get; set; }
137+
138+
[JsonPropertyName("uploader")]
139+
public Uploader Uploader { get; set; }
140+
141+
[JsonPropertyName("content_type")]
142+
public string ContentType { get; set; }
143+
144+
[JsonPropertyName("state")]
145+
public string State { get; set; }
146+
147+
[JsonPropertyName("size")]
148+
public int Size { get; set; }
149+
150+
[JsonPropertyName("download_count")]
151+
public int DownloadCount { get; set; }
152+
153+
[JsonPropertyName("created_at")]
154+
public DateTime CreatedAt { get; set; }
155+
156+
[JsonPropertyName("updated_at")]
157+
public DateTime UpdatedAt { get; set; }
158+
159+
[JsonPropertyName("browser_download_url")]
160+
public string BrowserDownloadUrl { get; set; }
161+
}
162+
163+
public class Reactions
164+
{
165+
[JsonPropertyName("url")]
166+
public string Url { get; set; }
167+
168+
[JsonPropertyName("total_count")]
169+
public int TotalCount { get; set; }
170+
171+
[JsonPropertyName("+1")]
172+
public int Positive { get; set; }
173+
174+
[JsonPropertyName("-1")]
175+
public int Negative { get; set; }
176+
177+
[JsonPropertyName("laugh")]
178+
public int Laugh { get; set; }
179+
180+
[JsonPropertyName("hooray")]
181+
public int Hooray { get; set; }
182+
183+
[JsonPropertyName("confused")]
184+
public int Confused { get; set; }
185+
186+
[JsonPropertyName("heart")]
187+
public int Heart { get; set; }
188+
189+
[JsonPropertyName("rocket")]
190+
public int Rocket { get; set; }
191+
192+
[JsonPropertyName("eyes")]
193+
public int Eyes { get; set; }
194+
}
195+
196+
public class Release
197+
{
198+
[JsonPropertyName("url")]
199+
public string Url { get; set; }
200+
201+
[JsonPropertyName("assets_url")]
202+
public string AssetsUrl { get; set; }
203+
204+
[JsonPropertyName("upload_url")]
205+
public string UploadUrl { get; set; }
206+
207+
[JsonPropertyName("html_url")]
208+
public string HtmlUrl { get; set; }
209+
210+
[JsonPropertyName("id")]
211+
public int Id { get; set; }
212+
213+
[JsonPropertyName("author")]
214+
public Author Author { get; set; }
215+
216+
[JsonPropertyName("node_id")]
217+
public string NodeId { get; set; }
218+
219+
[JsonPropertyName("tag_name")]
220+
public string TagName { get; set; }
221+
222+
[JsonPropertyName("target_commitish")]
223+
public string TargetCommitish { get; set; }
224+
225+
[JsonPropertyName("name")]
226+
public string Name { get; set; }
227+
228+
[JsonPropertyName("draft")]
229+
public bool Draft { get; set; }
230+
231+
[JsonPropertyName("prerelease")]
232+
public bool Prerelease { get; set; }
233+
234+
[JsonPropertyName("created_at")]
235+
public DateTime CreatedAt { get; set; }
236+
237+
[JsonPropertyName("published_at")]
238+
public DateTime PublishedAt { get; set; }
239+
240+
[JsonPropertyName("assets")]
241+
public List<Asset> Assets { get; } = new();
242+
243+
[JsonPropertyName("tarball_url")]
244+
public string TarballUrl { get; set; }
245+
246+
[JsonPropertyName("zipball_url")]
247+
public string ZipballUrl { get; set; }
248+
249+
[JsonPropertyName("body")]
250+
public string Body { get; set; }
251+
252+
[JsonPropertyName("reactions")]
253+
public Reactions Reactions { get; set; }
254+
255+
public override string ToString()
256+
{
257+
return $"{nameof(Name)}: {Name}, {nameof(TagName)}: {TagName}, {nameof(Prerelease)}: {Prerelease}, {nameof(PublishedAt)}: {PublishedAt}";
258+
}
259+
}

0 commit comments

Comments
 (0)