From 80c4b463367e6e1c19b4da768174ab445607f061 Mon Sep 17 00:00:00 2001 From: usbharu Date: Sun, 17 Mar 2024 17:56:20 +0900 Subject: [PATCH] =?UTF-8?q?illust-data:=20=E3=82=BF=E3=82=B0=E4=BB=98?= =?UTF-8?q?=E3=81=91=E3=83=AA=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88=E3=81=8C?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unos/illust/crud/RequestTaggingService.kt | 31 +++++++++++++++++++ .../src/main/proto/illust/tag/tag.proto | 4 +++ 2 files changed, 35 insertions(+) create mode 100644 illust-crud/src/main/kotlin/dev/usbharu/unos/illust/crud/RequestTaggingService.kt diff --git a/illust-crud/src/main/kotlin/dev/usbharu/unos/illust/crud/RequestTaggingService.kt b/illust-crud/src/main/kotlin/dev/usbharu/unos/illust/crud/RequestTaggingService.kt new file mode 100644 index 0000000..01ee41b --- /dev/null +++ b/illust-crud/src/main/kotlin/dev/usbharu/unos/illust/crud/RequestTaggingService.kt @@ -0,0 +1,31 @@ +package dev.usbharu.unos.illust.crud + +import illust.tag.IllustTaggingServiceGrpcKt +import illust.tag.taggingRequest +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.withContext +import java.util.* + +interface RequestTaggingService { + suspend fun requestTagging(illustId: UUID): List +} + +class RequestTaggingServiceImpl(private val clients: List) : + RequestTaggingService { + override suspend fun requestTagging(illustId: UUID): List { + val taggingResults = withContext(Dispatchers.IO) { + clients.map { + async { + it.requestTagging(taggingRequest { + this.illustId = illustId.toString() + }) + } + }.awaitAll() + } + + return taggingResults.flatMap { it.tagsList } + } + +} \ No newline at end of file diff --git a/unos-proto/src/main/proto/illust/tag/tag.proto b/unos-proto/src/main/proto/illust/tag/tag.proto index 697354b..19a1cfc 100644 --- a/unos-proto/src/main/proto/illust/tag/tag.proto +++ b/unos-proto/src/main/proto/illust/tag/tag.proto @@ -9,5 +9,9 @@ message TaggingRequest{ message TaggingResult{ string illust_id = 1; + repeated string tags = 2; +} +service IllustTaggingService { + rpc requestTagging(TaggingRequest) returns (TaggingResult); } \ No newline at end of file