Skip to content

Commit 6a54458

Browse files
committed
GitLab: reduce batch size and remove size retrieval
Follow up #525
1 parent 2f0ef15 commit 6a54458

3 files changed

Lines changed: 167 additions & 69 deletions

File tree

src/lib/components/assets/shared/info-panel.svelte

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
/** @type {AssetDetails} */
4343
let details = $state({ ...defaultAssetDetails });
4444
45+
// @todo Fetch file size and commit info on demand for GitLab
4546
const { path, size, kind, commitAuthor, commitDate } = $derived(asset);
4647
const { publicURL, repoBlobURL, dimensions, duration, createdDate, coordinates, usedEntries } =
4748
$derived(details);
@@ -99,14 +100,16 @@
99100
})}
100101
</p>
101102
</section>
102-
<section>
103-
<h4>{$_('size')}</h4>
104-
<p>
105-
{#key $appLocale}
106-
{formatSize(size)}
107-
{/key}
108-
</p>
109-
</section>
103+
{#if !!size}
104+
<section>
105+
<h4>{$_('size')}</h4>
106+
<p>
107+
{#key $appLocale}
108+
{formatSize(size)}
109+
{/key}
110+
</p>
111+
</section>
112+
{/if}
110113
{#if canPreview}
111114
<section>
112115
<h4>{$_('dimensions')}</h4>

src/lib/services/backends/git/gitlab/files.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,24 @@ export const fetchBlobs = async (paths, query) => {
160160
return {};
161161
}
162162

163+
const { isSelfHosted = false } = repository;
164+
const batchSize = isSelfHosted ? 20 : 100;
163165
const fetchingPaths = [...paths];
164166
/** @type {BlobItem[]} */
165167
const blobs = [];
166168

167169
// Fetch all the text contents with the GraphQL API. Pagination would fail if `paths` becomes too
168170
// long, so we just use a fixed number of paths to iterate. The complexity score of this query is
169-
// 15 + (2 * node size) so 50 paths = 115 complexity, giving the following conditions:
171+
// 15 + (2 * node size) so 100 paths = 215 complexity, giving the following conditions:
170172
// 1. The max number of records is 100
171173
// 2. The max query complexity is 250 or 300
172174
// 3. The total blob size must be under 20 MB (since GitLab 18.4.5)
173175
// @see https://github.com/sveltia/sveltia-cms/issues/525
174176
// @see https://gitlab.com/gitlab-org/gitlab/-/issues/576497
177+
// The batch size is reduced to 20 for self-hosted instances because they typically run on less
178+
// powerful hardware, which may lead to timeout issues.
175179
for (;;) {
176-
const currentPaths = fetchingPaths.splice(0, 50);
180+
const currentPaths = fetchingPaths.splice(0, batchSize);
177181

178182
const result = /** @type {FetchBlobsResponse} */ (
179183
await fetchGraphQL(query, { paths: currentPaths })
@@ -258,12 +262,12 @@ export const fetchCommits = async (paths) => {
258262
* Parse the file contents from the API response.
259263
* @param {object} args Arguments.
260264
* @param {BaseFileListItem[]} args.fetchingFiles Base file list.
261-
* @param {Record<string, BlobItem>} args.sizes File sizes.
262265
* @param {Record<string, BlobItem>} args.blobs Raw text blobs.
266+
* @param {Record<string, BlobItem>} [args.sizes] File sizes.
263267
* @param {Record<string, GitLabCommit>} [args.commits] Commit information for each file.
264268
* @returns {Promise<RepositoryContentsMap>} Parsed file contents map.
265269
*/
266-
export const parseFileContents = async ({ fetchingFiles, sizes, blobs, commits = {} }) => {
270+
export const parseFileContents = async ({ fetchingFiles, blobs, sizes = {}, commits = {} }) => {
267271
const entries = fetchingFiles.map(({ path, sha }) => {
268272
const commit = commits[path];
269273

@@ -307,19 +311,16 @@ export const fetchFileContents = async (fetchingFiles) => {
307311
// Show a fake progressbar because the request waiting time is long
308312
const dataLoadedProgressInterval = window.setInterval(() => {
309313
dataLoadedProgress.update((progress = 0) => progress + 1);
310-
}, fetchingFiles.length / 2);
314+
}, fetchingFiles.length / 10);
311315

312316
// Fetch blobs for entry/config files only
313317
const textPaths = fetchingFiles.filter(({ type }) => type !== 'asset').map(({ path }) => path);
314318
const blobs = await fetchBlobs(textPaths, FETCH_BLOBS_QUERY);
315-
// Fetch sizes for asset files only
316-
const assetPaths = fetchingFiles.filter(({ type }) => type === 'asset').map(({ path }) => path);
317-
const sizes = await fetchBlobs(assetPaths, FETCH_BLOBS_QUERY.replace('rawTextBlob', 'size'));
318319

319320
window.clearInterval(dataLoadedProgressInterval);
320321
dataLoadedProgress.set(undefined);
321322

322-
return parseFileContents({ fetchingFiles, sizes, blobs });
323+
return parseFileContents({ fetchingFiles, blobs });
323324
};
324325

325326
/**

0 commit comments

Comments
 (0)