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[],
metadataCacheUri: string
) {
const metadataCache = new MetadataCache(metadataCacheUri, Logger)
const result: DDO[] = []
const searchDids = JSON.stringify(bookmarks)
.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 ddo = bookmark && (await metadataCache.retrieveDDO(bookmark))
ddo && result.push(ddo)
const queryBookmarks = {
page: 1,
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)
}
}
const columns = [
@ -84,7 +104,7 @@ export default function Bookmarks(): ReactElement {
bookmarks[networkName],
config.metadataCacheUri
)
setPinned(resultPinned)
setPinned(resultPinned.results)
} catch (error) {
Logger.error(error.message)
}