Merge pull request #20846 from peppy/reduce-solo-scores-legacy-serialisation

Avoid serialising some more properties of `SoloScoreInfo` unless present
This commit is contained in:
Dan Balasescu 2022-10-21 20:38:49 +09:00 committed by GitHub
commit bbdeec1630
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -114,6 +114,7 @@ public APIBeatmapSet? BeatmapSet
[JsonProperty("has_replay")]
public bool HasReplay { get; set; }
// These properties are calculated or not relevant to any external usage.
public bool ShouldSerializeID() => false;
public bool ShouldSerializeUser() => false;
public bool ShouldSerializeBeatmap() => false;
@ -122,6 +123,18 @@ public APIBeatmapSet? BeatmapSet
public bool ShouldSerializeOnlineID() => false;
public bool ShouldSerializeHasReplay() => false;
// These fields only need to be serialised if they hold values.
// Generally this is required because this model may be used by server-side components, but
// we don't want to bother sending these fields in score submission requests, for instance.
public bool ShouldSerializeEndedAt() => EndedAt != default;
public bool ShouldSerializeStartedAt() => StartedAt != default;
public bool ShouldSerializeLegacyScoreId() => LegacyScoreId != null;
public bool ShouldSerializeLegacyTotalScore() => LegacyTotalScore != null;
public bool ShouldSerializeMods() => Mods.Length > 0;
public bool ShouldSerializeUserID() => UserID > 0;
public bool ShouldSerializeBeatmapID() => BeatmapID > 0;
public bool ShouldSerializeBuildID() => BuildID != null;
#endregion
public override string ToString() => $"score_id: {ID} user_id: {UserID}";