1
0
mirror of https://github.com/ppy/osu.git synced 2024-05-14 04:31:16 +08:00

Use native query to avoid huge overheads when cleaning up realm files

This commit is contained in:
Dean Herbert 2024-01-09 15:37:29 +09:00
parent f376bb5ec7
commit 19d1fff536
No known key found for this signature in database
2 changed files with 7 additions and 6 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using osu.Framework.Extensions;
@ -98,15 +99,11 @@ namespace osu.Game.Database
// can potentially be run asynchronously, although we will need to consider operation order for disk deletion vs realm removal.
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)
var files = r.All<RealmFile>().ToList();
foreach (var file in files)
foreach (var file in r.All<RealmFile>().Filter("Usages.@count = 0"))
{
totalFiles++;
if (file.BacklinksCount > 0)
continue;
Debug.Assert(file.BacklinksCount == 0);
try
{

View File

@ -1,6 +1,7 @@
// 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.
using System.Linq;
using osu.Game.IO;
using Realms;
@ -11,5 +12,8 @@ namespace osu.Game.Models
{
[PrimaryKey]
public string Hash { get; set; } = string.Empty;
[Backlink(nameof(RealmNamedFileUsage.File))]
public IQueryable<RealmNamedFileUsage> Usages { get; } = null!;
}
}