Skip to content

Commit 3275cf5

Browse files
cnruddlbwexler
andauthored
View Manager: cull archived/deleted view tokens from userPinned list when xhUserState is updated. (#474)
Co-authored-by: lbwexler <[email protected]>
1 parent 7e8cc60 commit 3275cf5

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
## 32.0-SNAPSHOT - unreleased
44

55
### ⚙️ Technical
6-
6+
* Cull obsolete ViewManager state for deleted views.
77
* Add support for recognizing `Island` browser
88

9+
910
## 31.0.3 - 2025-06-27
1011

1112
### ⚙️ Technical

grails-app/services/io/xh/hoist/jsonblob/JsonBlobService.groovy

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import grails.gorm.transactions.Transactional
1111
import grails.web.databinding.DataBinder
1212
import io.xh.hoist.BaseService
1313
import io.xh.hoist.exception.NotAuthorizedException
14+
import org.grails.datastore.mapping.query.api.BuildableCriteria
1415

1516
import static io.xh.hoist.json.JSONSerializer.serialize
1617
import static java.lang.System.currentTimeMillis
@@ -39,6 +40,23 @@ class JsonBlobService extends BaseService implements DataBinder {
3940
.findAll { passesAcl(it, username) }
4041
}
4142

43+
/** List all tokens for active blobs of a given type. */
44+
@ReadOnly
45+
List<String> listTokens(String type, String username = username) {
46+
BuildableCriteria c = JsonBlob.createCriteria()
47+
c {
48+
projections {
49+
property('token')
50+
}
51+
eq('type', type)
52+
eq('archivedDate', 0L)
53+
or {
54+
eq('acl', '*')
55+
eq('owner', username)
56+
}
57+
}
58+
}
59+
4260
@Transactional
4361
JsonBlob update(String token, Map data, String username = username) {
4462
def blob = get(token, username)

grails-app/services/io/xh/hoist/view/ViewService.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ class ViewService extends BaseService {
7575
if (update.containsKey('userPinned')) (newValue.userPinned as Map).putAll(update.userPinned as Map)
7676
if (update.containsKey('autoSave')) newValue.autoSave = update.autoSave
7777

78+
// Ensure that userPinned only contains tokens for views that exist
79+
if (newValue.userPinned) {
80+
Map userPinned = newValue.userPinned as Map
81+
userPinned.keySet().retainAll(jsonBlobService.listTokens(type, username))
82+
}
83+
7884
def blob = jsonBlobService.createOrUpdate(type, STATE_BLOB_NAME, [value: newValue], username)
7985
return getStateFromBlob(blob, viewInstance)
8086
}

0 commit comments

Comments
 (0)