1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 04:42:58 +08:00

Merge pull request #3354 from peppy/fix-web-request-schedules

Fix some web requests being run after disposal of their owner
This commit is contained in:
Dean Herbert 2018-09-06 17:35:09 +09:00 committed by GitHub
commit b05526b47f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 30 deletions

View File

@ -62,7 +62,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
loading = true;
getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset);
getScoresRequest.Success += r => Scores = r.Scores;
getScoresRequest.Success += r => Schedule(() => Scores = r.Scores);
api.Queue(getScoresRequest);
}
}
@ -134,5 +134,10 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
this.api = api;
updateDisplay();
}
protected override void Dispose(bool isDisposing)
{
getScoresRequest?.Cancel();
}
}
}

View File

@ -14,8 +14,8 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps
public class PaginatedBeatmapContainer : PaginatedContainer
{
private const float panel_padding = 10f;
private readonly BeatmapSetType type;
private GetUserBeatmapsRequest request;
public PaginatedBeatmapContainer(BeatmapSetType type, Bindable<User> user, string header, string missing = "None... yet.")
: base(user, header, missing)
@ -31,9 +31,8 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps
{
base.ShowMore();
var req = new GetUserBeatmapsRequest(User.Value.Id, type, VisiblePages++ * ItemsPerPage);
req.Success += sets =>
request = new GetUserBeatmapsRequest(User.Value.Id, type, VisiblePages++ * ItemsPerPage);
request.Success += sets => Schedule(() =>
{
ShowMoreButton.FadeTo(sets.Count == ItemsPerPage ? 1 : 0);
ShowMoreLoading.Hide();
@ -52,9 +51,15 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps
var panel = new DirectGridPanel(s.ToBeatmapSet(Rulesets));
ItemsContainer.Add(panel);
}
};
});
Api.Queue(req);
Api.Queue(request);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
request?.Cancel();
}
}
}

View File

@ -12,6 +12,8 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
{
public class PaginatedMostPlayedBeatmapContainer : PaginatedContainer
{
private GetUserMostPlayedBeatmapsRequest request;
public PaginatedMostPlayedBeatmapContainer(Bindable<User> user)
:base(user, "Most Played Beatmaps", "No records. :(")
{
@ -24,9 +26,8 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
{
base.ShowMore();
var req = new GetUserMostPlayedBeatmapsRequest(User.Value.Id, VisiblePages++ * ItemsPerPage);
req.Success += beatmaps =>
request = new GetUserMostPlayedBeatmapsRequest(User.Value.Id, VisiblePages++ * ItemsPerPage);
request.Success += beatmaps => Schedule(() =>
{
ShowMoreButton.FadeTo(beatmaps.Count == ItemsPerPage ? 1 : 0);
ShowMoreLoading.Hide();
@ -43,9 +44,16 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
{
ItemsContainer.Add(new DrawableMostPlayedRow(beatmap.GetBeatmapInfo(Rulesets), beatmap.PlayCount));
}
};
});
Api.Queue(req);
Api.Queue(request);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
request?.Cancel();
}
}
}

View File

@ -28,6 +28,7 @@ namespace osu.Game.Overlays.Profile.Sections
protected readonly Bindable<User> User = new Bindable<User>();
protected APIAccess Api;
protected APIRequest RetrievalRequest;
protected RulesetStore Rulesets;
public PaginatedContainer(Bindable<User> user, string header, string missing)

View File

@ -16,6 +16,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
{
private readonly bool includeWeight;
private readonly ScoreType type;
private GetUserScoresRequest request;
public PaginatedScoreContainer(ScoreType type, Bindable<User> user, string header, string missing, bool includeWeight = false)
: base(user, header, missing)
@ -32,9 +33,8 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
{
base.ShowMore();
var req = new GetUserScoresRequest(User.Value.Id, type, VisiblePages++ * ItemsPerPage);
req.Success += scores =>
request = new GetUserScoresRequest(User.Value.Id, type, VisiblePages++ * ItemsPerPage);
request.Success += scores => Schedule(() =>
{
foreach (var s in scores)
s.ApplyRuleset(Rulesets.GetRuleset(s.OnlineRulesetID));
@ -66,9 +66,15 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
ItemsContainer.Add(drawableScore);
}
};
});
Api.Queue(req);
Api.Queue(request);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
request?.Cancel();
}
}
}

View File

@ -12,6 +12,8 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
{
public class PaginatedRecentActivityContainer : PaginatedContainer
{
private GetUserRecentActivitiesRequest request;
public PaginatedRecentActivityContainer(Bindable<User> user, string header, string missing)
: base(user, header, missing)
{
@ -22,9 +24,8 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
{
base.ShowMore();
var req = new GetUserRecentActivitiesRequest(User.Value.Id, VisiblePages++ * ItemsPerPage);
req.Success += activities =>
request = new GetUserRecentActivitiesRequest(User.Value.Id, VisiblePages++ * ItemsPerPage);
request.Success += activities => Schedule(() =>
{
ShowMoreButton.FadeTo(activities.Count == ItemsPerPage ? 1 : 0);
ShowMoreLoading.Hide();
@ -41,9 +42,15 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
{
ItemsContainer.Add(new DrawableRecentActivity(activity));
}
};
});
Api.Queue(req);
Api.Queue(request);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
request?.Cancel();
}
}
}

View File

@ -73,16 +73,15 @@ namespace osu.Game.Overlays
FadeEdgeEffectTo(0, WaveContainer.DISAPPEAR_DURATION, Easing.Out);
}
public void ShowUser(long userId)
{
if (userId == Header.User.Id)
return;
ShowUser(new User { Id = userId });
}
public void ShowUser(long userId) => ShowUser(new User { Id = userId });
public void ShowUser(User user, bool fetchOnline = true)
{
Show();
if (user.Id == Header?.User.Id)
return;
userReq?.Cancel();
Clear();
lastSection = null;
@ -97,6 +96,7 @@ namespace osu.Game.Overlays
new BeatmapsSection(),
new KudosuSection()
};
tabs = new ProfileTabControl
{
RelativeSizeAxes = Axes.X,
@ -161,7 +161,6 @@ namespace osu.Game.Overlays
userLoadComplete(user);
}
Show();
sectionsContainer.ScrollToTop();
}