public ActionResult PutDatabase(
            [FromQuery] string key,
            [FromQuery] bool drop
            )
        {
            if (key != Environment.GetEnvironmentVariable("PRIVATE_API_KEY"))
            {
                return(Unauthorized("Key is wrong!"));
            }

            if (drop)
            {
                _searchEngine.DeleteAllBeatmaps();
                using (var db = _contextFactory.GetForWrite()) {
                    db.Context.Database.ExecuteSqlCommand
                        ("SET FOREIGN_KEY_CHECKS = 0;" +
                        "TRUNCATE TABLE `Beatmaps`;" +
                        "ALTER TABLE `Beatmaps` AUTO_INCREMENT = 1;" +
                        "TRUNCATE TABLE `BeatmapSet`;" +
                        "ALTER TABLE `BeatmapSet` AUTO_INCREMENT = 1;" +
                        "SET FOREIGN_KEY_CHECKS = 1;");
                }
            }

            lock (_lock) {
                var f = Request.Form.Files["dump.piss"];

                using (var stream = f.OpenReadStream())
                    using (var sr = new MStreamReader(stream))
                        using (var db = _contextFactory.GetForWrite())
                        {
                            var count = sr.ReadInt32();
                            Logger.LogPrint($"Count: {count}");

                            for (var i = 0; i < count; i++)
                            {
                                var set = sr.ReadData <BeatmapSet>();

                                Logger.LogPrint($"Importing BeatmapSet {set.SetId} {set.Artist} - {set.Title} ({set.Creator}) of Index {i}", LoggingTarget.Database, LogLevel.Important);

                                if (!drop)
                                {
                                    if (db.Context.BeatmapSet.Any(s => s.SetId == set.SetId))
                                    {
                                        db.Context.BeatmapSet.Update(set);
                                    }
                                    else
                                    {
                                        db.Context.BeatmapSet.Add(set);
                                    }
                                }
                                else
                                {
                                    db.Context.BeatmapSet.Add(set);
                                }
                            }
                            Logger.LogPrint("Finish importing maps!");
                        }

                return(Ok("Success!"));
            }
        }
        public ActionResult Recovery(
            [FromQuery] string key,
            [FromQuery] RecoveryAction action
            )
        {
            if (key != Environment.GetEnvironmentVariable("PRIVATE_API_KEY"))
            {
                return(Unauthorized("Key is wrong!"));
            }

            switch (action)
            {
            case RecoveryAction.RepairElastic:
                Logger.LogPrint("Repairing ElasticSearch");
                _crawler.Stop();
                _reibe.Stop();

                _searchEngine.DeleteAllBeatmaps();

                foreach (var beatmapSet in _contextFactory.Get().BeatmapSet)
                {
                    beatmapSet.ChildrenBeatmaps = _contextFactory.Get().Beatmaps.Where(b => b.ParentSetId == beatmapSet.SetId).ToList();
                    _searchEngine.IndexBeatmap(beatmapSet);
                }

                if (Environment.GetEnvironmentVariable("CRAWLER_DISABLED") != "true")
                {
                    _crawler.BeginCrawling();
                }

                if (Environment.GetEnvironmentVariable("CHEESEGULL_CRAWLER_DISABLED") != "true")
                {
                    _reibe.BeginCrawling();
                }
                break;

            case RecoveryAction.RecrawlEverything:
                Logger.LogPrint("Recrawl Everything!");

                _crawler.Stop();
                _reibe.Stop();

                _searchEngine.DeleteAllBeatmaps();
                using (var db = _contextFactory.GetForWrite()) {
                    db.Context.Database.ExecuteSqlCommand("SET FOREIGN_KEY_CHECKS = 0;" +
                                                          "TRUNCATE TABLE `Beatmaps`;" +
                                                          "ALTER TABLE `Beatmaps` AUTO_INCREMENT = 1;" +
                                                          "TRUNCATE TABLE `BeatmapSet`;" +
                                                          "ALTER TABLE `BeatmapSet` AUTO_INCREMENT = 1;" +
                                                          "SET FOREIGN_KEY_CHECKS = 1;");
                }
                using (var cacheDb = _cache.GetForWrite())
                {
                    cacheDb.Context.Database.ExecuteSqlCommand(
                        "DELETE FROM `CacheBeatmaps`;" +
                        "DELETE FROM `CacheBeatmapSet`;");
                }
                if (Environment.GetEnvironmentVariable("CRAWLER_DISABLED") != "true")
                {
                    _crawler.BeginCrawling();
                }
                if (Environment.GetEnvironmentVariable("CHEESEGULL_CRAWLER_DISABLED") != "true")
                {
                    _reibe.BeginCrawling();
                }
                break;

            case RecoveryAction.RecrawlUnknown:
                Logger.LogPrint("Recrawl All unknown maps!");

                _crawler.Stop();
                using (var db = _contextFactory.GetForWrite()) {
                    for (var i = 0; i < db.Context.BeatmapSet.Last().SetId; i++)
                    {
                        if (!db.Context.BeatmapSet.Any(set => set.SetId == i))
                        {
                            _crawler.Crawl(i, db.Context);
                        }
                    }
                }
                _crawler.BeginCrawling();
                break;

            default:
                return(BadRequest("Unknown Action type!"));
            }

            return(Ok("Success!"));
        }