@openneuro/server 4.34.0 → 4.34.1

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.34.0",
3
+ "version": "4.34.1",
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": "^2.7.0",
24
- "@openneuro/search": "^4.34.0",
24
+ "@openneuro/search": "^4.34.1",
25
25
  "@sentry/node": "^8.25.0",
26
26
  "@sentry/profiling-node": "^8.25.0",
27
27
  "base64url": "^3.0.0",
@@ -85,5 +85,5 @@
85
85
  "publishConfig": {
86
86
  "access": "public"
87
87
  },
88
- "gitHead": "7fba7bc8f590f788a4e4a95a5fb2a5b1ef9038b4"
88
+ "gitHead": "af9d77970641f2dcfd67921a8c39b9719743676c"
89
89
  }
@@ -178,7 +178,7 @@ export const datasetsFilter = (options) => (match) => {
178
178
  },
179
179
  {
180
180
  $match: {
181
- "summaries.0.modalities": options.modality,
181
+ "summaries.0.modalities": new RegExp(`^${options.modality}$`, "i"),
182
182
  },
183
183
  },
184
184
  ],
@@ -17,6 +17,7 @@ import { normalizeDOI } from "../../libs/doi/normalize"
17
17
  import { getDraftHead } from "../../datalad/dataset"
18
18
  import { downloadFiles } from "../../datalad/snapshots"
19
19
  import { snapshotValidation } from "./validation"
20
+ import { advancedDatasetSearchConnection } from "./dataset-search"
20
21
 
21
22
  export const snapshots = (obj) => {
22
23
  return datalad.getSnapshots(obj.id)
@@ -135,13 +136,28 @@ export const undoDeprecateSnapshot = async (
135
136
  }
136
137
  }
137
138
 
139
+ /** Query used to run a search for NIH datasets */
140
+ const brainInitiativeQuery = {
141
+ "bool": {
142
+ "filter": [
143
+ {
144
+ "match": {
145
+ "brainInitiative": {
146
+ "query": "true",
147
+ },
148
+ },
149
+ },
150
+ ],
151
+ },
152
+ }
153
+
138
154
  export const participantCount = (obj, { modality }) => {
139
- const cacheKey = modality === "NIH" ? "NIH" : modality || "all"
155
+ const cacheKey = modality || "all"
140
156
  const cache = new CacheItem(
141
157
  redis,
142
158
  CacheType.participantCount,
143
159
  [cacheKey],
144
- 3600,
160
+ 86400,
145
161
  )
146
162
 
147
163
  return cache.get(async () => {
@@ -151,23 +167,37 @@ export const participantCount = (obj, { modality }) => {
151
167
 
152
168
  let matchQuery: Record<string, unknown> = queryHasSubjects
153
169
 
154
- if (modality && modality !== "NIH") {
155
- matchQuery = {
156
- $and: [
157
- queryHasSubjects,
158
- {
159
- "summary.modalities": modality,
160
- },
161
- ],
170
+ if (modality === "nih") {
171
+ // For "nih" portal, we need to search for any relevant datasets first
172
+ const nihDatasets = []
173
+ while (true) {
174
+ let after = ""
175
+ const results = await advancedDatasetSearchConnection(null, {
176
+ query: brainInitiativeQuery,
177
+ datasetType: "All Public",
178
+ datasetStatus: "",
179
+ sortBy: "",
180
+ after,
181
+ first: 100,
182
+ }, { user: null, userInfo: {} })
183
+ nihDatasets.push(...results.edges.map((edge) => edge.id))
184
+ if (!results.pageInfo.hasNextPage) {
185
+ break
186
+ } else {
187
+ after = results.pageInfo.endCursor
188
+ }
162
189
  }
163
- } else if (modality === "NIH") {
164
190
  // When modality is 'NIH', we don't filter by a specific modality.
165
191
  // Instead, we query for datasets that have any modality within the NIH portal
192
+ matchQuery = {
193
+ $expr: { $in: ["$id", nihDatasets] },
194
+ }
195
+ } else {
166
196
  matchQuery = {
167
197
  $and: [
168
198
  queryHasSubjects,
169
199
  {
170
- "summary.modalities": { $exists: true },
200
+ "summary.modalities": new RegExp(`^${modality}$`, "i"),
171
201
  },
172
202
  ],
173
203
  }