Skip to content

Commit

Permalink
Only update link after processing when fields have been updated
Browse files Browse the repository at this point in the history
  • Loading branch information
raharrison committed Mar 29, 2022
1 parent 9409e2a commit aac4ad2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/main/kotlin/lynks/worker/LinkProcessingWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class LinkProcessorWorker(

private suspend fun processLinkPersist(link: Link, resourceSet: EnumSet<ResourceType>, process: Boolean) {
try {
val originalLink = link.copy(props = link.props)
resourceManager.deleteTempFiles(link.url)
link.props.clearTasks()
val resources = processorFactory.createProcessors(link.url).flatMap {
Expand All @@ -63,12 +64,16 @@ class LinkProcessorWorker(
}
}
}
link.thumbnailId = findThumbnail(resources)
link.thumbnailId = findThumbnail(resources) ?: link.thumbnailId
link.props.addAttribute(DEAD_LINK_PROP, false)
linkService.mergeProps(link.id, link.props)

linkService.update(link)
log.info("Link processing worker request complete, saved {} resources for entry={}", link.id, resources.size)
if (link != originalLink) {
linkService.update(link)
} else {
log.info("No changes found after link processing, not updating entity")
}
log.info("Link processing worker request complete, saved {} resources for entry={}", resources.size, link.id)
val message = "Link processed successfully, ${resources.size} resources created"
if (process) {
entryAuditService.acceptAuditEvent(
Expand Down
3 changes: 0 additions & 3 deletions src/test/kotlin/lynks/worker/LinkProcessorWorkerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class LinkProcessorWorkerTest {
coVerify(exactly = 1) { processorFactory.createProcessors(link.url) }
verify(exactly = 1) { processor.close() }
verify(exactly = 1) { linkService.mergeProps(eq("id1"), any()) }
verify(exactly = 1) { linkService.update(link) }
coVerify(exactly = 1) { notifyService.create(any()) }
coVerify(exactly = 1) { processor.scrapeResources(resourceSet) }
verify(exactly = 1) { resourceManager.migrateGeneratedResources(link.id, generatedResources) }
Expand Down Expand Up @@ -166,7 +165,6 @@ class LinkProcessorWorkerTest {
coVerify(exactly = 1) { processorFactory.createProcessors(link.url) }
verify(exactly = 1) { processor.close() }
verify(exactly = 1) { linkService.mergeProps(eq("id1"), any()) }
verify(exactly = 1) { linkService.update(link) }
coVerify(exactly = 0) { notifyService.create(any()) }

coVerify(exactly = 0) { processor.scrapeResources(any()) }
Expand All @@ -192,7 +190,6 @@ class LinkProcessorWorkerTest {
coVerify(exactly = 1) { processorFactory.createProcessors(link.url) }
verify(exactly = 1) { processor.close() }
verify(exactly = 1) { linkService.mergeProps(eq("id1"), any()) }
verify(exactly = 1) { linkService.update(link) }
coVerify(exactly = 1) { notifyService.create(any()) }

coVerify(exactly = 0) { processor.scrapeResources(any()) }
Expand Down

0 comments on commit aac4ad2

Please sign in to comment.