1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

optimize Bookmarks query (#259)

This commit is contained in:
Matthias Kretschmann 2020-11-17 14:52:10 +01:00 committed by GitHub
parent 225613745c
commit 476d13f009
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,15 +12,35 @@ async function getAssetsBookmarked(
bookmarks: string[], bookmarks: string[],
metadataCacheUri: string metadataCacheUri: string
) { ) {
const metadataCache = new MetadataCache(metadataCacheUri, Logger) const searchDids = JSON.stringify(bookmarks)
const result: DDO[] = [] .replace(/,/g, ' ')
.replace(/"/g, '')
.replace(/(\[|\])/g, '')
// for whatever reason ddo.id is not searchable, so use ddo.dataToken instead
.replace(/(did:op:)/g, '0x')
for (const bookmark of bookmarks) { const queryBookmarks = {
const ddo = bookmark && (await metadataCache.retrieveDDO(bookmark)) page: 1,
ddo && result.push(ddo) offset: 100,
query: {
nativeSearch: 1,
query_string: {
query: searchDids,
fields: ['dataToken'],
default_operator: 'OR'
}
},
sort: { created: -1 }
} as any
try {
const metadataCache = new MetadataCache(metadataCacheUri, Logger)
const result = await metadataCache.queryMetadata(queryBookmarks)
return result
} catch (error) {
Logger.error(error.message)
} }
return result
} }
const columns = [ const columns = [
@ -84,7 +104,7 @@ export default function Bookmarks(): ReactElement {
bookmarks[networkName], bookmarks[networkName],
config.metadataCacheUri config.metadataCacheUri
) )
setPinned(resultPinned) setPinned(resultPinned.results)
} catch (error) { } catch (error) {
Logger.error(error.message) Logger.error(error.message)
} }