mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 13:57:26 +08:00
Use native query to avoid huge overheads when cleaning up realm files
This commit is contained in:
parent
f376bb5ec7
commit
19d1fff536
@ -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
|
||||
{
|
||||
|
@ -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!;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user