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:
parent
225613745c
commit
476d13f009
@ -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
|
return result
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error(error.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user