MCPcopy Create free account
hub / github.com/OpenSIST/OpenSIST.github.io / getMetadataBatch

Function getMetadataBatch

src/Data/UserData.js:201–258  ·  view source on GitHub ↗
(displayNames, isRefresh = false, {priority = FOREGROUND_PRIORITY} = {})

Source from the content-addressed store, hash-verified

199 )));
200 const expiredDisplayNames = uniqueDisplayNames.filter((displayName, index) => (
201 isCacheEntryExpired(entries[index], isRefresh)
202 ));
203 const request = beginCacheRequests(expiredDisplayNames.map(metadataCacheKey), priority, requestEpoch);
204 const requestDisplayNames = request.keys.map(displayNameFromMetadataCacheKey);
205
206 if (requestDisplayNames.length === 0) {
207 return cachedMetadata;
208 }
209
210 try {
211 const response = await apiJson(GET_METADATA_BATCH, {
212 body: {display_names: requestDisplayNames},
213 fetchPriority: priority,
214 });
215 const refreshedRawMetadata = requestDisplayNames.reduce((metadataByName, displayName) => ({
216 ...metadataByName,
217 [displayName]: response.data?.[displayName] ?? null,
218 }), {});
219 const cacheWrites = requestDisplayNames.map((displayName) => {
220 const key = metadataCacheKey(displayName);
221 return writeCacheValue(key, refreshedRawMetadata[displayName], {
222 requestEpoch: request.epoch,
223 requestVersion: request.versionFor(key),
224 });
225 });
226 if (priority === BACKGROUND_PRIORITY) {
227 await Promise.all(cacheWrites);
228 } else {
229 cacheWrites.forEach((cacheWrite) => void cacheWrite.catch(() => {
230 }));
231 }
232 const refreshedMetadata = Object.fromEntries(
233 Object.entries(refreshedRawMetadata).map(([displayName, metadata]) => (
234 [displayName, metadataWithLatestYear(metadata)]
235 ))
236 );
237 return {
238 ...cachedMetadata,
239 ...refreshedMetadata,
240 };
241 } finally {
242 request.release();
243 }
244}
245
246/**
247 * Find the latest year with data for a given applicant
248 * @param {string[]} applicantIDs - Applicant IDs in the form "displayName@year"
249 * @returns {Promise<number|null>} - Latest year or null if no data found
250 */
251function findLatestYearForApplicant(applicantIDs = []) {
252 const validYears = applicantIDs
253 .map(id => Number.parseInt(id.split('@')[1], 10))
254 .filter(Number.isFinite);
255 return validYears.length > 0 ? Math.max(...validYears) : null;
256}
257
258function metadataWithLatestYear(metadata) {

Callers 2

prefetchProfilesFunction · 0.90
getMetadataFunction · 0.85

Calls 8

getCacheEpochFunction · 0.90
readCacheEntryFunction · 0.90
isCacheEntryExpiredFunction · 0.90
beginCacheRequestsFunction · 0.90
apiJsonFunction · 0.90
writeCacheValueFunction · 0.90
metadataCacheKeyFunction · 0.85
metadataWithLatestYearFunction · 0.85

Tested by

no test coverage detected