1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-15 15:27:20 +08:00

Allow "refreshing" instances via DatabaseBackedStore

This commit is contained in:
Dean Herbert 2017-10-25 18:28:28 +09:00
parent 5cd04392b4
commit 8452e315f4
3 changed files with 16 additions and 0 deletions

View File

@ -18,6 +18,11 @@ namespace osu.Game.Database
private readonly ThreadLocal<OsuDbContext> queryContext;
/// <summary>
/// Refresh an instance potentially from a diffrent thread with a local context-tracked instance.
/// </summary>
protected void Refresh<T>(ref T obj) where T : class, IHasPrimaryKey => obj = GetContext().Find<T>(obj.ID);
/// <summary>
/// Retrieve a shared context for performing lookups (or write operations on the update thread, for now).
/// </summary>

View File

@ -0,0 +1,10 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Database
{
public interface IHasPrimaryKey
{
int ID { get; set; }
}
}

View File

@ -282,6 +282,7 @@
<Compile Include="Beatmaps\Drawables\BeatmapSetCover.cs" />
<Compile Include="Beatmaps\Drawables\BeatmapSetHeader.cs" />
<Compile Include="Database\DatabaseContextFactory.cs" />
<Compile Include="Database\IHasPrimaryKey.cs" />
<Compile Include="Migrations\20171019041408_InitialCreate.cs" />
<Compile Include="Migrations\20171019041408_InitialCreate.Designer.cs">
<DependentUpon>20171019041408_InitialCreate.cs</DependentUpon>