예제 #1
0
        // questionable
        public async Task SyncBeatmapsFromHoLLy(IEnumerable <BeatmapEntry> entries)
        {
            var allBeatmaps = entries.Select(BeatmapConvertExtension.ParseFromHolly).ToList();
            var allIds      = allBeatmaps.Select(k => k.Id).ToList();

            var nonExistAnyMore = await Beatmaps.AsNoTracking().Where(k => !allIds.Contains(k.Id)).ToListAsync();

            if (nonExistAnyMore.Count > 0)
            {
                Beatmaps.RemoveRange(nonExistAnyMore);
            }

            var exists = await Beatmaps.AsNoTracking().Where(k => allIds.Contains(k.Id)).Select(k => k.Id).ToListAsync();

            if (exists.Count > 0)
            {
                var existsHashSet = exists.ToHashSet();
                Beatmaps.UpdateRange(allBeatmaps.Where(k => existsHashSet.Contains(k.Id)));
            }

            var news = allIds.Except(exists).ToHashSet();

            if (news.Count > 0)
            {
                var addRange = allBeatmaps.Where(k => news.Contains(k.Id)).ToHashSet();
                Beatmaps.AddRange(addRange);
            }

            await SaveChangesAsync();
        }
예제 #2
0
 public async Task RemoveSyncedAll()
 {
     Beatmaps.RemoveRange(Beatmaps.Where(k => !k.InOwnDb));
     await SaveChangesAsync();
 }