Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Refactor MongodbUtils to remove caching logic from getCollection method
  • Loading branch information
zhangshenghang committed Nov 25, 2025
commit e503f459a3c491b7fd36752ccc756009a56f9334
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;

import static com.mongodb.client.model.Aggregates.match;
Expand Down Expand Up @@ -87,8 +85,6 @@
@Slf4j
public class MongodbUtils {

private static final Map<TableId, MongoCollection<?>> cache = new ConcurrentHashMap<>();

public static ChangeStreamDescriptor getChangeStreamDescriptor(
@Nonnull MongodbSourceConfig sourceConfig,
List<String> discoveredDatabases,
Expand Down Expand Up @@ -364,16 +360,9 @@ public static BsonDocument readCollectionMetadata(
@SuppressWarnings("unchecked")
public static <T> @Nonnull MongoCollection<T> getCollection(
MongoClient mongoClient, TableId collectionId, Class<T> documentClass) {
MongoCollection<?> cachedCollection = cache.get(collectionId);
if (cachedCollection == null) {
MongoCollection<T> collection =
mongoClient
.getDatabase(collectionId.catalog())
.getCollection(collectionId.table(), documentClass);
cache.put(collectionId, collection);
return collection;
}
return (MongoCollection<T>) cachedCollection;
return mongoClient
.getDatabase(collectionId.catalog())
.getCollection(collectionId.table(), documentClass);
}

public static MongoClient createMongoClient(MongodbSourceConfig sourceConfig) {
Expand Down