Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions backend/RepoAPI.Tests/Features/Wiki/Costs/CostParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Microsoft.Extensions.Logging;
using NSubstitute;
using RepoAPI.Features.Wiki.Templates;
using SkyblockRepo;
using SkyblockRepo.Models;
Expand All @@ -26,12 +24,15 @@ public async Task CostParser_ItemsParseCorrectly()
{
var input = @"{{Item/PUMPKIN_DICER|lore}}\n\n&7Cost\n&6Gold medal\n&aJacob's Ticket &8x32";

var logger = Substitute.For<ILogger<SkyblockRepoUpdater>>();
var config = new SkyblockRepoConfiguration
{
LocalRepoPath = Path.Join(SkyblockRepoUtils.GetSolutionPath(), "..", "output")
UseNeuRepo = false,
SkyblockRepo = new RepoSettings
{
LocalPath = Path.Join(SkyblockRepoUtils.GetSolutionPath(), "..", "output")
}
};
var updater = new SkyblockRepoUpdater(config, logger);
var updater = new SkyblockRepoUpdater(config);
var repo = new SkyblockRepoClient(updater);

await repo.InitializeAsync(TestContext.Current.CancellationToken);
Expand Down
35 changes: 34 additions & 1 deletion backend/RepoAPI/Features/Items/Services/ItemsIngestionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using RepoAPI.Features.Output.Services;
using RepoAPI.Features.Wiki.Services;
using RepoAPI.Features.Wiki.Templates;
using SkyblockRepo;

namespace RepoAPI.Features.Items.Services;

Expand All @@ -19,6 +20,7 @@ public class ItemsIngestionService(
JsonWriteQueue writeQueue,
WikiItemsIngestionService wikiItemsIngestionService,
HybridCache hybridCache,
ISkyblockRepoClient skyblockRepoClient,
ILogger<ItemsIngestionService> logger)
{
public async Task IngestItemsDataAsync() {
Expand Down Expand Up @@ -46,10 +48,22 @@ public async Task IngestItemsDataAsync() {

// Use a new list for items to be added to avoid modifying the context while iterating
var itemsToAdd = new List<SkyblockItem>();

foreach (var apiItem in itemsFromApi) {
if (apiItem.Id is null) continue;

if (apiItem.Skin is null) {
var existingRepoItem = skyblockRepoClient.FindItem(apiItem.Id);
if (existingRepoItem?.Data?.Skin is not null)
{
apiItem.Skin = new ItemSkin()
{
Value = existingRepoItem.Data.Skin.Value,
Signature = existingRepoItem.Data.Skin.Signature
};
}
}

if (existingItems.TryGetValue(apiItem.Id, out var existingItem)) {
// Check if the item data has changed
if (existingItem.Data is null || ParserUtils.DeepJsonEquals(apiItem, existingItem.Data)) {
Expand Down Expand Up @@ -131,6 +145,25 @@ await context.SkyblockItems
await WriteChangesToFile(newItem);
}

foreach (var existingItem in existingItems.Values)
{
if (existingItem.Data?.Skin is not null) continue;
var repoItem = skyblockRepoClient.FindItem(existingItem.InternalId);
if (repoItem?.Data?.Skin is null) continue;

existingItem.Data ??= new ItemResponse();
existingItem.Data.Id ??= existingItem.InternalId;
existingItem.Data.Skin = new ItemSkin()
{
Value = repoItem.Data.Skin.Value,
Signature = repoItem.Data.Skin.Signature
};

context.SkyblockItems.Update(existingItem);
await WriteChangesToFile(existingItem);
updatedCount++;
}

if (itemsToAdd.Count != 0) {
context.SkyblockItems.AddRange(itemsToAdd);
}
Expand Down
Loading
Loading