Skip to content

Commit 2e120b2

Browse files
committed
Fix bug in getting last modified timestamp
1 parent e2ac808 commit 2e120b2

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/main/java/picoded/dstack/mongodb/MongoDB_FileWorkspaceMap.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,10 +848,14 @@ public long backend_createdTimestamp(final String oid, final String filepath) {
848848
public long backend_modifiedTimestamp(final String oid, final String filepath) {
849849
// Lets build the query for the "root file"
850850
Bson query = Filters.eq("filename", oid + "/" + filepath);
851-
851+
852852
// Lets prepare the search
853-
GridFSFindIterable search = gridFSBucket.find(query).limit(1);
854-
853+
GridFSFindIterable search = gridFSBucket.find(query)
854+
// GridFS uses an index on the files collection using the filename and uploadDate fields.
855+
// Make sure to sort the query by uploadDate descending (-1) to ensure that we get the latest file.
856+
.sort((new Document()).append("uploadDate", -1 /* descending*/ ))
857+
.limit(1);
858+
855859
// Lets iterate the search result, and return true on an item
856860
try (MongoCursor<GridFSFile> cursor = search.iterator()) {
857861
if (cursor.hasNext()) {

0 commit comments

Comments
 (0)