Skip to content

Commit eb38cf7

Browse files
committed
#251 (fix) transaction issues
1 parent 3ad3dab commit eb38cf7

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

grails-app/controllers/au/org/ala/alerts/NotificationController.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class NotificationController {
134134
notificationService.refreshProperties(queryResult, lastResult)
135135
boolean hasChanged = notificationService.hasChanged(queryResult)
136136
def records = notificationService.collectUpdatedRecords(queryResult)
137-
def results = ["hasChanged": hasChanged, "brief": queryResult.brief(), "records": records]
137+
def results = ["hasChanged": hasChanged, "brief": queryResult.details(), "records": records]
138138
render results as JSON
139139
}
140140

grails-app/services/au/org/ala/alerts/NotificationService.groovy

+17-13
Original file line numberDiff line numberDiff line change
@@ -862,25 +862,29 @@ class NotificationService {
862862
}
863863
}
864864

865+
865866
def unsubscribeMyAnnotation(User user) {
866867
String myAnnotationQueryPath = queryService.constructMyAnnotationQueryPath(user?.userId)
867868
Query retrievedQuery = Query.findByQueryPath(myAnnotationQueryPath)
868869

869-
if (retrievedQuery != null) {
870-
// delete the notification
871-
def notification = Notification.findByQueryAndUser(retrievedQuery, user)
872-
if (notification) {
873-
notification.delete(flush: true)
874-
}
875870

876-
// delete the query result
877-
QueryResult qr = QueryResult.findByQueryAndFrequency(retrievedQuery, user?.frequency)
878-
if (qr) {
879-
qr.delete(flush: true)
880-
}
871+
Query.withTransaction {
872+
if (retrievedQuery != null) {
873+
// delete the notification
874+
def notification = Notification.findByQueryAndUser(retrievedQuery, user)
875+
if (notification) {
876+
notification.delete(flush: true)
877+
}
878+
879+
// delete the query result
880+
QueryResult qr = QueryResult.findByQueryAndFrequency(retrievedQuery, user?.frequency)
881+
if (qr) {
882+
qr.delete(flush: true)
883+
}
881884

882-
// delete query
883-
retrievedQuery.delete(flush: true)
885+
// delete query
886+
retrievedQuery.delete(flush: true)
887+
}
884888
}
885889
}
886890

0 commit comments

Comments
 (0)