Ejemplo n.º 1
0
        protected virtual OsuDbContext CreateContext()
        {
            var ctx = new OsuDbContext(host.Storage.GetDatabaseConnectionString(database_name));

            ctx.Database.AutoTransactionsEnabled = false;

            return(ctx);
        }
Ejemplo n.º 2
0
        private void migrateSettings(OsuDbContext db)
        {
            // migrate ruleset settings. can be removed 20220315.
            var existingSettings = db.DatabasedSetting.ToList();

            // previous entries in EF are removed post migration.
            if (!existingSettings.Any())
            {
                return;
            }

            log("Beginning settings migration to realm");

            realm.Run(r =>
            {
                using (var transaction = r.BeginWrite())
                {
                    // only migrate data if the realm database is empty.
                    if (!r.All <RealmRulesetSetting>().Any())
                    {
                        log($"Migrating {existingSettings.Count} settings");

                        foreach (var dkb in existingSettings)
                        {
                            if (dkb.RulesetID == null)
                            {
                                continue;
                            }

                            string?shortName = getRulesetShortNameFromLegacyID(dkb.RulesetID.Value);

                            if (string.IsNullOrEmpty(shortName))
                            {
                                continue;
                            }

                            r.Add(new RealmRulesetSetting
                            {
                                Key         = dkb.Key,
                                Value       = dkb.StringValue,
                                RulesetName = shortName,
                                Variant     = dkb.Variant ?? 0,
                            });
                        }
                    }

                    transaction.Commit();
                }
            });
        }
Ejemplo n.º 3
0
        private void migrateSkins(OsuDbContext db)
        {
            // can be removed 20220530.
            var existingSkins = db.SkinInfo
                                .Include(s => s.Files)
                                .ThenInclude(f => f.FileInfo)
                                .AsSplitQuery()
                                .ToList();

            // previous entries in EF are removed post migration.
            if (!existingSkins.Any())
            {
                return;
            }

            var userSkinChoice = config.GetBindable <string>(OsuSetting.Skin);

            int.TryParse(userSkinChoice.Value, out int userSkinInt);

            switch (userSkinInt)
            {
            case EFSkinInfo.DEFAULT_SKIN:
                userSkinChoice.Value = SkinInfo.DEFAULT_SKIN.ToString();
                break;

            case EFSkinInfo.CLASSIC_SKIN:
                userSkinChoice.Value = SkinInfo.CLASSIC_SKIN.ToString();
                break;
            }

            realm.Run(r =>
            {
                using (var transaction = r.BeginWrite())
                {
                    // only migrate data if the realm database is empty.
                    // note that this cannot be written as: `r.All<SkinInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
                    if (!r.All <SkinInfo>().Any(s => !s.Protected))
                    {
                        log($"Migrating {existingSkins.Count} skins");

                        foreach (var skin in existingSkins)
                        {
                            var realmSkin = new SkinInfo
                            {
                                Name              = skin.Name,
                                Creator           = skin.Creator,
                                Hash              = skin.Hash,
                                Protected         = false,
                                InstantiationInfo = skin.InstantiationInfo,
                            };

                            migrateFiles(skin, r, realmSkin);

                            r.Add(realmSkin);

                            if (skin.ID == userSkinInt)
                            {
                                userSkinChoice.Value = realmSkin.ID.ToString();
                            }
                        }
                    }

                    transaction.Commit();
                }
            });
        }
Ejemplo n.º 4
0
        private void migrateScores(OsuDbContext db)
        {
            // can be removed 20220730.
            var existingScores = db.ScoreInfo
                                 .Include(s => s.Ruleset)
                                 .Include(s => s.BeatmapInfo)
                                 .Include(s => s.Files)
                                 .ThenInclude(f => f.FileInfo)
                                 .AsSplitQuery();

            log("Beginning scores migration to realm");

            // previous entries in EF are removed post migration.
            if (!existingScores.Any())
            {
                log("No scores found to migrate");
                return;
            }

            int count = existingScores.Count();

            realm.Run(r =>
            {
                log($"Found {count} scores in EF");

                var transaction = r.BeginWrite();
                int written     = 0;
                int missing     = 0;

                try
                {
                    foreach (var score in existingScores)
                    {
                        if (++written % 1000 == 0)
                        {
                            transaction.Commit();
                            transaction = r.BeginWrite();
                            log($"Migrated {written}/{count} scores...");
                        }

                        var beatmap = r.All <BeatmapInfo>().FirstOrDefault(b => b.Hash == score.BeatmapInfo.Hash);
                        var ruleset = r.Find <RulesetInfo>(score.Ruleset.ShortName);

                        if (beatmap == null || ruleset == null)
                        {
                            log($"Skipping {++missing} scores with missing ruleset or beatmap");
                            continue;
                        }

                        var user = new RealmUser
                        {
                            OnlineID = score.User.OnlineID,
                            Username = score.User.Username
                        };

                        var realmScore = new ScoreInfo(beatmap, ruleset, user)
                        {
                            Hash           = score.Hash,
                            DeletePending  = score.DeletePending,
                            OnlineID       = score.OnlineID ?? -1,
                            ModsJson       = score.ModsJson,
                            StatisticsJson = score.StatisticsJson,
                            TotalScore     = score.TotalScore,
                            MaxCombo       = score.MaxCombo,
                            Accuracy       = score.Accuracy,
                            HasReplay      = ((IScoreInfo)score).HasReplay,
                            Date           = score.Date,
                            PP             = score.PP,
                            Rank           = score.Rank,
                            HitEvents      = score.HitEvents,
                            Passed         = score.Passed,
                            Combo          = score.Combo,
                            Position       = score.Position,
                            Statistics     = score.Statistics,
                            Mods           = score.Mods,
                            APIMods        = score.APIMods,
                        };

                        migrateFiles(score, r, realmScore);

                        r.Add(realmScore);
                    }
                }
                finally
                {
                    transaction.Commit();
                }

                log($"Successfully migrated {count} scores to realm");
            });
        }
Ejemplo n.º 5
0
        private void migrateBeatmaps(OsuDbContext ef)
        {
            // can be removed 20220730.
            var existingBeatmapSets = ef.EFBeatmapSetInfo
                                      .Include(s => s.Beatmaps).ThenInclude(b => b.RulesetInfo)
                                      .Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
                                      .Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty)
                                      .Include(s => s.Files).ThenInclude(f => f.FileInfo)
                                      .Include(s => s.Metadata)
                                      .AsSplitQuery();

            log("Beginning beatmaps migration to realm");

            // previous entries in EF are removed post migration.
            if (!existingBeatmapSets.Any())
            {
                log("No beatmaps found to migrate");
                return;
            }

            int count = existingBeatmapSets.Count();

            realm.Run(r =>
            {
                log($"Found {count} beatmaps in EF");

                var transaction = r.BeginWrite();
                int written     = 0;
                int missing     = 0;

                try
                {
                    foreach (var beatmapSet in existingBeatmapSets)
                    {
                        if (++written % 1000 == 0)
                        {
                            transaction.Commit();
                            transaction = r.BeginWrite();
                            log($"Migrated {written}/{count} beatmaps...");
                        }

                        var realmBeatmapSet = new BeatmapSetInfo
                        {
                            OnlineID      = beatmapSet.OnlineID ?? -1,
                            DateAdded     = beatmapSet.DateAdded,
                            Status        = beatmapSet.Status,
                            DeletePending = beatmapSet.DeletePending,
                            Hash          = beatmapSet.Hash,
                            Protected     = beatmapSet.Protected,
                        };

                        migrateFiles(beatmapSet, r, realmBeatmapSet);

                        foreach (var beatmap in beatmapSet.Beatmaps)
                        {
                            var ruleset  = r.Find <RulesetInfo>(beatmap.RulesetInfo.ShortName);
                            var metadata = getBestMetadata(beatmap.Metadata, beatmapSet.Metadata);

                            if (ruleset == null)
                            {
                                log($"Skipping {++missing} beatmaps with missing ruleset");
                                continue;
                            }

                            var realmBeatmap = new BeatmapInfo(ruleset, new BeatmapDifficulty(beatmap.BaseDifficulty), metadata)
                            {
                                DifficultyName           = beatmap.DifficultyName,
                                Status                   = beatmap.Status,
                                OnlineID                 = beatmap.OnlineID ?? -1,
                                Length                   = beatmap.Length,
                                BPM                      = beatmap.BPM,
                                Hash                     = beatmap.Hash,
                                StarRating               = beatmap.StarRating,
                                MD5Hash                  = beatmap.MD5Hash,
                                Hidden                   = beatmap.Hidden,
                                AudioLeadIn              = beatmap.AudioLeadIn,
                                StackLeniency            = beatmap.StackLeniency,
                                SpecialStyle             = beatmap.SpecialStyle,
                                LetterboxInBreaks        = beatmap.LetterboxInBreaks,
                                WidescreenStoryboard     = beatmap.WidescreenStoryboard,
                                EpilepsyWarning          = beatmap.EpilepsyWarning,
                                SamplesMatchPlaybackRate = beatmap.SamplesMatchPlaybackRate,
                                DistanceSpacing          = beatmap.DistanceSpacing,
                                BeatDivisor              = beatmap.BeatDivisor,
                                GridSize                 = beatmap.GridSize,
                                TimelineZoom             = beatmap.TimelineZoom,
                                Countdown                = beatmap.Countdown,
                                CountdownOffset          = beatmap.CountdownOffset,
                                Bookmarks                = beatmap.Bookmarks,
                                BeatmapSet               = realmBeatmapSet,
                            };

                            realmBeatmapSet.Beatmaps.Add(realmBeatmap);
                        }

                        r.Add(realmBeatmapSet);
                    }
                }
                finally
                {
                    transaction.Commit();
                }

                log($"Successfully migrated {count} beatmaps to realm");
            });
        }
Ejemplo n.º 6
0
 public DatabaseWriteUsage(OsuDbContext context, Action <DatabaseWriteUsage> onCompleted)
 {
     Context        = context;
     usageCompleted = onCompleted;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Called when removing an item completely from the database.
 /// </summary>
 /// <param name="items">The items to be purged.</param>
 /// <param name="context">The write context which can be used to perform subsequent deletions.</param>
 protected virtual void Purge(List <T> items, OsuDbContext context) => context.RemoveRange(items);
Ejemplo n.º 8
0
 public DatabaseWriteUsage(OsuDbContext context, Action <DatabaseWriteUsage> onCompleted)
 {
     Context        = context;
     transaction    = Context.BeginTransaction();
     usageCompleted = onCompleted;
 }