@openneuro/server 4.11.0 → 4.12.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openneuro/server",
3
- "version": "4.11.0",
3
+ "version": "4.12.0-alpha.0",
4
4
  "description": "Core service for the OpenNeuro platform.",
5
5
  "license": "MIT",
6
6
  "main": "src/server.js",
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "@apollo/client": "3.4.17",
20
20
  "@elastic/elasticsearch": "7.15.0",
21
- "@openneuro/search": "^4.11.0",
21
+ "@openneuro/search": "^4.12.0-alpha.0",
22
22
  "@passport-next/passport-google-oauth2": "^1.0.0",
23
23
  "@sentry/node": "^4.5.3",
24
24
  "apollo-server": "2.25.3",
@@ -105,5 +105,5 @@
105
105
  "publishConfig": {
106
106
  "access": "public"
107
107
  },
108
- "gitHead": "4795359e0756b2f6d83f385172a80d9b26b5fdc8"
108
+ "gitHead": "3d8f7524b2233605f2da66f05de90b2e96e7a127"
109
109
  }
@@ -12,7 +12,7 @@ import * as subscriptions from '../handlers/subscriptions.js'
12
12
  import { generateDataladCookie } from '../libs/authentication/jwt'
13
13
  import { redis } from '../libs/redis'
14
14
  import CacheItem, { CacheType } from '../cache/item'
15
- import { updateDatasetRevision, expireDraftFiles } from './draft.js'
15
+ import { updateDatasetRevision } from './draft.js'
16
16
  import { fileUrl, getFileName, encodeFilePath, filesUrl } from './files'
17
17
  import { getAccessionNumber } from '../libs/dataset.js'
18
18
  import Dataset from '../models/dataset'
@@ -309,7 +309,6 @@ export const testBlacklist = (path, filename) =>
309
309
  export const addFile = async (datasetId, path, file) => {
310
310
  try {
311
311
  const { filename, mimetype, createReadStream, capacitor } = await file
312
- await expireDraftFiles(datasetId)
313
312
 
314
313
  // Apply blacklist to uploaded files
315
314
  if (testBlacklist(path, filename)) {
@@ -127,7 +127,6 @@ export const description = obj => {
127
127
  return cache
128
128
  .get(() => {
129
129
  return getFiles(datasetId, revision)
130
- .then(response => response.files)
131
130
  .then(getDescriptionObject(datasetId))
132
131
  .then(uncachedDescription => ({ id: revision, ...uncachedDescription }))
133
132
  })
@@ -4,16 +4,9 @@
4
4
  import fetch from 'node-fetch'
5
5
  import request from 'superagent'
6
6
  import Dataset from '../models/dataset'
7
- import { redis } from '../libs/redis'
8
- import CacheItem, { CacheType } from '../cache/item'
9
7
  import publishDraftUpdate from '../graphql/utils/publish-draft-update.js'
10
8
  import { getDatasetWorker } from '../libs/datalad-service'
11
9
 
12
- export const expireDraftFiles = datasetId => {
13
- const cache = new CacheItem(redis, CacheType.commitFiles, [datasetId])
14
- return cache.drop()
15
- }
16
-
17
10
  export const getDraftRevision = async datasetId => {
18
11
  const draftUrl = `http://${getDatasetWorker(
19
12
  datasetId,
@@ -29,10 +22,6 @@ export const updateDatasetRevision = (datasetId, gitRef) => {
29
22
  */
30
23
  return Dataset.updateOne({ id: datasetId }, { modified: new Date() })
31
24
  .exec()
32
- .then(() => {
33
- // Remove the now invalid draft files cache
34
- return expireDraftFiles(datasetId)
35
- })
36
25
  .then(() => publishDraftUpdate(datasetId, gitRef))
37
26
  }
38
27
 
@@ -61,19 +61,17 @@ export const computeTotalSize = files =>
61
61
  * Get files for a specific revision
62
62
  * Similar to getDraftFiles but different cache key and fixed revisions
63
63
  * @param {string} datasetId - Dataset accession number
64
- * @param {string} hexsha - Git treeish hexsha
64
+ * @param {string} treeish - Git treeish hexsha
65
65
  */
66
- export const getFiles = (datasetId, hexsha) => {
66
+ export const getFiles = (datasetId, treeish) => {
67
67
  const cache = new CacheItem(redis, CacheType.commitFiles, [
68
68
  datasetId,
69
- hexsha.substring(0, 7),
69
+ treeish.substring(0, 7),
70
70
  ])
71
71
  return cache.get(() =>
72
72
  request
73
73
  .get(
74
- `${getDatasetWorker(
75
- datasetId,
76
- )}/datasets/${datasetId}/snapshots/${hexsha}/files`,
74
+ `${getDatasetWorker(datasetId)}/datasets/${datasetId}/tree/${treeish}`,
77
75
  )
78
76
  .set('Accept', 'application/json')
79
77
  .then(response => {
@@ -81,11 +79,7 @@ export const getFiles = (datasetId, hexsha) => {
81
79
  const {
82
80
  body: { files },
83
81
  } = response
84
- const size = computeTotalSize(files)
85
- return {
86
- files: files.map(addFileUrl(datasetId, hexsha)),
87
- size,
88
- }
82
+ return files.map(addFileUrl(datasetId, treeish))
89
83
  }
90
84
  }),
91
85
  )
@@ -155,9 +155,7 @@ export const createSnapshot = async (
155
155
  snapshotChanges,
156
156
  )
157
157
  snapshot.created = new Date()
158
- const { files, size } = await getFiles(datasetId, tag)
159
- snapshot.files = files
160
- snapshot.size = size
158
+ snapshot.files = await getFiles(datasetId, tag)
161
159
 
162
160
  await Promise.all([
163
161
  // Update the draft status in datasets collection in case any changes were made (DOI, License)
@@ -1,24 +1,25 @@
1
+ import Summary from '../../models/summary'
1
2
  import { summary } from './summary.js'
2
3
  import { issues } from './issues.js'
3
4
  import { description } from './description.js'
4
5
  import { readme } from './readme.js'
5
6
  import { getDraftRevision, updateDatasetRevision } from '../../datalad/draft.js'
6
7
  import { checkDatasetWrite } from '../permissions.js'
7
- import { getFiles, filterFiles } from '../../datalad/files.js'
8
+ import { getFiles } from '../../datalad/files.js'
8
9
  import { filterRemovedAnnexObjects } from '../utils/file.js'
9
10
 
10
11
  // A draft must have a dataset parent
11
12
  const draftFiles = async (dataset, args, { userInfo }) => {
12
13
  const hexsha = await getDraftRevision(dataset.id)
13
- const { files } = await getFiles(dataset.id, hexsha)
14
- const prefixFiltered = filterFiles('prefix' in args && args.prefix)(files)
15
- return filterRemovedAnnexObjects(dataset.id, userInfo)(prefixFiltered)
14
+ const files = await getFiles(dataset.id, args.tree || hexsha)
15
+ return filterRemovedAnnexObjects(dataset.id, userInfo)(files)
16
16
  }
17
17
 
18
18
  const draftSize = async (dataset, args, { userInfo }) => {
19
19
  const hexsha = await getDraftRevision(dataset.id)
20
- const { size } = await getFiles(dataset.id, hexsha)
21
- return size
20
+ return Summary.findOne({ datasetId: dataset.id, id: hexsha })
21
+ .exec()
22
+ .then(res => res?.toObject()?.size)
22
23
  }
23
24
 
24
25
  /**
@@ -6,7 +6,8 @@ import { readme } from './readme.js'
6
6
  import { description } from './description.js'
7
7
  import { summary } from './summary.js'
8
8
  import { snapshotIssues } from './issues.js'
9
- import { getFiles, filterFiles } from '../../datalad/files.js'
9
+ import { getFiles } from '../../datalad/files.js'
10
+ import Summary from '../../models/summary'
10
11
  import DatasetModel from '../../models/dataset'
11
12
  import { filterRemovedAnnexObjects } from '../utils/file.js'
12
13
  import DeprecatedSnapshot from '../../models/deprecatedSnapshot'
@@ -28,13 +29,14 @@ export const snapshot = (obj, { datasetId, tag }, context) => {
28
29
  description: () => description(snapshot),
29
30
  readme: () => readme(snapshot),
30
31
  summary: () => summary({ id: datasetId, revision: snapshot.hexsha }),
31
- files: ({ prefix }) =>
32
- getFiles(datasetId, snapshot.hexsha)
33
- .then(response => response.files)
34
- .then(filterFiles(prefix))
35
- .then(filterRemovedAnnexObjects(datasetId, context.userInfo)),
32
+ files: ({ tree }) =>
33
+ getFiles(datasetId, tree || snapshot.hexsha).then(
34
+ filterRemovedAnnexObjects(datasetId, context.userInfo),
35
+ ),
36
36
  size: () =>
37
- getFiles(datasetId, snapshot.hexsha).then(response => response.size),
37
+ Summary.findOne({ datasetId: datasetId, id: snapshot.hexsha })
38
+ .exec()
39
+ .then(res => res?.toObject()?.size),
38
40
  deprecated: () => deprecated({ datasetId, tag }),
39
41
  related: () => related(datasetId),
40
42
  onBrainlife: () => onBrainlife(snapshot),
@@ -434,7 +434,7 @@ export const typeDefs = `
434
434
  # Validator issues
435
435
  issues: [ValidationIssue]
436
436
  # Committed files in the working tree
437
- files(prefix: String = ""): [DatasetFile]
437
+ files(tree: String): [DatasetFile]
438
438
  # dataset_description.json fields
439
439
  description: Description
440
440
  # Dataset README
@@ -461,7 +461,7 @@ export const typeDefs = `
461
461
  # bids-validator issues for this snapshot
462
462
  issues: [ValidationIssue]
463
463
  # Snapshot files
464
- files(prefix: String = ""): [DatasetFile]
464
+ files(tree: String): [DatasetFile]
465
465
  # dataset_description.json fields
466
466
  description: Description
467
467
  # Snapshot usage and download statistics
@@ -689,7 +689,6 @@ export const typeDefs = `
689
689
  size: BigInt
690
690
  annexed: Boolean
691
691
  urls: [String]
692
- objectpath: String
693
692
  # Return a flag if this is a directory which contains more files
694
693
  directory: Boolean
695
694
  }