Skip to content

Commit 1668618

Browse files
committed
update task cache when bundle is deleted
1 parent 18c12bf commit 1668618

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

app/org/maproulette/framework/repository/TaskBundleRepository.scala

+28-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory
1010
import anorm.ToParameterValue
1111
import anorm._, postgresql._
1212
import javax.inject.{Inject, Singleton}
13-
import org.maproulette.exception.{InvalidException}
13+
import org.maproulette.exception.{InvalidException, NotFoundException}
1414
import org.maproulette.Config
1515
import org.maproulette.framework.psql.Query
1616
import org.maproulette.framework.psql.filter.BaseParameter
@@ -33,6 +33,7 @@ class TaskBundleRepository @Inject() (
3333
with Locking[Task] {
3434
protected val logger = LoggerFactory.getLogger(this.getClass)
3535
implicit val baseTable: String = Task.TABLE
36+
val cacheManager = this.taskRepository.cacheManager
3637

3738
/**
3839
* Inserts a new task bundle with the given tasks, assigning ownership of
@@ -144,8 +145,15 @@ class TaskBundleRepository @Inject() (
144145
def deleteTaskBundle(user: User, bundle: TaskBundle, primaryTaskId: Option[Long] = None): Unit = {
145146
this.withMRConnection { implicit c =>
146147
SQL(
147-
"UPDATE tasks SET bundle_id = NULL, is_bundle_primary = NULL WHERE bundle_id = {bundleId}"
148-
).on(Symbol("bundleId") -> bundle.bundleId).executeUpdate()
148+
"""UPDATE tasks
149+
SET bundle_id = NULL,
150+
is_bundle_primary = NULL
151+
WHERE bundle_id = {bundleId} OR id = {primaryTaskId}"""
152+
).on(
153+
Symbol("bundleId") -> bundle.bundleId,
154+
Symbol("primaryTaskId") -> primaryTaskId
155+
)
156+
.executeUpdate()
149157

150158
if (primaryTaskId != None) {
151159
// unlock tasks (everything but the primary task id)
@@ -164,6 +172,23 @@ class TaskBundleRepository @Inject() (
164172
}
165173
}
166174

175+
// Update cache for each task in the bundle
176+
bundle.tasks match {
177+
case Some(t) =>
178+
for (task <- t) {
179+
this.cacheManager.withOptionCaching { () =>
180+
Some(
181+
task.copy(
182+
bundleId = None,
183+
isBundlePrimary = None
184+
)
185+
)
186+
}
187+
}
188+
189+
case None => // no tasks in bundle
190+
}
191+
167192
// Delete from task_bundles which will also cascade delete from bundles
168193
SQL("DELETE FROM task_bundles WHERE bundle_id = {bundleId}")
169194
.on(Symbol("bundleId") -> bundle.bundleId)

0 commit comments

Comments
 (0)