Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix gravsearch results infinite loading (DEV-1541) #480

Merged
merged 1 commit into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/api/v2/search/search-endpoint-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export class SearchEndpointV2 extends Endpoint {
*/
doExtendedSearch(gravsearchQuery: string): Observable<ReadResourceSequence | ApiResponseError> {
// TODO: Do not hard-code the URL and http call params, generate this from Knora

// TODO: check if content-type have to be set to text/plain

return this.httpPost("/searchextended", gravsearchQuery, "sparql").pipe(
Expand Down
41 changes: 25 additions & 16 deletions src/models/v2/resources/ResourcesConversionUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,40 @@ import { ResourceClassAndPropertyDefinitions } from "../../../cache/ontology-cac
export namespace ResourcesConversionUtil {

/**
* Given a JSON-LD representing zero, one more resources, converts it to an array of ReadResource.
* Given a JSON-LD representing zero, one or more resources, converts it to an array of ReadResource.
*
* JSON-LD is expected to have expanded prefixes (processed by jsonld processor).
*
* @param resourcesJsonld a JSON-LD object with expanded prefixes representing zero, one or more resources.
* @param resourcesJsonld a JSON-LD object with expanded prefixes representing zero, one or more resources.
* @param ontologyCache instance of OntologyCache to be used.
* @param listNodeCache instance of ListNodeCache to be used.
* @param jsonConvert instance of JsonConvert to be used.
*/
export const createReadResourceSequence = (resourcesJsonld: object, ontologyCache: OntologyCache, listNodeCache: ListNodeV2Cache, jsonConvert: JsonConvert): Observable<ReadResourceSequence> => {

if (resourcesJsonld.hasOwnProperty("@graph")) {
// sequence of resources
return forkJoin((resourcesJsonld as { [index: string]: object[] })["@graph"]
.map((res: { [index: string]: object[] | string }) => createReadResource(res, ontologyCache, listNodeCache, jsonConvert))).pipe(
map((resources: ReadResource[]) => {
// check for mayHaveMoreResults
if (resourcesJsonld.hasOwnProperty(Constants.MayHaveMoreResults)) {
// presence of knora-api:mayHaveMoreResults implicitly means true
return new ReadResourceSequence(resources, true);
} else {
return new ReadResourceSequence(resources);
}
})
);
let graphLength: number = (resourcesJsonld as { [index: string]: object[] })["@graph"].length

if (graphLength > 0) {
// sequence of resources
return forkJoin((resourcesJsonld as { [index: string]: object[] })["@graph"]
.map((res: { [index: string]: object[] | string }) => createReadResource(res, ontologyCache, listNodeCache, jsonConvert))).pipe(
map((resources: ReadResource[]) => {
// check for mayHaveMoreResults
if (resourcesJsonld.hasOwnProperty(Constants.MayHaveMoreResults)) {
// presence of knora-api:mayHaveMoreResults implicitly means true
return new ReadResourceSequence(resources, true);
} else {
return new ReadResourceSequence(resources);
}
})
);
} else {
if (resourcesJsonld.hasOwnProperty(Constants.MayHaveMoreResults)) {
return of(new ReadResourceSequence([], true));
} else {
return of(new ReadResourceSequence([]));
}
}
} else {
// one or no resource
if (Object.keys(resourcesJsonld).length === 0) {
Expand Down
4 changes: 1 addition & 3 deletions src/models/v2/resources/read/read-resource-sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ export class ReadResourceSequence {
* @param resources sequence of resources.
* @param mayHaveMoreResults flag whether there are more results to be fetched, i.e. for search results.
*/
constructor(readonly resources: ReadResource[], readonly mayHaveMoreResults = false) {
}

constructor(readonly resources: ReadResource[], readonly mayHaveMoreResults = false) { }
}