diff --git a/DragaliaAPI/DragaliaAPI.Database/Repositories/UnitRepository.cs b/DragaliaAPI/DragaliaAPI.Database/Repositories/UnitRepository.cs index 86ed2db68..e62914482 100644 --- a/DragaliaAPI/DragaliaAPI.Database/Repositories/UnitRepository.cs +++ b/DragaliaAPI/DragaliaAPI.Database/Repositories/UnitRepository.cs @@ -103,12 +103,19 @@ ILogger logger public async Task> AddCharas(IEnumerable idList) { List enumeratedIdList = idList.ToList(); + IEnumerable storyIdList = GetFirstCharaStories(enumeratedIdList); // Generate result. The first occurrence of a character in the list should be new (if not in the DB) // but subsequent results should then not be labelled as new. - List ownedCharas = await Charas.Select(x => x.CharaId).ToListAsync(); + List ownedCharas = await Charas + .Select(x => x.CharaId) + .Where(x => enumeratedIdList.Contains(x)) + .ToListAsync(); + List ownedCharaStories = await this - .apiContext.PlayerStoryState.Where(x => x.StoryType == StoryTypes.Chara) + .apiContext.PlayerStoryState.Where(x => + x.StoryType == StoryTypes.Chara && storyIdList.Contains(x.StoryId) + ) .Select(x => x.StoryId) .ToListAsync(); @@ -149,6 +156,17 @@ ILogger logger } return newMapping.Select(x => (x.Id, x.IsNew)); + + static IEnumerable GetFirstCharaStories(IEnumerable charaIdList) + { + foreach (Charas c in charaIdList) + { + if (MasterAsset.CharaStories.TryGetValue((int)c, out StoryData? storyData)) + { + yield return storyData.storyIds[0]; + } + } + } } public async Task AddCharas(Charas id) @@ -160,9 +178,13 @@ public async Task AddCharas(Charas id) { List enumeratedIdList = idList.ToList(); - List ownedDragons = await Dragons.Select(x => x.DragonId).ToListAsync(); + List ownedDragons = await Dragons + .Select(x => x.DragonId) + .Where(x => enumeratedIdList.Contains(x)) + .ToListAsync(); List ownedReliabilities = await DragonReliabilities .Select(x => x.DragonId) + .Where(x => enumeratedIdList.Contains(x)) .ToListAsync(); List newMapping = MarkNewDragons(