Skip to content

Commit

Permalink
limit file list results to 1000 items (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
purplecabbage authored Jun 25, 2024
1 parent bd873f3 commit fede885
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
7 changes: 3 additions & 4 deletions lib/impl/AzureBlobFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,9 @@ class AzureBlobFiles extends Files {
async _listFolder (filePath) {
const __listFolder = async (_filePath, /** @type {AzureProps} */azureProps) => {
const elements = []
const prefix = _filePath
// listBlobsFlat is using the '/' delimiter by default
// error handling (wrap)?
for await (const item of azureProps.containerClient.listBlobsFlat({ prefix })) {
const iterator = azureProps.containerClient.listBlobsFlat({ prefix: _filePath }).byPage({ maxPageSize: 1000 })
const response = (await iterator.next()).value
for (const item of response.segment.blobItems) {
elements.push({
name: item.name,
creationTime: item.properties.createdOn,
Expand Down
34 changes: 23 additions & 11 deletions test/impl/AzureBlobFiles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,19 @@ describe('_listFolder', () => {
azure.ContainerClient.mockImplementation(url => {
const containerMockList = url.includes('public') ? mockContainerPublicList : mockContainerPrivateList
return {
listBlobsFlat: containerMockList,
listBlobsFlat: () => {
return {
byPage: () => {
return {
next: () => {
return {
value: containerMockList()
}
}
}
}
}
},
getBlockBlobClient: () => ({
url: 'some/url?asdklk'
})
Expand All @@ -308,8 +320,16 @@ describe('_listFolder', () => {
async function testListFolder (filePath, listsPublic, listsPrivate, isRoot) {
const publicFiles = fakeFiles.map(f => publicDir + f)
const privateFiles = fakeFiles2.map(f => privateDir + f)
mockContainerPublicList.mockReturnValue(fakeAzureListResponse(publicFiles))
mockContainerPrivateList.mockReturnValue(fakeAzureListResponse(privateFiles))
mockContainerPublicList.mockReturnValue({
segment: {
blobItems: fakeAzureListResponse(publicFiles)
}
})
mockContainerPrivateList.mockReturnValue({
segment: {
blobItems: fakeAzureListResponse(privateFiles)
}
})

const fileList = await files._listFolder(filePath)
expect(fileList).toStrictEqual(expect.arrayContaining([expect.objectContaining({ name: expect.any(String) })]))
Expand All @@ -318,14 +338,6 @@ describe('_listFolder', () => {

expect(mockContainerPublicList).toHaveBeenCalledTimes(listsPublic ? 1 : 0)
expect(mockContainerPrivateList).toHaveBeenCalledTimes(listsPrivate ? 1 : 0)

if (listsPublic) {
expect(mockContainerPublicList).toHaveBeenCalledWith({ prefix: isRoot ? 'public' : filePath })
}

if (listsPrivate) {
expect(mockContainerPrivateList).toHaveBeenCalledWith({ prefix: filePath })
}
}

test('when it is the root (empty string)', async () => {
Expand Down

0 comments on commit fede885

Please sign in to comment.