mirror of
https://github.com/ppy/osu
synced 2025-01-05 05:39:49 +00:00
Remove unnecessary branching around EF logic
This commit is contained in:
parent
93482414d6
commit
eef9949a0a
@ -511,29 +511,21 @@ namespace osu.Game.Database
|
||||
/// <param name="file">The existing file to be deleted.</param>
|
||||
public void DeleteFile(TModel model, TFileModel file)
|
||||
{
|
||||
if (model.ID > 0)
|
||||
using (var usage = ContextFactory.GetForWrite())
|
||||
{
|
||||
using (var usage = ContextFactory.GetForWrite())
|
||||
// Dereference the existing file info, since the file model will be removed.
|
||||
if (file.FileInfo != null)
|
||||
{
|
||||
// Dereference the existing file info, since the file model will be removed.
|
||||
if (file.FileInfo != null)
|
||||
Files.Dereference(file.FileInfo);
|
||||
|
||||
if (file.ID > 0)
|
||||
{
|
||||
Files.Dereference(file.FileInfo);
|
||||
|
||||
if (file.ID > 0)
|
||||
{
|
||||
// This shouldn't be required, but here for safety in case the provided TModel is not being change tracked
|
||||
// Definitely can be removed once we rework the database backend.
|
||||
usage.Context.Set<TFileModel>().Remove(file);
|
||||
}
|
||||
// This shouldn't be required, but here for safety in case the provided TModel is not being change tracked
|
||||
// Definitely can be removed once we rework the database backend.
|
||||
usage.Context.Set<TFileModel>().Remove(file);
|
||||
}
|
||||
|
||||
model.Files.Remove(file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Files.Dereference(file.FileInfo);
|
||||
|
||||
model.Files.Remove(file);
|
||||
}
|
||||
}
|
||||
@ -546,29 +538,17 @@ namespace osu.Game.Database
|
||||
/// <param name="filename">The filename for the new file.</param>
|
||||
public void AddFile(TModel model, Stream contents, string filename)
|
||||
{
|
||||
if (model.ID > 0)
|
||||
using (ContextFactory.GetForWrite())
|
||||
{
|
||||
using (ContextFactory.GetForWrite())
|
||||
{
|
||||
model.Files.Add(new TFileModel
|
||||
{
|
||||
Filename = filename,
|
||||
FileInfo = Files.Add(contents)
|
||||
});
|
||||
|
||||
Update(model);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// This function may be called during the import process.
|
||||
// Should not exist like this once we have switched to realm.
|
||||
model.Files.Add(new TFileModel
|
||||
{
|
||||
Filename = filename,
|
||||
FileInfo = Files.Add(contents)
|
||||
});
|
||||
}
|
||||
|
||||
if (model.ID > 0)
|
||||
Update(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user