mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 16:27:26 +08:00
Add transactional committing of scores/beatmaps
This helps slightly with performance, allows better monitoring via realm studio, but most importantly greatly reduces filesize. fully compacted: 109M transaction size 100: 115M transaction size 1000: 123M transaction size 10000: 164M single transaction: 183M With a transaction size of 100 there is a performance reduction, so 1000 seems to be the best middle-ground.
This commit is contained in:
parent
973836484c
commit
42736c9995
@ -94,10 +94,20 @@ namespace osu.Game.Database
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var transaction = realm.BeginWrite())
|
||||
var transaction = realm.BeginWrite();
|
||||
int written = 0;
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var beatmapSet in existingBeatmapSets)
|
||||
{
|
||||
if (++written % 1000 == 0)
|
||||
{
|
||||
transaction.Commit();
|
||||
transaction = realm.BeginWrite();
|
||||
Logger.Log($"Migrated {written}/{count} beatmaps...", LoggingTarget.Database);
|
||||
}
|
||||
|
||||
var realmBeatmapSet = new BeatmapSetInfo
|
||||
{
|
||||
OnlineID = beatmapSet.OnlineID ?? -1,
|
||||
@ -149,10 +159,13 @@ namespace osu.Game.Database
|
||||
|
||||
realm.Add(realmBeatmapSet);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
Logger.Log($"Successfully migrated {count} beatmaps to realm", LoggingTarget.Database);
|
||||
}
|
||||
finally
|
||||
{
|
||||
transaction.Commit();
|
||||
}
|
||||
|
||||
Logger.Log($"Successfully migrated {count} beatmaps to realm", LoggingTarget.Database);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -221,10 +234,20 @@ namespace osu.Game.Database
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var transaction = realm.BeginWrite())
|
||||
var transaction = realm.BeginWrite();
|
||||
int written = 0;
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var score in existingScores)
|
||||
{
|
||||
if (++written % 1000 == 0)
|
||||
{
|
||||
transaction.Commit();
|
||||
transaction = realm.BeginWrite();
|
||||
Logger.Log($"Migrated {written}/{count} scores...", LoggingTarget.Database);
|
||||
}
|
||||
|
||||
var realmScore = new ScoreInfo
|
||||
{
|
||||
Hash = score.Hash,
|
||||
@ -255,10 +278,13 @@ namespace osu.Game.Database
|
||||
|
||||
realm.Add(realmScore);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
Logger.Log($"Successfully migrated {count} scores to realm", LoggingTarget.Database);
|
||||
}
|
||||
finally
|
||||
{
|
||||
transaction.Commit();
|
||||
}
|
||||
|
||||
Logger.Log($"Successfully migrated {count} scores to realm", LoggingTarget.Database);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user