Skip to content

Commit 7c03e93

Browse files
authored
Merge pull request #3174 from OpenNeuroOrg/3173-fix-draft-time-caching
Resolve draft modified time from commit history instead of cache
2 parents b165334 + 9897641 commit 7c03e93

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

packages/openneuro-server/src/datalad/dataset.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,26 @@ export const createDataset = async (
6969
}
7070
}
7171

72+
interface WorkerDraftFields {
73+
// Commit id hash
74+
ref: string
75+
// Commit tree ref
76+
tree: string
77+
// Commit message
78+
message: string
79+
// Commit author time
80+
modified: string
81+
}
82+
7283
/**
7384
* Return the latest commit
7485
* @param {string} id Dataset accession number
7586
*/
76-
export const getDraftHead = async (id) => {
87+
export const getDraftHead = async (id): Promise<WorkerDraftFields> => {
7788
const draftRes = await request
7889
.get(`${getDatasetWorker(id)}/datasets/${id}/draft`)
7990
.set("Accept", "application/json")
80-
return draftRes.body.hexsha
91+
return draftRes.body
8192
}
8293

8394
/**
@@ -87,7 +98,7 @@ export const getDataset = async (id) => {
8798
const dataset = await Dataset.findOne({ id }).lean()
8899
return {
89100
...dataset,
90-
revision: await getDraftHead(id),
101+
revision: (await getDraftHead(id)).ref,
91102
}
92103
}
93104

packages/openneuro-server/src/graphql/resolvers/dataset.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,14 @@ const worker = (obj) => getDatasetWorker(obj.id)
276276
*/
277277
const Dataset = {
278278
uploader: (ds) => user(ds, { id: ds.uploader }),
279-
draft: async (obj) => ({
280-
id: obj.id,
281-
revision: await datalad.getDraftHead(obj.id),
282-
modified: obj.modified,
283-
}),
279+
draft: async (obj) => {
280+
const draftHead = await datalad.getDraftHead(obj.id)
281+
return {
282+
id: obj.id,
283+
revision: draftHead.ref,
284+
modified: draftHead.modified,
285+
}
286+
},
284287
snapshots,
285288
latestSnapshot,
286289
analytics,

packages/openneuro-server/src/graphql/resolvers/snapshots.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export const latestSnapshot = async (obj, _, context) => {
227227
// In the case where there are no real snapshots, return most recent commit as snapshot
228228
return await snapshot(
229229
obj,
230-
{ datasetId: obj.id, tag: await getDraftHead(obj.id) },
230+
{ datasetId: obj.id, tag: (await getDraftHead(obj.id)).ref },
231231
context,
232232
)
233233
}

services/datalad/datalad_service/handlers/draft.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
import os
23

34
import falcon
@@ -19,8 +20,11 @@ async def on_get(self, req, resp, dataset):
1920
if dataset and os.path.exists(dataset_path):
2021
repo = pygit2.Repository(dataset_path)
2122
commit = repo.revparse_single('HEAD')
22-
resp.media = {'hexsha': str(commit.id),
23-
'tree': str(commit.tree_id)}
23+
resp.media = {'ref': str(commit.id),
24+
'hexsha': str(commit.id), # Deprecate 'hexsha' but retain for now
25+
'tree': str(commit.tree_id),
26+
'message': str(commit.message),
27+
'modified': datetime.datetime.fromtimestamp(commit.author.time).isoformat() + 'Z'}
2428
resp.status = falcon.HTTP_OK
2529
else:
2630
resp.status = falcon.HTTP_NOT_FOUND

0 commit comments

Comments
 (0)