@openneuro/server 4.44.6 → 4.45.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.44.6",
3
+ "version": "4.45.0",
4
4
  "description": "Core service for the OpenNeuro platform.",
5
5
  "license": "MIT",
6
6
  "main": "src/server.js",
@@ -21,7 +21,7 @@
21
21
  "@elastic/elasticsearch": "8.13.1",
22
22
  "@graphql-tools/schema": "^10.0.0",
23
23
  "@keyv/redis": "^4.5.0",
24
- "@openneuro/search": "^4.44.6",
24
+ "@openneuro/search": "^4.45.0",
25
25
  "@sentry/node": "^10.37.0",
26
26
  "@sentry/profiling-node": "^10.37.0",
27
27
  "base64url": "^3.0.0",
@@ -89,5 +89,5 @@
89
89
  "publishConfig": {
90
90
  "access": "public"
91
91
  },
92
- "gitHead": "1c266a5a49f11d604ea83725661c7896df40eca1"
92
+ "gitHead": "6a61f1a6aabd06e403acbc58dd00a1b0cf696143"
93
93
  }
@@ -17,9 +17,6 @@ export const trackAnalytics = async (datasetId, tag, type) => {
17
17
  views: 1,
18
18
  },
19
19
  },
20
- {
21
- upsert: true,
22
- },
23
20
  ).exec()
24
21
  } else if (type === "downloads") {
25
22
  return Dataset.updateOne(
@@ -31,9 +28,6 @@ export const trackAnalytics = async (datasetId, tag, type) => {
31
28
  downloads: 1,
32
29
  },
33
30
  },
34
- {
35
- upsert: true,
36
- },
37
31
  ).exec()
38
32
  }
39
33
  }
@@ -503,7 +503,6 @@ export async function updatePublic(datasetId, publicFlag, user) {
503
503
  await Dataset.updateOne(
504
504
  { id: datasetId },
505
505
  { public: publicFlag, publishDate: new Date() },
506
- { upsert: true },
507
506
  ).exec()
508
507
  await updateEvent(event)
509
508
  }
@@ -103,13 +103,16 @@ const postSnapshot = async (
103
103
  export const getSnapshots = async (datasetId): Promise<SnapshotDocument[]> => {
104
104
  const dataset = await Dataset.findOne({ id: datasetId })
105
105
  if (!dataset) return null
106
- const url = `${getDatasetWorker(datasetId)}/datasets/${datasetId}/snapshots`
107
- return request
108
- .get(url)
109
- .set("Accept", "application/json")
110
- .then(({ body: { snapshots } }) => {
111
- return snapshots.sort(snapshotCreationComparison)
112
- })
106
+ const cache = new CacheItem(redis, CacheType.snapshot, [datasetId], 432000)
107
+ return cache.get(() => {
108
+ const url = `${getDatasetWorker(datasetId)}/datasets/${datasetId}/snapshots`
109
+ return request
110
+ .get(url)
111
+ .set("Accept", "application/json")
112
+ .then(({ body: { snapshots } }) => {
113
+ return snapshots.sort(snapshotCreationComparison)
114
+ })
115
+ })
113
116
  }
114
117
 
115
118
  const announceNewSnapshot = async (snapshot, datasetId, user) => {
@@ -175,6 +178,11 @@ export const createSnapshot = async (
175
178
  updateDatasetName(datasetId),
176
179
  ])
177
180
 
181
+ const snapshotListCache = new CacheItem(redis, CacheType.snapshot, [
182
+ datasetId,
183
+ ])
184
+ await snapshotListCache.drop()
185
+
178
186
  // Version is created here and event is updated
179
187
  await updateEvent(event)
180
188
 
@@ -205,6 +213,10 @@ export const deleteSnapshot = (datasetId, tag) => {
205
213
  tag,
206
214
  ])
207
215
  await snapshotCache.drop()
216
+ const snapshotListCache = new CacheItem(redis, CacheType.snapshot, [
217
+ datasetId,
218
+ ])
219
+ await snapshotListCache.drop()
208
220
  return body
209
221
  })
210
222
  }
@@ -42,7 +42,13 @@ export const brainInitiative = async (
42
42
  }
43
43
  }
44
44
  // Check for grant ids too - filter to only alphanumeric to improve matching across format differences
45
- const identifier = metadata.grantIdentifier.replace(/[^a-zA-Z0-9]/g, "")
45
+ const identifier = metadata?.grantIdentifier?.replace(
46
+ /[^a-zA-Z0-9]/g,
47
+ "",
48
+ )
49
+ if (!identifier) {
50
+ return false
51
+ }
46
52
  for (const grant of brainInitiativeGrants) {
47
53
  if (
48
54
  identifier.includes(grant)
@@ -5,8 +5,10 @@ import { description } from "./description.js"
5
5
  * Return "schema" or "legacy" depending on the validator preferred for a dataset
6
6
  */
7
7
  export async function datasetType(dsOrSnapshot): Promise<"schema" | "legacy"> {
8
- const ds = new Dataset({ id: dsOrSnapshot.datasetId })
9
- if (ds.schemaValidator) {
8
+ const ds = await Dataset.findOne({
9
+ id: dsOrSnapshot.datasetId || dsOrSnapshot.id,
10
+ }).lean()
11
+ if (ds && ds.schemaValidator) {
10
12
  return "schema"
11
13
  } else {
12
14
  const dsDescription = await description(dsOrSnapshot)