Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -35,6 +38,8 @@ public class Migration059PolicySetToPolicyMap {

private final ReactiveMongoTemplate mongoTemplate;

private final CacheableRepositoryHelper cacheableRepositoryHelper;

private static final Set<String> CE_COLLECTION_NAMES = Set.of(
"actionCollection",
"application",
Expand Down Expand Up @@ -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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a block call?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnaghHegde here the MongoTemplate that is injected is a reactive one, in other cases we inject the non-reactive template. The blocking is required just to make sure the eviction happens after the migration is completed. This can be done using .then but thought it won't make any difference as the earlier call is also blocking in nature.

assert defaultTenant != null : "Default tenant not found";
cacheableRepositoryHelper.evictCachedTenant(defaultTenant.getId()).block();
}

private static Mono<Void> executeForCollection(ReactiveMongoTemplate mongoTemplate, String collectionName) {
Expand Down