Skip to content

Commit 85fba12

Browse files
committed
refactor: Simplify field initialization in Songs and SongData records
1 parent c0919a3 commit 85fba12

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/Prober/DivingFish/Models/Song.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ public record Song
3434

3535
internal record Songs
3636
{
37-
private static Songs? _shared;
38-
3937
private readonly DateTimeOffset _pullTime;
4038
private readonly ImmutableArray<Song> _songs;
4139
private readonly FrozenDictionary<string, Song> _songsById;
@@ -51,15 +49,15 @@ private static Songs SharedSongs
5149
{
5250
get
5351
{
54-
if (_shared is not null && DateTimeOffset.Now.AddHours(10).Date == _shared._pullTime.AddHours(10).Date)
52+
if (field is not null && DateTimeOffset.Now.AddHours(10).Date == field._pullTime.AddHours(10).Date)
5553
{
56-
return _shared;
54+
return field;
5755
}
5856

5957
DfResourceClient resource = new();
60-
_shared = (Songs)resource.GetSongsAsync().Result;
58+
field = (Songs)resource.GetSongsAsync().Result;
6159

62-
return _shared;
60+
return field;
6361
}
6462
}
6563

src/Prober/Lxns/Models/SongData.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ public record SongData
77
{
88
private readonly DateTimeOffset _pullTime = DateTimeOffset.Now;
99

10-
private FrozenDictionary<int, Song>? _songsById;
11-
12-
private FrozenDictionary<int, Version>? _versionsByGroup;
13-
1410
[JsonPropertyName("songs")]
1511
public required List<Song> Songs { get; set; }
1612

@@ -20,9 +16,9 @@ public record SongData
2016
[JsonPropertyName("versions")]
2117
public required List<Version> Versions { get; set; }
2218

23-
public FrozenDictionary<int, Song> SongsById => _songsById ??= Songs.ToFrozenDictionary(x => x.Id);
19+
public FrozenDictionary<int, Song> SongsById => field ??= Songs.ToFrozenDictionary(x => x.Id);
2420

25-
public FrozenDictionary<int, Version> VersionsByGroup => _versionsByGroup ??=
21+
public FrozenDictionary<int, Version> VersionsByGroup => field ??=
2622
Versions.GroupBy(x => x.VersionNumber / 100).ToFrozenDictionary(x => x.Key, x => x.First());
2723

2824
public static SongData Shared

0 commit comments

Comments
 (0)