Skip to content

Commit f7a6179

Browse files
dragonpooludomikula
authored andcommitted
modify snapshot task logic to move from normal collection to timeseries one.
1 parent b605907 commit f7a6179

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

server/api-service/lowcoder-server/src/main/java/org/lowcoder/runner/migrations/DatabaseChangelog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public void addTimeSeriesSnapshotHistory(MongockTemplate mongoTemplate, CommonCo
329329

330330
// Aggregation pipeline to fetch the records
331331
List<Document> aggregationPipeline = Arrays.asList(
332-
new Document("$match", new Document("createdAt", new Document("$gte", thresholdDate))),
332+
new Document("$match", new Document("createdAt", new Document("$lte", thresholdDate))),
333333
new Document("$project", new Document()
334334
.append("applicationId", 1)
335335
.append("dsl", 1)
@@ -365,7 +365,7 @@ public void addTimeSeriesSnapshotHistory(MongockTemplate mongoTemplate, CommonCo
365365

366366
// Aggregation pipeline with $out
367367
List<Document> aggregationPipeline = Arrays.asList(
368-
new Document("$match", new Document("createdAt", new Document("$gte", thresholdDate))),
368+
new Document("$match", new Document("createdAt", new Document("$lte", thresholdDate))),
369369
new Document("$project", new Document()
370370
.append("applicationId", 1)
371371
.append("dsl", 1)

server/api-service/lowcoder-server/src/main/java/org/lowcoder/runner/task/ArchiveSnapshotTask.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ private int getMongoDBVersion() {
4646
private void archiveForVersion5AndAbove(Instant thresholdDate) {
4747
log.info("Running archival for MongoDB version >= 5");
4848

49-
MongoCollection<Document> sourceCollection = mongoTemplate.getDb().getCollection("applicationHistorySnapshotTS");
50-
MongoCollection<Document> targetCollection = mongoTemplate.getDb().getCollection("applicationHistorySnapshot");
49+
MongoCollection<Document> sourceCollection = mongoTemplate.getDb().getCollection("applicationHistorySnapshot");
50+
MongoCollection<Document> targetCollection = mongoTemplate.getDb().getCollection("applicationHistorySnapshotTS");
5151

5252
long totalDocuments = sourceCollection.countDocuments(Filters.lte("createdAt", thresholdDate));
5353
log.info("Total documents to archive: {}", totalDocuments);
@@ -91,7 +91,7 @@ private void archiveForVersion5AndAbove(Instant thresholdDate) {
9191
private void archiveForVersionBelow5(Instant thresholdDate) {
9292
log.info("Running archival for MongoDB version < 5");
9393

94-
MongoCollection<Document> sourceCollection = mongoTemplate.getDb().getCollection("applicationHistorySnapshotTS");
94+
MongoCollection<Document> sourceCollection = mongoTemplate.getDb().getCollection("applicationHistorySnapshot");
9595

9696
long totalDocuments = sourceCollection.countDocuments(Filters.lte("createdAt", thresholdDate));
9797
log.info("Total documents to archive: {}", totalDocuments);
@@ -119,7 +119,7 @@ private void archiveForVersionBelow5(Instant thresholdDate) {
119119
.append("modifiedBy", document.get("modifiedBy"))
120120
.append("updatedAt", document.get("updatedAt"))
121121
.append("id", document.get("id"))),
122-
new Document("$out", "applicationHistorySnapshot")
122+
new Document("$out", "applicationHistorySnapshotTS")
123123
)).first();
124124
} catch (Exception e) {
125125
log.error("Failed to aggregate and insert document with ID {}. Error: {}", document.getObjectId("id"), e.getMessage());

0 commit comments

Comments
 (0)