From 10e4c5e78e2ccd174f36443e6ed06f795c810489 Mon Sep 17 00:00:00 2001 From: Roman Kalyakin Date: Thu, 2 Jan 2025 20:16:05 +0100 Subject: [PATCH] Refactor resolvers to simplify function signatures and improve async handling --- src/hooks/resolvers/articles.resolvers.js | 23 ++-- src/hooks/search-info.ts | 22 ++-- src/internalServices/cachedResolvers.ts | 16 +-- src/models/search-facets.model.ts | 2 +- src/services/filters-items/extractors.js | 108 +++++++++--------- src/services/search/search.extractors.ts | 31 ++--- src/services/stats/stats.class.ts | 67 ++++++----- .../topics-graph/topics-graph.class.js | 96 +++++++++------- src/services/topics/topics.class.js | 51 +++++---- tsconfig.json | 6 +- 10 files changed, 222 insertions(+), 200 deletions(-) diff --git a/src/hooks/resolvers/articles.resolvers.js b/src/hooks/resolvers/articles.resolvers.js index 7cb79eb6..17091573 100644 --- a/src/hooks/resolvers/articles.resolvers.js +++ b/src/hooks/resolvers/articles.resolvers.js @@ -1,3 +1,4 @@ +import { buildResolvers } from '../../internalServices/cachedResolvers' import { resolveAsync } from '../../util/solr/adapters' const lodash = require('lodash') const debug = require('debug')('impresso/hooks/resolvers:articles') @@ -8,16 +9,22 @@ const resolveTopics = () => async context => { if (!context.result) { debug('resolveTopics: no "context.result" found') } else if (context.result.data && context.result.data.length) { - context.result.data = context.result.data.map(d => { - if (!d.topics) { + const resolvers = buildResolvers(context.app) + + context.result.data = await Promise.all( + context.result.data.map(async d => { + if (!d.topics) { + return d + } + d.topics = await Promise.all( + d.topics.map(async at => { + at.topic = await resolvers.topic(at.topicUid, 'topic') + return at + }) + ) return d - } - d.topics = d.topics.map(at => { - at.topic = Topic.getCached(at.topicUid) - return at }) - return d - }) + ) } else if (context.result.topics && context.result.topics.length) { debug(`resolveTopics: "context.result.topics" found with ${context.result.topics.length} topics`) diff --git a/src/hooks/search-info.ts b/src/hooks/search-info.ts index fd6e3833..bec384b2 100644 --- a/src/hooks/search-info.ts +++ b/src/hooks/search-info.ts @@ -1,11 +1,10 @@ import { HookContext } from '@feathersjs/feathers' import { AppServices, ImpressoApplication } from '../types' import { mediaSourceToNewspaper } from '../services/newspapers/newspapers.class' +import { buildResolvers } from '../internalServices/cachedResolvers' const debug = require('debug')('impresso/hooks:search-info') -const Topic = require('../models/topics.model') - /** * check if there are any params to be added to our beloved facets. * This hook **must** follow facets validation. @@ -63,11 +62,14 @@ const resolveFacets = () => async (context: HookContext ({ - ...d, - item: Topic.getCached(d.val), - uid: d.val, - })) + const resolvers = buildResolvers(context.app) + context.result.info.facets.topic.buckets = await Promise.all( + context.result.info.facets.newspaper.buckets.map(async (d: any) => ({ + ...d, + item: await resolvers.topic(d.val), + uid: d.val, + })) + ) } } } @@ -88,10 +90,12 @@ const resolveQueryComponents = () => async (context: HookContext mediaSourceToNewspaper(mediaSourcesLookup[uid])) } } else if (d.type === 'topic') { + const resolvers = buildResolvers(context.app) + if (!Array.isArray(d.q)) { - d.items = [Topic.getCached(d.q)] + d.items = [resolvers.topic(d.q)] } else { - d.items = d.q.map((uid: string) => Topic.getCached(uid)) + d.items = await Promise.all(d.q.map(async (uid: string) => await resolvers.topic(uid))) } } else if (d.type === 'collection' && context.params.user) { // eslint-disable-next-line no-await-in-loop diff --git a/src/internalServices/cachedResolvers.ts b/src/internalServices/cachedResolvers.ts index 0ecb3608..441eb60c 100644 --- a/src/internalServices/cachedResolvers.ts +++ b/src/internalServices/cachedResolvers.ts @@ -8,30 +8,30 @@ import { Newspaper as NewspaperInternal } from '../models/generated/schemas' export type CachedFacetType = 'newspaper' | 'topic' | 'person' | 'location' | 'collection' | 'year' -type IResolver = (id: string, type: CachedFacetType) => Promise +export type IResolver = (id: string) => Promise export type ICachedResolvers = Record> -const collectionResolver: IResolver = async (id: string, _) => +const collectionResolver: IResolver = async (id: string) => new Collection({ uid: id, name: id, }) -const entityResolver: IResolver = async (id: string, type: CachedFacetType) => +const entityResolver = async (id: string, type: CachedFacetType) => new Entity({ uid: id, type, name: Entity.getNameFromUid(id), }) -const topicResolver: IResolver = async (id: string, _) => Topic.getCached(id) +const topicResolver: IResolver = async (id: string) => Topic.getCached(id) -const yearResolver: IResolver = async (id: string, _) => Year.getCached(id) +const yearResolver: IResolver = async (id: string) => Year.getCached(id) const getNewspaperResolver = (app: ImpressoApplication): IResolver => { const mediaSources = app.service('media-sources') - return async (id: string, _) => { + return async (id: string) => { const lookup = await mediaSources.getLookup() const item = lookup[id] return optionalMediaSourceToNewspaper(item) @@ -40,8 +40,8 @@ const getNewspaperResolver = (app: ImpressoApplication): IResolver ({ collection: collectionResolver, - location: entityResolver, - person: entityResolver, + location: (id: string) => entityResolver(id, 'location'), + person: (id: string) => entityResolver(id, 'person'), topic: topicResolver, year: yearResolver, newspaper: getNewspaperResolver(app), diff --git a/src/models/search-facets.model.ts b/src/models/search-facets.model.ts index 9d3210f9..74ee3fa7 100644 --- a/src/models/search-facets.model.ts +++ b/src/models/search-facets.model.ts @@ -62,7 +62,7 @@ class SearchFacetBucket implements ISearchFacetBucket { const uid = String(val) const resolver = resolvers[type as CachedFacetType] - const item = resolver != null ? await resolver(uid, type as CachedFacetType) : undefined + const item = resolver != null ? await resolver(uid) : undefined return new SearchFacetBucket({ val, diff --git a/src/services/filters-items/extractors.js b/src/services/filters-items/extractors.js index 6575fa25..350f6f1b 100644 --- a/src/services/filters-items/extractors.js +++ b/src/services/filters-items/extractors.js @@ -1,82 +1,82 @@ -const newspapersIndex = require('../../data')('newspapers'); -const Topic = require('../../models/topics.model'); -const Entity = require('../../models/entities.model'); -const Year = require('../../models/years.model'); +import { buildResolvers } from '../../internalServices/cachedResolvers' +const Entity = require('../../models/entities.model') -const isDateRangeString = v => v.match(/.+ TO .+/) != null; -const getDateStrings = v => v.match(/(.+) TO (.+)/).slice(1, 3); +const isDateRangeString = v => v.match(/.+ TO .+/) != null +const getDateStrings = v => v.match(/(.+) TO (.+)/).slice(1, 3) -function daterangeExtractor ({ q = '' }) { - const values = Array.isArray(q) ? q : [q]; +function daterangeExtractor({ q = '' }) { + const values = Array.isArray(q) ? q : [q] // if `q` is an array with two date strings, return one item for them - const isTwoDatesArray = values.length === 2 && values.filter(isDateRangeString).length === 0; + const isTwoDatesArray = values.length === 2 && values.filter(isDateRangeString).length === 0 if (isTwoDatesArray) { - const [start, end] = values; - return [{ start, end }]; + const [start, end] = values + return [{ start, end }] } // otherwise parse ranges - return values.map((value) => { - const [start, end] = getDateStrings(value); - return { start, end }; - }); + return values.map(value => { + const [start, end] = getDateStrings(value) + return { start, end } + }) } -function newspaperExtractor ({ q = '' }) { - const codes = Array.isArray(q) ? q : [q]; - return codes.map(code => newspapersIndex.values[code.trim()] || {}); +async function newspaperExtractor({ q = '' }, app) { + const resolvers = buildResolvers(app) + + const codes = Array.isArray(q) ? q : [q] + return await Promise.all(codes.map(async code => resolvers.newspaper(code.trim()))) } -function topicExtractor ({ q = '' }) { - const items = Array.isArray(q) ? q : [q]; - return items - .map(item => Topic.getCached(item.trim())) - .filter(item => item != null); +async function topicExtractor({ q = '' }, app) { + const resolvers = buildResolvers(app) + const items = Array.isArray(q) ? q : [q] + return await Promise.all(items.map(async item => await resolvers.topic(item.trim()))).filter(item => item != null) } -function entityExtractor ({ q = '' }) { - const items = Array.isArray(q) ? q : [q]; - return items - .map(item => Entity.getCached(item.trim())) - .filter(item => item != null); +async function entityExtractor({ q = '' }, app) { + const resolvers = buildResolvers(app) + const items = Array.isArray(q) ? q : [q] + return await Promise.all( + items.map(async item => { + const uid = item.trim() + const type = Entity.getTypeFromUid(uid) + return type === 'person' ? await resolvers.person(uid) : await resolvers.location(uid) + }) + ).filter(item => item != null) } -function yearExtractor ({ q = '' }) { - const items = Array.isArray(q) ? q : [q]; - return items - .map(item => Year.getCached(item.trim())) - .filter(item => item != null); +async function yearExtractor({ q = '' }, app) { + const resolvers = buildResolvers(app) + + const items = Array.isArray(q) ? q : [q] + return await Promise.all(items.map(async item => resolvers.year(item.trim()))).filter(item => item != null) } -async function collectionExtractor ({ q = '' }, app) { - const items = Array.isArray(q) ? q : [q]; +async function collectionExtractor({ q = '' }, app) { + const items = Array.isArray(q) ? q : [q] try { - return await Promise.all(items.map(async (item) => { - const payload = { query: { nameOnly: true } }; - return app.service('collections').get(item.trim(), payload); - })); + return await Promise.all( + items.map(async item => { + const payload = { query: { nameOnly: true } } + return app.service('collections').get(item.trim(), payload) + }) + ) } catch (error) { - if (error.name === 'NotFound') return []; - throw error; + if (error.name === 'NotFound') return [] + throw error } } -function numberRangeExtractor ({ q = '' }) { - const [start, end] = Array.isArray(q) - ? q - : q.trim().split(' TO '); - return start && end - ? [{ start: parseInt(start, 10), end: parseInt(end, 10) }] - : []; +function numberRangeExtractor({ q = '' }) { + const [start, end] = Array.isArray(q) ? q : q.trim().split(' TO ') + return start && end ? [{ start: parseInt(start, 10), end: parseInt(end, 10) }] : [] } -function simpleValueExtractor ({ q = '' }) { - const items = Array.isArray(q) - ? q - : [q.trim()]; - return items.map(uid => ({ uid })); +function simpleValueExtractor({ q = '' }) { + const items = Array.isArray(q) ? q : [q.trim()] + return items.map(uid => ({ uid })) } module.exports = { @@ -88,4 +88,4 @@ module.exports = { collectionExtractor, numberRangeExtractor, simpleValueExtractor, -}; +} diff --git a/src/services/search/search.extractors.ts b/src/services/search/search.extractors.ts index ce456172..7b525642 100644 --- a/src/services/search/search.extractors.ts +++ b/src/services/search/search.extractors.ts @@ -1,13 +1,9 @@ import { keyBy, isEmpty, assignIn, clone, isUndefined, fromPairs } from 'lodash' import Article from '../../models/articles.model' -import Newspaper from '../../models/newspapers.model' -import Topic from '../../models/topics.model' -import Entity from '../../models/entities.model' -import Year from '../../models/years.model' import { filtersToQueryAndVariables, getRegionCoordinatesFromDocument } from '../../util/solr' import { Service } from '../articles/articles.class' import { ImpressoApplication } from '../../types' -import { optionalMediaSourceToNewspaper } from '../newspapers/newspapers.class' +import { buildResolvers, CachedFacetType, IResolver } from '../../internalServices/cachedResolvers' function getAricleMatchesAndRegions( article: Article | undefined, @@ -81,28 +77,15 @@ export async function getItemsFromSolrResponse( }) } -async function addCachedItems(bucket: { val: any }, provider: (id: string) => any) { - if (isUndefined(provider)) return bucket +async function addCachedItems(bucket: { val: any }, resolver: IResolver, type: CachedFacetType) { + if (isUndefined(resolver)) return bucket return { ...bucket, - item: await provider(bucket.val), + item: await resolver(bucket.val), uid: bucket.val, } } -type CacheProviderType = 'newspaper' | 'topic' | 'person' | 'location' | 'year' - -const getCacheProviders = ( - app: ImpressoApplication -): Record Promise | any> => ({ - newspaper: async (id: string) => - optionalMediaSourceToNewspaper(await app.service('media-sources').getMediaSource(id)), - topic: Topic.getCached, - person: Entity.getCached, - location: Entity.getCached, - year: Year.getCached, -}) - /** * Extract facets from Solr response. * @param {object} response Solr response @@ -114,14 +97,14 @@ export async function getFacetsFromSolrResponse( ) { const { facets = {} } = response - const cacheProviders = getCacheProviders(app) + const resolvers = buildResolvers(app) const facetPairs = await Promise.all( Object.keys(facets).map(async facetLabel => { if (!facets[facetLabel].buckets) return [facetLabel, facets[facetLabel]] - const cacheProvider = cacheProviders[facetLabel as CacheProviderType] + const resolver = resolvers[facetLabel as CachedFacetType] const buckets = await Promise.all( - facets[facetLabel].buckets.map(async (b: any) => addCachedItems(b, cacheProvider)) + facets[facetLabel].buckets.map(async (b: any) => addCachedItems(b, resolver, facetLabel as CachedFacetType)) ) return [facetLabel, assignIn(clone(facets[facetLabel]), { buckets })] diff --git a/src/services/stats/stats.class.ts b/src/services/stats/stats.class.ts index 8a83769c..80f612a6 100644 --- a/src/services/stats/stats.class.ts +++ b/src/services/stats/stats.class.ts @@ -2,12 +2,10 @@ import Debug from 'debug' import { ImpressoApplication } from '../../types' import { Id, Params } from '@feathersjs/feathers' import { SelectRequestBody, SimpleSolrClient } from '../../internalServices/simpleSolr' -import { optionalMediaSourceToNewspaper } from '../newspapers/newspapers.class' +import { buildResolvers } from '../../internalServices/cachedResolvers' const { statsConfiguration } = require('../../data') const { filtersToQueryAndVariables } = require('../../util/solr') const { getWidestInclusiveTimeInterval } = require('../../logic/filters') -const Topic = require('../../models/topics.model') -const Entity = require('../../models/entities.model') const { TimeDomain, StatsToSolrFunction, StatsToSolrStatistics } = require('./common') @@ -24,28 +22,34 @@ const TemporalResolution = Object.freeze({ Day: 'day', }) -const entityCacheExtractor = (key: string) => { - const entity = Entity.getCached(key) - return entity == null ? key : entity.name -} +type FacetLabel = 'topic' | 'newspaper' | 'person' | 'location' | 'language' | 'country' | 'type' +type LabelExtractor = (id: string) => Promise -const FacetLabelCache = Object.freeze({ - topic: async (key: string) => { - const topic = await Topic.getCached(key) - if (topic == null) return key - return topic.words.map(({ w }: any) => w).join(', ') - }, - newspaper: async (key: string, app: ImpressoApplication) => { - const mediaSourcesLookup = await app.service('media-sources').getLookup() - const newspaper = optionalMediaSourceToNewspaper(mediaSourcesLookup[key]) - return newspaper == null ? key : newspaper.name - }, - person: entityCacheExtractor, - location: entityCacheExtractor, - language: (key: string) => key, - country: (key: string) => key, - type: (key: string) => key, -}) +const getFacetLabelCache = (app: ImpressoApplication): Record => { + const resolvers = buildResolvers(app) + return { + topic: async (key: string) => { + const topic = await resolvers.topic(key) + if (topic == null) return key + return topic.words.map(({ w }: any) => w).join(', ') + }, + newspaper: async (key: string) => { + const newspaper = await resolvers.newspaper(key) + return newspaper == null ? key : newspaper.name + }, + person: async (key: string) => { + const entity = await resolvers.person(key) + return entity == null ? key : entity.name + }, + location: async (key: string) => { + const entity = await resolvers.location(key) + return entity == null ? key : entity.name + }, + language: async (key: string) => key, + country: async (key: string) => key, + type: async (key: string) => key, + } +} const getFacetType = (index: string, facet: any) => { const indexFacets = statsConfiguration.indexes[index].facets @@ -132,10 +136,11 @@ const parseDate = (val: any, resolution: any) => { } } -const withLabel = async (val: any, facet: keyof typeof FacetLabelCache, app: ImpressoApplication) => { - const extractor = FacetLabelCache[facet] +const withLabel = async (val: any, facet: FacetLabel, app: ImpressoApplication) => { + const extractors = getFacetLabelCache(app) + const extractor = extractors[facet] return { - label: extractor ? await extractor(val, app) : val, + label: extractor ? await extractor(val) : val, value: val, } } @@ -157,18 +162,20 @@ const parseValue = (object: any, facetType: any) => { } } -async function buildItemsDictionary(items: any, facet: keyof typeof FacetLabelCache, app: ImpressoApplication) { +async function buildItemsDictionary(items: any, facet: FacetLabel, app: ImpressoApplication) { const terms = new Set( items.flatMap(({ value: { items: subitems = [] } }) => subitems).map(({ term }: any) => term) ) - const extractor = FacetLabelCache[facet] + const extractors = getFacetLabelCache(app) + const extractor = extractors[facet] + if (extractor == null) return {} return [...terms].reduce( async (accPromise, term: string) => { const acc = await accPromise - acc[term] = await extractor(term as string, app) + acc[term] = await extractor(term as string) return acc }, {} as Promise> diff --git a/src/services/topics-graph/topics-graph.class.js b/src/services/topics-graph/topics-graph.class.js index 051dc178..d68ab8c1 100644 --- a/src/services/topics-graph/topics-graph.class.js +++ b/src/services/topics-graph/topics-graph.class.js @@ -1,4 +1,5 @@ /* eslint-disable no-unused-vars */ +import { buildResolvers } from '../../internalServices/cachedResolvers' import { asFindAll } from '../../util/solr/adapters' const debug = require('debug')('impresso/services:topics-graph') @@ -43,7 +44,8 @@ class TopicsGraph { async get(id, params) { debug('[get] query:', params.sanitized) - const topic = Topic.getCached(id) + const resolvers = buildResolvers(this.app) + const topic = resolvers.topic(id) if (!topic.uid.length) { throw new NotFound() } @@ -155,6 +157,8 @@ class TopicsGraph { } } + const resolvers = buildResolvers(this.app) + if (!params.sanitized.expand) { restrictToUids = params.sanitized.filters .filter(d => d.type === 'topic' && d.context === 'visualize') @@ -164,13 +168,15 @@ class TopicsGraph { .filter((value, index, self) => self.indexOf(value) === index) debug('[find] n of restrictToUids:', restrictToUids.length) // initial set of nodes - restrictToUids.forEach(d => { - nodesIndex[d] = nodes.length - nodes.push({ - ...toNode(Topic.getCached(d)), - countItems: 0, + await Promise.all( + restrictToUids.map(async d => { + nodesIndex[d] = nodes.length + nodes.push({ + ...toNode(await resolvers.topic(d)), + countItems: 0, + }) }) - }) + ) } const request = { @@ -220,46 +226,50 @@ class TopicsGraph { } } // return solrResponse; - solrResponse.facets.topic.buckets.forEach(d => { - if (restrictToUids.length && !restrictToUids.includes(d.val)) { - return - } - if (typeof nodesIndex[d.val] === 'undefined') { - nodesIndex[d.val] = nodes.length - nodes.push({ - ...toNode(Topic.getCached(d.val)), - countItems: d.count, - }) - // console.log('add', d.val, d.count); - } else { - nodes[nodesIndex[d.val]].countItems = d.count - } - // console.log('index', nodesIndex); - d.topNodes.buckets.forEach(dd => { - if (restrictToUids.length && !restrictToUids.includes(dd.val)) { + await Promise.all( + solrResponse.facets.topic.buckets.map(async d => { + if (restrictToUids.length && !restrictToUids.includes(d.val)) { return } - if (typeof nodesIndex[dd.val] === 'undefined') { - nodesIndex[dd.val] = nodes.length - nodes.push(toNode(Topic.getCached(dd.val))) - } - // add link - if (dd.val !== d.val) { - const linkId = [nodesIndex[d.val], nodesIndex[dd.val]].sort().join('-') - if (typeof linksIndex[linkId] === 'undefined') { - linksIndex[linkId] = links.length - links.push({ - id: linkId, - source: nodesIndex[d.val], - target: nodesIndex[dd.val], - w: dd.count, - }) - nodes[nodesIndex[d.val]].degree += 1 - nodes[nodesIndex[dd.val]].degree += 1 - } + if (typeof nodesIndex[d.val] === 'undefined') { + nodesIndex[d.val] = nodes.length + nodes.push({ + ...toNode(await resolvers.topic(d.val)), + countItems: d.count, + }) + // console.log('add', d.val, d.count); + } else { + nodes[nodesIndex[d.val]].countItems = d.count } + // console.log('index', nodesIndex); + await Promise.all( + d.topNodes.buckets.map(async dd => { + if (restrictToUids.length && !restrictToUids.includes(dd.val)) { + return + } + if (typeof nodesIndex[dd.val] === 'undefined') { + nodesIndex[dd.val] = nodes.length + nodes.push(toNode(await resolvers.topic(dd.val))) + } + // add link + if (dd.val !== d.val) { + const linkId = [nodesIndex[d.val], nodesIndex[dd.val]].sort().join('-') + if (typeof linksIndex[linkId] === 'undefined') { + linksIndex[linkId] = links.length + links.push({ + id: linkId, + source: nodesIndex[d.val], + target: nodesIndex[dd.val], + w: dd.count, + }) + nodes[nodesIndex[d.val]].degree += 1 + nodes[nodesIndex[dd.val]].degree += 1 + } + } + }) + ) }) - }) + ) return { nodes, diff --git a/src/services/topics/topics.class.js b/src/services/topics/topics.class.js index 114f1f85..3aea6924 100644 --- a/src/services/topics/topics.class.js +++ b/src/services/topics/topics.class.js @@ -6,6 +6,7 @@ const SequelizeService = require('../sequelize.service') const Topic = require('../../models/topics.model') const { measureTime } = require('../../util/instruments') const { asFindAll, asGet } = require('../../util/solr/adapters') +const { buildResolvers } = require('../../internalServices/cachedResolvers') class Service { constructor({ app = null, name = '' }) { @@ -14,7 +15,7 @@ class Service { } get solr() { - return this.app.service('simpleSolrService') + return this.app.service('simpleSolrClient') } async find(params) { @@ -58,17 +59,21 @@ class Service { } if (!params.sanitized.filters.length) { + const resolvers = buildResolvers(this.app) + return { total: solrSuggestResponse.response.numFound, - data: solrSuggestResponse.response.docs - .slice(params.query.offset, params.query.offset + params.query.limit) - .map(d => { - const t = Topic.getCached(d.id) - if (solrSuggestResponse.highlighting[t.uid].topic_suggest) { - t.matches = solrSuggestResponse.highlighting[t.uid].topic_suggest - } - return t - }), + data: Promise.all( + solrSuggestResponse.response.docs + .slice(params.query.offset, params.query.offset + params.query.limit) + .map(async d => { + const t = await resolvers.topic(d.id) + if (solrSuggestResponse.highlighting[t.uid].topic_suggest) { + t.matches = solrSuggestResponse.highlighting[t.uid].topic_suggest + } + return t + }) + ), limit: params.query.limit, offset: params.query.offset, info: { @@ -153,15 +158,19 @@ class Service { // get only the portion we need. data = data.slice(params.query.offset, params.query.offset + params.query.limit) } + + const resolvers = buildResolvers(this.app) // remap data - data = data.map(d => { - const topic = Topic.getCached(d.val) - if (uids.length && topics[d.val]) { - topic.matches = topics[d.val].matches - } - topic.countItems = d.count - return topic - }) + data = Promise.all( + data.map(async d => { + const topic = await resolvers.topic(d.val) + if (uids.length && topics[d.val]) { + topic.matches = topics[d.val].matches + } + topic.countItems = d.count + return topic + }) + ) return { total, @@ -176,10 +185,12 @@ class Service { } async get(id, params) { + const resolvers = buildResolvers(this.app) + return measureTime( () => - asGet(this.solr, id, params, Topic.solrFactory).then(topic => { - const cached = Topic.getCached(id) + asGet(this.solr, id, params, Topic.solrFactory).then(async topic => { + const cached = await resolvers.topic(id) topic.countItems = cached.countItems topic.relatedTopics = cached.relatedTopics return topic diff --git a/tsconfig.json b/tsconfig.json index ff3475af..db3530f4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -35,9 +35,9 @@ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ - "paths": { - "@/*": ["./src/*"] - }, + // "paths": { + // "@/*": ["./src/*"] + // }, // "rootDirs": [ // "./src", "./test" // ], /* Allow multiple folders to be treated as one when resolving modules. */