Skip to content

Commit 653484b

Browse files
committed
fix(pat contentbrowser): Use POST request for quering selected items in order to not get too long URIs when there are many items present.
1 parent 2b64636 commit 653484b

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/pat/contentbrowser/src/ContentStore.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import logger from "@patternslib/patternslib/src/core/logging";
12
import { writable, get } from "svelte/store";
23
import { request } from "./utils.js";
34

5+
const log = logger.getLogger("pat-contentbrowser");
6+
47
export default function (config, pathCache) {
58
const store = writable([]);
69

@@ -22,7 +25,8 @@ export default function (config, pathCache) {
2225
try {
2326
return await request(query);
2427
}
25-
catch {
28+
catch (e) {
29+
log.debug(`Could not load data from backend. ${e}`);
2630
return {
2731
"error": "Could load data from backend."
2832
};

src/pat/contentbrowser/src/utils.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,27 +104,39 @@ export async function request({
104104
};
105105
const url_query = JSON.stringify(vocabQuery);
106106
const url_parameters = JSON.stringify(attributes);
107-
const url_batch = JSON.stringify({
107+
const url_batch = pageSize ? JSON.stringify({
108108
page: page,
109109
size: pageSize,
110-
});
110+
}) : "";
111111

112-
const url = encodeURI(`${vocabularyUrl}${vocabularyUrl.indexOf("?") !== -1 ? "&" : "?"}query=${url_query}&attributes=${url_parameters}&batch=${url_batch}`);
113-
log.debug(url);
112+
let url = encodeURI(`${vocabularyUrl}${vocabularyUrl.indexOf("?") !== -1 ? "&" : "?"}query=${url_query}&attributes=${url_parameters}` + (url_batch ? `&batch=${url_batch}` : ""));
114113

115114
const headers = new Headers();
116115
headers.set("Accept", "application/json");
117116

118-
const response = await fetch(url, {
117+
let request_params = {
119118
method: method,
120119
headers: headers,
121-
});
120+
};
121+
122+
if (method == "POST" && url.indexOf("?") !== -1) {
123+
const url_parts = url.split("?");
124+
url = url_parts[0];
125+
const post_data = url_parts[1];
126+
headers.set("Content-Type", "application/x-www-form-urlencoded");
127+
128+
log.debug(url, post_data);
129+
130+
request_params['body'] = post_data;
131+
}
132+
133+
const response = await fetch(url, request_params);
122134

123135
if (!response.ok) {
124136
return {
125137
results: [],
126138
total: 0,
127-
errors: json.errors,
139+
errors: response.errors,
128140
};
129141
}
130142

@@ -153,9 +165,13 @@ export async function get_items_from_uids(uids, config) {
153165
return [];
154166
}
155167
const selectedItemsFromUids = await request({
168+
// use POST request (when many selected items are present the URL might get too long)
169+
method: "POST",
156170
vocabularyUrl: config.vocabularyUrl,
157171
attributes: config.attributes,
158172
uids: uids,
173+
// do not batch here, otherwise we do not get all items
174+
pageSize: null,
159175
});
160176
let results = (await selectedItemsFromUids?.results) || [];
161177
// resort the results based on the order of uids

0 commit comments

Comments
 (0)