Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import android.net.Uri
import android.util.Base64.decode
import android.util.Log
import androidx.core.net.toUri
import androidx.work.WorkInfo
import androidx.work.WorkManager
import com.example.metasearch.core.common.utils.toFile
Expand Down Expand Up @@ -52,18 +51,24 @@ class ImageAnalysisRepositoryImpl @Inject constructor(
}

override suspend fun runFullAnalysis() = withContext(Dispatchers.IO) {
Log.d(tag, "runFullAnalysis 함수 실행")
Log.d(tag, "1. runFullAnalysis 함수 실행")

val currentGalleryUris = galleryRepository.getAllGalleryImages()
Log.d(tag, "2. 갤러리 이미지 로드 완료: ${currentGalleryUris.size}개")
val currentGalleryUrisString = currentGalleryUris.map { it.toString() }

val alreadyAnalyzedPaths = analyzedImageDao.getAllAnalyzedPaths()
Log.d(tag, "3. 기존 분석 경로 로드 완료: ${alreadyAnalyzedPaths.size}개")
val dbName = databaseNameRepository.getPersistentDeviceDatabaseName()

Log.d(tag, "5. 삭제 로직 시작")
deleteMissingImages(alreadyAnalyzedPaths, currentGalleryUrisString, dbName)
Log.d(tag, "6. 삭제 로직 완료")

val addUris = currentGalleryUris.filter { uri ->
uri.toString() !in alreadyAnalyzedPaths
}
Log.d(tag, "7. 추가할 이미지 수: ${addUris.size}")
Comment on lines +56 to +73
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix the inconsistent log numbering sequence.

The debug logs skip from step "3" to step "5", missing step "4". This inconsistency could confuse developers tracing execution flow.

🔎 Proposed fix to correct the numbering
-        Log.d(tag, "5. 삭제 로직 시작")
+        Log.d(tag, "4. 삭제 로직 시작")
         deleteMissingImages(alreadyAnalyzedPaths, currentGalleryUrisString, dbName)
-        Log.d(tag, "6. 삭제 로직 완료")
+        Log.d(tag, "5. 삭제 로직 완료")
 
         val addUris = currentGalleryUris.filter { uri ->
             uri.toString() !in alreadyAnalyzedPaths
         }
-        Log.d(tag, "7. 추가할 이미지 수: ${addUris.size}")
+        Log.d(tag, "6. 추가할 이미지 수: ${addUris.size}")

And update line 87:

         } else {
-            Log.d(tag, "8. 추가할 이미지가 없어 종료함")
+            Log.d(tag, "7. 추가할 이미지가 없어 종료함")
         }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In
core/data/impl/src/main/java/com/example/metasearch/core/data/impl/repository/ImageAnalysisRepositoryImpl.kt
around lines 54 to 71, the debug log numbering skips "4" (it goes 1,2,3,5...).
Rename the log strings so the sequence is consecutive: change "5. 삭제 로직 시작" →
"4. 삭제 로직 시작", "6. 삭제 로직 완료" → "5. 삭제 로직 완료", and "7. 추가할 이미지 수" → "6. 추가할 이미지
수"; also scan nearby logs (e.g., around line 87) and adjust any further step
numbers to maintain a consistent incremental sequence.


if (addUris.isNotEmpty()) {
val allSuccessfulPaths = mutableListOf<String>()
Expand All @@ -78,27 +83,34 @@ class ImageAnalysisRepositoryImpl @Inject constructor(
if (allSuccessfulPaths.isNotEmpty()) {
processAnalysisFinish(allSuccessfulPaths, dbName)
}
} else {
Log.d(tag, "8. 추가할 이미지가 없어 종료함")
}

syncMismatchedNames(dbName)
}

private suspend fun deleteMissingImages(alreadyPaths: List<String>, currentPaths: List<String>, dbName: String) {
val deletePaths = alreadyPaths.filter { it !in currentPaths }
deletePaths.forEach { pathString ->
val uri = pathString.toUri()
val tempFile = uri.toFile(context)
val requestFile = tempFile.asRequestBody("image/*".toMediaTypeOrNull())
val fileNamePart = MultipartBody.Part.createFormData("deleteImage", tempFile.name, requestFile)

Log.d(tag, "삭제 대상 개수: ${deletePaths.size}개")
deletePaths.forEachIndexed { index, pathString ->
Log.d(tag, "이미지 삭제 중 (${index + 1}/${deletePaths.size}): $pathString")
val dbNameBody = dbName.toRequestBody("text/plain".toMediaTypeOrNull())

val fileName = pathString.substringAfterLast('/')
val dummyRequestBody = "".toRequestBody("image/*".toMediaTypeOrNull())

val fileNamePart = MultipartBody.Part.createFormData("deleteImage", fileName, dummyRequestBody)

val webSuccess = runCatching { webService.uploadWebDeleteImage(fileNamePart, dbName) }.isSuccess
val aiSuccess = runCatching { aiService.uploadDeleteImage(fileNamePart, dbNameBody) }.isSuccess

if (webSuccess && aiSuccess) analyzedImageDao.deletePath(pathString)

tempFile.delete()
if (webSuccess && aiSuccess) {
analyzedImageDao.deletePath(pathString)
Log.d(tag, "삭제 성공: $pathString")
} else {
Log.e(tag, "삭제 실패 (Web: $webSuccess, AI: $aiSuccess): $pathString")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.metasearch.core.network.request

import kotlinx.serialization.Serializable

@Serializable
data class DeleteImageRequest(
val dbName: String,
val deleteImage: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface AIService {
@Multipart
@POST("android/upload_delete")
suspend fun uploadDeleteImage(
@Part("deleteImage") filename: MultipartBody.Part,
@Part filename: MultipartBody.Part,
@Part("dbName") dbName: RequestBody,
): CommonResponse
Comment on lines 36 to 41
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for invocations of uploadDeleteImage
rg -nP --type=kotlin -C5 'uploadDeleteImage\s*\(' -g '!AIService.kt'

Repository: komodgn/meta-android

Length of output: 1896


🏁 Script executed:

# Also check for DeleteImageRequest usage in the codebase
rg -nP --type=kotlin 'DeleteImageRequest' -C2

Repository: komodgn/meta-android

Length of output: 1997


🏁 Script executed:

# Verify the WebService pattern mentioned in the review
rg -nP --type=kotlin -C5 'uploadWebDeleteImage'

Repository: komodgn/meta-android

Length of output: 2945


🏁 Script executed:

# Check if there are other implementations or related methods
rg -nP --type=kotlin 'uploadDelete|deleteImage' -C2

Repository: komodgn/meta-android

Length of output: 3080


🏁 Script executed:

# Check the exact WebService signature and any overloads
rg -nP --type=kotlin -A3 'fun uploadWebDeleteImage' core/network/src/main/java/com/example/metasearch/core/network/service/WebService.kt

Repository: komodgn/meta-android

Length of output: 167


🏁 Script executed:

# Check if there might be an older version of uploadWebDeleteImage still present
rg -nP --type=kotlin 'uploadWebDeleteImage|uploadDeleteImage' core/network/src/main/java/com/example/metasearch/core/network/service/

Repository: komodgn/meta-android

Length of output: 312


🏁 Script executed:

# Get more context from the repository to understand the invocation
cat -n core/data/impl/src/main/java/com/example/metasearch/core/data/impl/repository/ImageAnalysisRepositoryImpl.kt | sed -n '95,115p'

Repository: komodgn/meta-android

Length of output: 1265


Critical: Incomplete refactoring across the entire call chain—WebService invocation is broken.

The AIService incompleteness is real, but the larger issue is that the repository layer is invoking webService.uploadWebDeleteImage with the old signature. Line 105 in ImageAnalysisRepositoryImpl.kt calls:

webService.uploadWebDeleteImage(fileNamePart, dbName)

But WebService.uploadWebDeleteImage expects a single @Body DeleteImageRequest parameter (lines 70–72). This signature mismatch would cause a runtime/compilation failure.

To complete the refactoring, both services must be aligned and the repository must be updated:

  1. AIService: Remove @Multipart and update to accept @Body request: DeleteImageRequest (matching WebService)
  2. Repository: Create DeleteImageRequest instance and pass it correctly to both services

The inconsistency across AIService, WebService, and the repository layer breaks the entire delete flow.

🤖 Prompt for AI Agents
In
core/network/src/main/java/com/example/metasearch/core/network/service/AIService.kt
around lines 36 to 41, the uploadDeleteImage method remains multipart but the
WebService and repository were refactored to expect a single DeleteImageRequest
body; update AIService to remove @Multipart and change the signature to suspend
fun uploadDeleteImage(@Body request: DeleteImageRequest): CommonResponse so it
matches WebService, then update the repository call (ImageAnalysisRepositoryImpl
line ~105) to construct a DeleteImageRequest instance and pass that single
request object to both webService.uploadWebDeleteImage(...) and
aiService.uploadDeleteImage(...), ensuring parameter types and imports are
consistent.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.metasearch.core.network.service

import com.example.metasearch.core.network.request.ChangeNameRequest
import com.example.metasearch.core.network.request.DeleteEntityRequest
import com.example.metasearch.core.network.request.DeleteImageRequest
import com.example.metasearch.core.network.request.DetectedObjectsRequest
import com.example.metasearch.core.network.request.NLQueryRequest
import com.example.metasearch.core.network.request.PersonFrequencyRequest
Expand Down Expand Up @@ -65,10 +66,8 @@ public interface WebService {
@Query("dbName") dbName: String,
)

@Multipart
@POST("android/deleteimg")
@POST("deleteImage/")
suspend fun uploadWebDeleteImage(
@Part filename: MultipartBody.Part,
@Part("dbName") dbName: String,
@Body request: DeleteImageRequest,
)
}
Loading