@@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory
10
10
import anorm .ToParameterValue
11
11
import anorm ._ , postgresql ._
12
12
import javax .inject .{Inject , Singleton }
13
- import org .maproulette .exception .{InvalidException }
13
+ import org .maproulette .exception .{InvalidException , NotFoundException }
14
14
import org .maproulette .Config
15
15
import org .maproulette .framework .psql .Query
16
16
import org .maproulette .framework .psql .filter .BaseParameter
@@ -33,6 +33,7 @@ class TaskBundleRepository @Inject() (
33
33
with Locking [Task ] {
34
34
protected val logger = LoggerFactory .getLogger(this .getClass)
35
35
implicit val baseTable : String = Task .TABLE
36
+ val cacheManager = this .taskRepository.cacheManager
36
37
37
38
/**
38
39
* Inserts a new task bundle with the given tasks, assigning ownership of
@@ -144,8 +145,15 @@ class TaskBundleRepository @Inject() (
144
145
def deleteTaskBundle (user : User , bundle : TaskBundle , primaryTaskId : Option [Long ] = None ): Unit = {
145
146
this .withMRConnection { implicit c =>
146
147
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()
149
157
150
158
if (primaryTaskId != None ) {
151
159
// unlock tasks (everything but the primary task id)
@@ -164,6 +172,23 @@ class TaskBundleRepository @Inject() (
164
172
}
165
173
}
166
174
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
+
167
192
// Delete from task_bundles which will also cascade delete from bundles
168
193
SQL (" DELETE FROM task_bundles WHERE bundle_id = {bundleId}" )
169
194
.on(Symbol (" bundleId" ) -> bundle.bundleId)
0 commit comments