From 539a7675d780abebdb6ad8b90f2d8d2923374bb3 Mon Sep 17 00:00:00 2001 From: Abhijeet Date: Mon, 12 Aug 2024 14:12:48 +0530 Subject: [PATCH] chore: Add tenant cache eviction for the existing policies to policyMap migration --- .../db/ce/Migration059PolicySetToPolicyMap.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration059PolicySetToPolicyMap.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration059PolicySetToPolicyMap.java index 98d67dc90c6e..76c3f6d00ac5 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration059PolicySetToPolicyMap.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration059PolicySetToPolicyMap.java @@ -1,5 +1,7 @@ package com.appsmith.server.migrations.db.ce; +import com.appsmith.server.domains.Tenant; +import com.appsmith.server.repositories.CacheableRepositoryHelper; import com.mongodb.client.result.UpdateResult; import io.mongock.api.annotations.ChangeUnit; import io.mongock.api.annotations.Execution; @@ -19,6 +21,7 @@ import java.util.Set; import static com.appsmith.external.helpers.StringUtils.dotted; +import static com.appsmith.server.constants.ce.FieldNameCE.DEFAULT; import static com.appsmith.server.helpers.ce.bridge.BridgeQuery.where; import static com.appsmith.server.migrations.constants.DeprecatedFieldName.POLICIES; import static com.appsmith.server.migrations.constants.FieldName.POLICY_MAP; @@ -35,6 +38,8 @@ public class Migration059PolicySetToPolicyMap { private final ReactiveMongoTemplate mongoTemplate; + private final CacheableRepositoryHelper cacheableRepositoryHelper; + private static final Set CE_COLLECTION_NAMES = Set.of( "actionCollection", "application", @@ -80,6 +85,13 @@ public void execute() { return Mono.error(error); }) .block(); + + // Evict the default tenant from the cache to ensure that the updated tenant object is fetched from the database + Query tenantQuery = new Query(); + tenantQuery.addCriteria(where(Tenant.Fields.slug).is(DEFAULT)); + Tenant defaultTenant = mongoTemplate.findOne(tenantQuery, Tenant.class).block(); + assert defaultTenant != null : "Default tenant not found"; + cacheableRepositoryHelper.evictCachedTenant(defaultTenant.getId()).block(); } private static Mono executeForCollection(ReactiveMongoTemplate mongoTemplate, String collectionName) {