Skip to content

Commit 89d283b

Browse files
committed
improvement(FeedSourceSummary,java): Addressed PR feedback
Removed static prefixes and redundant field references
1 parent cf5458d commit 89d283b

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

src/main/java/com/conveyal/datatools/manager/models/FeedSourceSummary.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
88
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
99
import com.google.common.collect.Lists;
10-
import com.mongodb.client.model.Aggregates;
1110
import com.mongodb.client.model.Sorts;
1211
import com.mongodb.client.model.UnwindOptions;
1312
import com.mongodb.client.model.Variable;
@@ -39,6 +38,7 @@
3938
import static com.mongodb.client.model.Projections.computed;
4039
import static com.mongodb.client.model.Projections.fields;
4140
import static com.mongodb.client.model.Projections.include;
41+
import static com.mongodb.client.model.Sorts.descending;
4242
import static java.util.Objects.requireNonNullElse;
4343

4444
/**
@@ -171,7 +171,7 @@ public static List<FeedSourceSummary> getFeedSourceSummaries(String projectId, S
171171

172172
// Project only necessary fields early to reduce document size.
173173
project(
174-
fields(include(
174+
include(
175175
"_id",
176176
"name",
177177
"deployable",
@@ -180,7 +180,7 @@ public static List<FeedSourceSummary> getFeedSourceSummaries(String projectId, S
180180
"labelIds",
181181
"url",
182182
"filename",
183-
"noteIds")
183+
"noteIds"
184184
)
185185
),
186186
sort(Sorts.ascending("name"))
@@ -197,15 +197,15 @@ public static List<FeedSourceSummary> getFeedSourceSummaries(String projectId, S
197197
public static Map<String, FeedVersionSummary> getLatestFeedVersionForFeedSources(String projectId) {
198198
List<Bson> feedVersionPipeline = Arrays.asList(
199199
// Match FeedVersion documents where feedSourceId equals the feedSourceId passed from the outer document.
200-
Aggregates.match(
200+
match(
201201
expr(
202202
new Document("$eq", Arrays.asList("$feedSourceId", "$$feedSourceId"))
203203
)
204204
),
205-
Aggregates.sort(Sorts.descending("version")),
206-
Aggregates.limit(1),
205+
sort(descending("version")),
206+
limit(1),
207207
// Project only the fields needed from the FeedVersion to reduce payload size.
208-
Aggregates.project(fields(
208+
project(
209209
include(
210210
"version",
211211
"_id",
@@ -215,14 +215,14 @@ public static Map<String, FeedVersionSummary> getLatestFeedVersionForFeedSources
215215
"gtfsPlusValidation",
216216
"namespace"
217217
)
218-
))
218+
)
219219
);
220220

221221
// Define the variable passed into the lookup pipeline.
222222
List<Variable<String>> feedSourceId = List.of(new Variable<>("feedSourceId", "$_id"));
223223

224224
// $lookup that uses the above pipeline to produce "latestFeedVersion" (an array with at most one element).
225-
Bson lookupLatestFeedVersion = Aggregates.lookup(
225+
Bson lookupLatestFeedVersion = lookup(
226226
"FeedVersion",
227227
feedSourceId,
228228
feedVersionPipeline,
@@ -232,21 +232,21 @@ public static Map<String, FeedVersionSummary> getLatestFeedVersionForFeedSources
232232
// Pipeline to find the published FeedVersion by namespace (or identifier stored in publishedVersionId)
233233
List<Bson> publishedFeedVersionPipeline = Arrays.asList(
234234
// Match FeedVersion documents where namespace equals the outer document's publishedVersionId.
235-
Aggregates.match(
235+
match(
236236
expr(
237237
new Document("$eq", Arrays.asList("$namespace", "$$publishedVersionId"))
238238
)
239239
),
240-
Aggregates.limit(1),
240+
limit(1),
241241
// Project only the validationResult because that's all that is needed later.
242-
Aggregates.project(fields(include("validationResult")))
242+
project(include("validationResult"))
243243
);
244244

245245
// Pass publishedVersionId from the local document into the lookup pipeline.
246246
List<Variable<String>> publishedVersionId = List.of(new Variable<>("publishedVersionId", "$publishedVersionId"));
247247

248248
// $lookup that uses the above pipeline to produce "publishedFeedVersion" (an array with at most one element).
249-
Bson lookupPublishedFeedVersion = Aggregates.lookup(
249+
Bson lookupPublishedFeedVersion = lookup(
250250
"FeedVersion",
251251
publishedVersionId,
252252
publishedFeedVersionPipeline,
@@ -329,19 +329,19 @@ public static Map<String, FeedVersionSummary> getFeedVersionsFromLatestDeploymen
329329
)));
330330

331331
// Sort deployments by lastUpdated descending.
332-
stages.add(sort(Sorts.descending("lastUpdated")));
332+
stages.add(sort(descending("lastUpdated")));
333333
stages.add(limit(1));
334334

335335
List<Bson> feedVersionPipeline = Arrays.asList(
336336
match(expr(new Document("$in", Arrays.asList("$_id", "$$feedVersionIds")))),
337-
project(fields(
337+
project(
338338
include(
339339
"feedSourceId",
340340
"validationResult.firstCalendarDate",
341341
"validationResult.lastCalendarDate",
342342
"validationResult.errorCount"
343343
)
344-
))
344+
)
345345
);
346346

347347
// Use pipeline form of lookup to fetch FeedVersions matching deployment’s feedVersionIds
@@ -356,13 +356,13 @@ public static Map<String, FeedVersionSummary> getFeedVersionsFromLatestDeploymen
356356
stages.add(unwind("$feedVersions", new UnwindOptions().preserveNullAndEmptyArrays(false)));
357357
stages.add(replaceRoot("$feedVersions"));
358358
// Final projection: select and compute only the fields needed for the output to minimize size.
359-
stages.add(project(fields(
359+
stages.add(project(
360360
include(
361361
"_id",
362362
"feedSourceId",
363363
"validationResult"
364364
)
365-
)));
365+
));
366366

367367
return extractFeedVersionSummaries(
368368
"Project",
@@ -384,7 +384,7 @@ public static Map<String, FeedVersionSummary> getFeedVersionsFromPinnedDeploymen
384384
stages.add(match(in("_id", projectId)));
385385

386386
// Project only pinnedDeploymentId to keep doc small.
387-
stages.add(project(fields(include("pinnedDeploymentId"))));
387+
stages.add(project(include("pinnedDeploymentId")));
388388

389389
// Lookup Deployment documents by pinnedDeploymentId.
390390
stages.add(lookup("Deployment", "pinnedDeploymentId", "_id", "deployment"));
@@ -394,20 +394,20 @@ public static Map<String, FeedVersionSummary> getFeedVersionsFromPinnedDeploymen
394394

395395
// Define pipeline in $lookup to filter and project FeedVersion docs.
396396
List<Bson> feedVersionPipeline = Arrays.asList(
397-
Aggregates.match(
397+
match(
398398
expr(
399399
new Document("$in", Arrays.asList("$_id", "$$feedVersionIds"))
400400
)
401401
),
402-
project(fields(
402+
project(
403403
include(
404404
"_id",
405405
"feedSourceId",
406406
"validationResult.firstCalendarDate",
407407
"validationResult.lastCalendarDate",
408408
"validationResult.errorCount"
409409
)
410-
))
410+
)
411411
);
412412

413413
// Define variable for correlated lookup on FeedVersion collection.

0 commit comments

Comments
 (0)