Skip to content

Commit 54018ae

Browse files
netomiautumnfound
andauthored
Fix: evict all relevant caches when deleting an extension (#1890)
* fix: Add missing cache evictions on extension deletion to be consistent * evict cached only after extension has been deleted from database in case there is a problem * sync cache evication also to deleteExtensionAndDependencies --------- Co-authored-by: Martin Lowe <martin.lowe@eclipse-foundation.org>
1 parent 453c9f9 commit 54018ae

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

server/src/main/java/org/eclipse/openvsx/admin/AdminService.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,20 @@ public void deleteExtensionAndDependencies(String namespaceName, String extensio
136136
}
137137

138138
public void deleteExtensionAndDependencies(Extension extension, UserData admin, int depth) throws ErrorResultException {
139-
if(depth > 5) {
139+
if (depth > 5) {
140140
throw new ErrorResultException("Failed to delete extension and its dependencies. Exceeded maximum recursion depth.", HttpStatus.INTERNAL_SERVER_ERROR);
141141
}
142142

143143
var bundledRefs = repositories.findBundledExtensionsReference(extension);
144-
for(var bundledRef : bundledRefs) {
144+
for (var bundledRef : bundledRefs) {
145145
deleteExtensionAndDependencies(bundledRef, admin, depth);
146146
}
147147

148148
var dependRefs = repositories.findDependenciesReference(extension);
149-
for(var dependRef : dependRefs) {
149+
for (var dependRef : dependRefs) {
150150
deleteExtensionAndDependencies(dependRef, admin, depth);
151151
}
152152

153-
cache.evictExtensionJsons(extension);
154153
for (var extVersion : repositories.findVersions(extension)) {
155154
removeExtensionVersion(extVersion);
156155
}
@@ -159,12 +158,18 @@ public void deleteExtensionAndDependencies(Extension extension, UserData admin,
159158
}
160159

161160
var deprecatedExtensions = repositories.findDeprecatedExtensions(extension);
162-
for(var deprecatedExtension : deprecatedExtensions) {
161+
for (var deprecatedExtension : deprecatedExtensions) {
163162
deprecatedExtension.setReplacement(null);
164163
cache.evictExtensionJsons(deprecatedExtension);
165164
}
166165

167166
entityManager.remove(extension);
167+
168+
// evict the cache entries only after the changes have been commited
169+
cache.evictExtensionJsons(extension);
170+
cache.evictNamespaceDetails(extension);
171+
cache.evictLatestExtensionVersion(extension);
172+
168173
search.removeSearchEntry(extension);
169174
logs.logAction(admin, ResultJson.success("Deleted " + NamingUtil.toExtensionId(extension)));
170175
}
@@ -189,12 +194,12 @@ public ResultJson deleteExtension(
189194
String extensionName,
190195
List<TargetPlatformVersionJson> targetVersions
191196
) {
192-
if(targetVersions == null || repositories.countVersions(namespaceName, extensionName) == targetVersions.size()) {
197+
if (targetVersions == null || repositories.countVersions(namespaceName, extensionName) == targetVersions.size()) {
193198
return deleteExtension(namespaceName, extensionName, adminUser);
194199
}
195200

196201
var results = new ArrayList<ResultJson>();
197-
for(var targetVersion : targetVersions) {
202+
for (var targetVersion : targetVersions) {
198203
results.add(deleteExtension(namespaceName, extensionName, targetVersion.targetPlatform(), targetVersion.version(), adminUser));
199204
}
200205

@@ -245,21 +250,27 @@ protected ResultJson deleteExtension(Extension extension, UserData admin) throws
245250
.collect(Collectors.joining(", ")));
246251
}
247252

248-
cache.evictExtensionJsons(extension);
249253
for (var extVersion : repositories.findVersions(extension)) {
250254
removeExtensionVersion(extVersion);
251255
}
256+
252257
for (var review : repositories.findAllReviews(extension)) {
253258
entityManager.remove(review);
254259
}
255260

256261
var deprecatedExtensions = repositories.findDeprecatedExtensions(extension);
257-
for(var deprecatedExtension : deprecatedExtensions) {
262+
for (var deprecatedExtension : deprecatedExtensions) {
258263
deprecatedExtension.setReplacement(null);
259264
cache.evictExtensionJsons(deprecatedExtension);
260265
}
261266

262267
entityManager.remove(extension);
268+
269+
// evict the cache entries only after the changes have been commited
270+
cache.evictExtensionJsons(extension);
271+
cache.evictNamespaceDetails(extension);
272+
cache.evictLatestExtensionVersion(extension);
273+
263274
search.removeSearchEntry(extension);
264275

265276
var result = ResultJson.success("Deleted " + NamingUtil.toExtensionId(extension));
@@ -431,7 +442,7 @@ public void changeNamespace(ChangeNamespaceJson json) {
431442
var duplicateExtensions = oldExtensions.keySet().stream()
432443
.filter(newExtensions::containsKey)
433444
.collect(Collectors.joining("','"));
434-
if(!duplicateExtensions.isEmpty()) {
445+
if (!duplicateExtensions.isEmpty()) {
435446
var message = "Can't merge namespaces, because new namespace '" +
436447
json.newNamespace() +
437448
"' and old namespace '" +
@@ -563,24 +574,24 @@ private UserData checkAdminUser(UserData user) {
563574
public AdminStatistics getAdminStatistics(int year, int month) throws ErrorResultException {
564575
validateYearAndMonth(year, month);
565576
var statistics = repositories.findAdminStatisticsByYearAndMonth(year, month);
566-
if(statistics == null) {
577+
if (statistics == null) {
567578
throw new NotFoundException();
568579
}
569580

570581
return statistics;
571582
}
572583

573584
private void validateYearAndMonth(int year, int month) {
574-
if(year < 0) {
585+
if (year < 0) {
575586
throw new ErrorResultException("Year can't be negative", HttpStatus.BAD_REQUEST);
576587
}
577-
if(month < 1 || month > 12) {
588+
if (month < 1 || month > 12) {
578589
throw new ErrorResultException("Month must be a value between 1 and 12", HttpStatus.BAD_REQUEST);
579590
}
580591

581592
var now = TimeUtil.getCurrentUTC();
582-
if(year > now.getYear() || (year == now.getYear() && month >= now.getMonthValue())) {
593+
if (year > now.getYear() || (year == now.getYear() && month >= now.getMonthValue())) {
583594
throw new ErrorResultException("Combination of year and month lies in the future", HttpStatus.BAD_REQUEST);
584595
}
585596
}
586-
}
597+
}

0 commit comments

Comments
 (0)