Updated scanner/upsert logic.

This commit is contained in:
2025-09-17 09:40:24 -04:00
parent 3b2a0e3491
commit db0c3349a2
14 changed files with 434 additions and 66 deletions

View File

@@ -2,24 +2,23 @@
public class DLSiteWork
{
public DLSiteWorkType WorkType { get; set; }
public DLSiteWorkType Type { get; set; }
public DLSiteWorkCategory Category { get; set; }
public string? ProductName { get; set; }
public string? ProductUrl { get; set; }
public string? ProductId { get; set; }
public required string ProductName { get; set; }
public required string ProductId { get; set; }
public DateOnly? AnnouncedDate { get; set; }
public DateOnly? ExpectedDate { get; set; }
public DateOnly? SalesDate { get; set; }
public int? Downloads { get; set; }
public int Downloads { get; set; }
public byte? StarRating { get; set; }
public int? Votes { get; set; }
public string? Maker { get; set; }
public string? MakerId { get; set; }
public required string Maker { get; set; }
public required string MakerId { get; set; }
public string? Description { get; set; }
public ICollection<string> Genres { get; set; } = [];
public bool HasTrial { get; set;}
public ICollection<string> Tags { get; set; } = [];
public ICollection<string> Creators { get; set; } = [];
public string? ImageUrl { get; set; }
public string? SmallImageUrl { get; set; }
public string? Type { get; set; }
}

View File

@@ -0,0 +1,21 @@
using JSMR.Application.Integrations.DLSite.Models;
namespace JSMR.Application.Scanning.Contracts;
public record VoiceWorkIngest(DLSiteWork Work, VoiceWorkDetails? Details)
{
public string MakerId { get; init; } = Work.MakerId;
public string MakerName { get; init; } = Work.Maker;
public string ProductId { get; init; } = Work.ProductId;
public string Title { get; init; } = Work.ProductName;
public string? Description { get; init; } = Work.Description;
public ICollection<string> Tags { get; init; } = Work.Tags;
public ICollection<string> Creators { get; init; } = Work.Creators;
public int WishlistCount { get; init; } = Details?.WishlistCount ?? 0;
public int Downloads { get; init; } = Math.Max(Work.Downloads, Details?.DownloadCount ?? 0);
public bool HasTrial { get; init; } = Work.HasTrial || (Details?.HasTrial ?? false);
public bool HasDLPlay { get; init; } = Details?.HasDLPlay ?? false;
public byte? StarRating { get; init; } = Work.StarRating;
public int? Votes { get; init; } = Work.Votes;
// TODO: Other properties
}

View File

@@ -0,0 +1,6 @@
namespace JSMR.Application.Scanning.Ports;
public interface IVoiceWorkSearchUpdater
{
Task UpdateAsync(int[] voiceWorkIds, CancellationToken cancellationToken);
}

View File

@@ -3,11 +3,17 @@ using JSMR.Application.Integrations.DLSite.Models;
using JSMR.Application.Integrations.Ports;
using JSMR.Application.Scanning.Contracts;
using JSMR.Application.Scanning.Ports;
using JSMR.Application.VoiceWorks.Ports;
using Microsoft.Extensions.DependencyInjection;
namespace JSMR.Application.Scanning;
public sealed class ScanVoiceWorksHandler(IServiceProvider serviceProvider, IDLSiteClient dlsiteClient, ISpamCircleCache spamCircleCache)
public sealed class ScanVoiceWorksHandler(
IServiceProvider serviceProvider,
IDLSiteClient dlsiteClient,
ISpamCircleCache spamCircleCache,
IVoiceWorkWriter writer,
IVoiceWorkSearchUpdater searchUpdater)
{
public async Task<ScanVoiceWorksResponse> HandleAsync(ScanVoiceWorksRequest request, CancellationToken cancellationToken)
{
@@ -32,21 +38,14 @@ public sealed class ScanVoiceWorksHandler(IServiceProvider serviceProvider, IDLS
string[] productIds = [.. works.Where(x => !string.IsNullOrWhiteSpace(x.ProductId)).Select(x => x.ProductId!)];
VoiceWorkDetailCollection voiceWorkDetails = await dlsiteClient.GetVoiceWorkDetailsAsync(productIds, cancellationToken);
// TODO
/*
var ingests = works.Select(VoiceWorkIngest.From).ToList();
var upsert = await _writer.UpsertAsync(ingests, ct);
// only update search text for affected rows
await _search.UpdateAsync(upsert.AffectedVoiceWorkIds, ct);
return new ScanVoiceWorksResponse
List<VoiceWorkIngest> ingests = [.. works.Select(work =>
{
Inserted = upsert.Inserted,
Updated = upsert.Updated
};
*/
voiceWorkDetails.TryGetValue(work.ProductId!, out VoiceWorkDetails? value);
return new VoiceWorkIngest(work, value);
})];
int[] voiceWorkIds = await writer.UpsertAsync(ingests, cancellationToken);
await searchUpdater.UpdateAsync(voiceWorkIds, cancellationToken);
return new();
}