Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new read-only interfaces for all remaining model types #14917

Merged
merged 20 commits into from
Oct 6, 2021

Conversation

peppy
Copy link
Member

@peppy peppy commented Oct 1, 2021

The provides a baseline for the structure of models going forward. They can/should be used in any cases we only want to allow read-only access to models.

@peppy
Copy link
Member Author

peppy commented Oct 1, 2021

Judging from the test failures it looks like Newtonsoft.Json is indeed serialising the base interface properties.

Not sure why this is required, doesn't make much sense.
bdach
bdach previously requested changes Oct 2, 2021
/// <summary>
/// The best-effort metadata representing this set. In the case metadata differs between contained beatmaps, one is arbitrarily chosen.
/// </summary>
IBeatmapMetadataInfo? Metadata { get; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this nullability a transitional measure? I don't imagine this will be allowed to be null when the whole series of changes concludes, will it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm still not sure. I brought this up for discussion last week but didn't get a solid answer, so for now have not changed the structure. We need to figure how/where we are going to attach metadata to cause the least issues. For not I avoided change.

osu.Game/Beatmaps/IBeatmapSetInfo.cs Outdated Show resolved Hide resolved
osu.Game/Beatmaps/IBeatmapInfo.cs Outdated Show resolved Hide resolved
osu.Game/Beatmaps/IBeatmapMetadataInfo.cs Outdated Show resolved Hide resolved
Comment on lines 40 to 41
// overwrite the pre-populated RulesetInfo with a potentially database attached copy.
// ruleset.RulesetInfo = this;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one gives me a bit of anxiety - looks like this was a hack to bypass some EF idiosyncrasy, but this being available and potentially callable by mistake feels like a footgun waiting to fire. I'd probably trim this for now unless it's really needed somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to leave it there for now, but I have added a TODO. I'll revisit this when I rebase my RulesetStore implementation. We may want this to be attached if it's a common pattern to access ruleset.RulesetInfo expecting to get a realm-based object, but I'd hope we avoid that pattern in the first place. Although that's what we have to IBeatmap right now, so a bit up in the air until I check usages.

osu.Game/Beatmaps/BeatmapSetFileInfo.cs Show resolved Hide resolved
osu.Game/Beatmaps/BeatmapSetInfo.cs Outdated Show resolved Hide resolved
@bdach
Copy link
Collaborator

bdach commented Oct 4, 2021

going to dismiss my review since the blockers look to be resolved. however i am not getting why StoryboardFile died on a stack overflow and SearchableTerms didn't, and so i'd probably feel better with all usages of that default interface pattern gone altogether.

@bdach bdach dismissed their stale review October 4, 2021 18:55

see above

/// <summary>
/// All beatmaps contained in this set.
/// </summary>
IEnumerable<IBeatmapInfo> Beatmaps { get; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be named BeatmapInfos to be in line with the new naming?

Copy link
Member Author

Choose a reason for hiding this comment

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

Very unsure about that.. just because BeatmapInfos sounds weird.

osu.Game/Rulesets/IRulesetInfo.cs Outdated Show resolved Hide resolved

// overwrite the pre-populated RulesetInfo with a potentially database attached copy.
// TODO: figure if we still want/need this after switching to realm.
// ruleset.RulesetInfo = this;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be uncommented for the time being, since we haven't switched to realm yet?

Copy link
Member Author

Choose a reason for hiding this comment

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

This method is unused for now (the one in RulesetInfo is still there). Can remove the interface level method for the time being if that feels better.

/// <summary>
/// A user-presentable display title representing this metadata.
/// </summary>
string DisplayTitle
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about all these default implementations. On the one hand it makes sense from the POV of being able to override these members' implementations, but on the other hand they seem like abuse and maybe extension methods would fit better.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will change to extension methods, I think we want to avoid interface defaults everywhere at this point.


// temporary helper methods until we figure which metadata should be where.
private static IBeatmapMetadataInfo getClosestMetadata(IBeatmapInfo beatmapInfo) =>
beatmapInfo.Metadata ?? beatmapInfo.BeatmapSet?.Metadata ?? new BeatmapMetadata();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unsure whether this should be a

Suggested change
beatmapInfo.Metadata ?? beatmapInfo.BeatmapSet?.Metadata ?? new BeatmapMetadata();
beatmapInfo.Metadata ?? beatmapInfo.BeatmapSet.Metadata ?? new BeatmapMetadata();

as the inspection suggests, or if BeatmapSet should be marked nullable on the interface. There are several other places that nullcheck the property so probably safest to go with the latter for now?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think nullable is the safest option for now, yep. Will require revisiting once things are locked in place.

Copy link
Member Author

Choose a reason for hiding this comment

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

For what it's worth, I made this change due to an actual null ref, so it can happen.

@smoogipoo smoogipoo merged commit 13bea78 into ppy:master Oct 6, 2021
@peppy peppy deleted the new-interfaces branch October 6, 2021 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants