diff --git a/src/backends/backend.js b/src/backends/backend.js index de36edca5afc..4674a8a90488 100644 --- a/src/backends/backend.js +++ b/src/backends/backend.js @@ -227,6 +227,12 @@ class Backend { // returns all the collected entries. Used to retrieve all entries // for local searches and queries. async listAllEntries(collection) { + if (collection.get("folder") && this.implementation.allEntriesByFolder) { + const extension = selectFolderEntryExtension(collection); + return this.implementation.allEntriesByFolder(collection, extension) + .then(entries => this.processEntries(entries, collection)); + } + const response = await this.listEntries(collection); const { entries } = response; let { cursor } = response; diff --git a/src/backends/gitlab/API.js b/src/backends/gitlab/API.js index c6b384221e92..673150f7e494 100644 --- a/src/backends/gitlab/API.js +++ b/src/backends/gitlab/API.js @@ -150,6 +150,24 @@ export default class API { return { entries, cursor: this.reverseCursor(newCursor) }; }; + listAllEntries = async path => { + const entries = []; + let { cursor, entries: initialEntries } = await this.fetchCursorAndEntries({ + url: `${ this.repoURL }/repository/tree`, + // Get the maximum number of entries per page + params: { path, ref: this.branch, per_page: 100 }, + }); + entries.push(...initialEntries); + while (cursor && cursor.actions.includes("next")) { + const link = cursor.data.links["next"]; + const { cursor: newCursor, entries: newEntries } = await this.fetchCursorAndEntries(link); + entries.push(...newEntries); + cursor = newCursor; + console.log({ cursor, entries }); + } + return entries; + }; + toBase64 = str => Promise.resolve(Base64.encode(str)); fromBase64 = str => Base64.decode(str); uploadAndCommit = async (item, { commitMessage, updateFile = false, branch = this.branch }) => { diff --git a/src/backends/gitlab/implementation.js b/src/backends/gitlab/implementation.js index a4f663d26f34..779ee733eb39 100644 --- a/src/backends/gitlab/implementation.js +++ b/src/backends/gitlab/implementation.js @@ -68,6 +68,11 @@ export default class GitLab { ); } + allEntriesByFolder(collection, extension) { + return this.api.listAllEntries(collection.get("folder"), extension) + .then(files => this.fetchFiles(files.filter(file => fileExtension(file.name) === extension))); + } + entriesByFiles(collection) { const files = collection.get("files").map(collectionFile => ({ path: collectionFile.get("file"),