mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 16:42:56 +00:00
refactor: use range query for canteen module
This commit is contained in:
@@ -14,8 +14,16 @@
|
||||
*/
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Client} from '@openstapps/api/lib/client';
|
||||
import {SCSearchRequest, SCSearchResponse, SCThingOriginType, SCThings, SCThingType} from '@openstapps/core';
|
||||
import {
|
||||
SCMultiSearchRequest, SCMultiSearchResponse,
|
||||
SCSearchRequest,
|
||||
SCSearchResponse,
|
||||
SCThingOriginType,
|
||||
SCThings,
|
||||
SCThingType,
|
||||
} from '@openstapps/core';
|
||||
import {SCSaveableThing} from '@openstapps/core';
|
||||
import {chunk, fromPairs, toPairs} from 'lodash-es';
|
||||
import {environment} from '../../../environments/environment';
|
||||
import {StorageProvider} from '../storage/storage.provider';
|
||||
import {StAppsWebHttpClient} from './stapps-web-http-client.provider';
|
||||
@@ -35,6 +43,20 @@ export enum DataScope {
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class DataProvider {
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
get storagePrefix(): string {
|
||||
return this._storagePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
set storagePrefix(storagePrefix) {
|
||||
this._storagePrefix = storagePrefix;
|
||||
}
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
@@ -43,6 +65,10 @@ export class DataProvider {
|
||||
* Version of the app (used for the header in communication with the backend)
|
||||
*/
|
||||
appVersion = environment.backend_version;
|
||||
/**
|
||||
* Maximum number of sub-queries in a multi-query allowed by the backend
|
||||
*/
|
||||
backendQueriesLimit = 5;
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
@@ -144,6 +170,18 @@ export class DataProvider {
|
||||
return this.storageProvider.has(this.getDataKey(uid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs multiple searches at once and returns their responses
|
||||
*
|
||||
* @param query - query to send to the backend (auto-splits according to the backend limit)
|
||||
*/
|
||||
async multiSearch(query: SCMultiSearchRequest): Promise<SCMultiSearchResponse> {
|
||||
// partition object into chunks, process those requests in parallel, then merge their responses again
|
||||
return Object.assign({}, ...(await Promise.all(chunk(toPairs(query), this.backendQueriesLimit)
|
||||
.map((request) => this.client.multiSearch(fromPairs(request))),
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a data item
|
||||
*
|
||||
@@ -174,18 +212,4 @@ export class DataProvider {
|
||||
async search(query: SCSearchRequest): Promise<SCSearchResponse> {
|
||||
return (this.client.search(query));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
get storagePrefix(): string {
|
||||
return this._storagePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
set storagePrefix(storagePrefix) {
|
||||
this._storagePrefix = storagePrefix;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user