mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:52:53 +08:00
Merge pull request #26451 from peppy/realm-cleanup-overheads-fix
Use native query to avoid huge overheads when cleaning up realm files
This commit is contained in:
commit
006946093b
@ -2,8 +2,8 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.IO.Stores;
|
using osu.Framework.IO.Stores;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
@ -98,15 +98,11 @@ namespace osu.Game.Database
|
|||||||
// can potentially be run asynchronously, although we will need to consider operation order for disk deletion vs realm removal.
|
// can potentially be run asynchronously, although we will need to consider operation order for disk deletion vs realm removal.
|
||||||
realm.Write(r =>
|
realm.Write(r =>
|
||||||
{
|
{
|
||||||
// TODO: consider using a realm native query to avoid iterating all files (https://github.com/realm/realm-dotnet/issues/2659#issuecomment-927823707)
|
foreach (var file in r.All<RealmFile>().Filter(@$"{nameof(RealmFile.Usages)}.@count = 0"))
|
||||||
var files = r.All<RealmFile>().ToList();
|
|
||||||
|
|
||||||
foreach (var file in files)
|
|
||||||
{
|
{
|
||||||
totalFiles++;
|
totalFiles++;
|
||||||
|
|
||||||
if (file.BacklinksCount > 0)
|
Debug.Assert(file.BacklinksCount == 0);
|
||||||
continue;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
using Realms;
|
using Realms;
|
||||||
|
|
||||||
@ -11,5 +12,8 @@ namespace osu.Game.Models
|
|||||||
{
|
{
|
||||||
[PrimaryKey]
|
[PrimaryKey]
|
||||||
public string Hash { get; set; } = string.Empty;
|
public string Hash { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Backlink(nameof(RealmNamedFileUsage.File))]
|
||||||
|
public IQueryable<RealmNamedFileUsage> Usages { get; } = null!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user