Skip to content
Draft
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
33 changes: 21 additions & 12 deletions lib/private/Files/Cache/FileAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,16 @@ private function rowsToEntries(array $rows): array {
*/
#[\Override]
public function getByFileIds(array $fileIds): array {
$query = $this->getQuery()->selectFileCache();
$query->andWhere($query->expr()->in('filecache.fileid', $query->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY)));

$rows = $query->executeQuery()->fetchAll();
return $this->rowsToEntries($rows);
if (empty($fileIds)) {
return [];
}
$result = [];
foreach (array_chunk($fileIds, 1000) as $chunk) {
$query = $this->getQuery()->selectFileCache();
$query->andWhere($query->expr()->in('filecache.fileid', $query->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
$result += $this->rowsToEntries($query->executeQuery()->fetchAll());
}
return $result;
}

/**
Expand All @@ -95,13 +100,17 @@ public function getByFileIds(array $fileIds): array {
*/
#[\Override]
public function getByFileIdsInStorage(array $fileIds, int $storageId): array {
$fileIds = array_values($fileIds);
$query = $this->getQuery()->selectFileCache();
$query->andWhere($query->expr()->in('filecache.fileid', $query->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY)));
$query->andWhere($query->expr()->eq('filecache.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));

$rows = $query->executeQuery()->fetchAll();
return $this->rowsToEntries($rows);
if (empty($fileIds)) {
return [];
}
$result = [];
foreach (array_chunk(array_values($fileIds), 1000) as $chunk) {
$query = $this->getQuery()->selectFileCache();
$query->andWhere($query->expr()->in('filecache.fileid', $query->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
$query->andWhere($query->expr()->eq('filecache.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
$result += $this->rowsToEntries($query->executeQuery()->fetchAll());
}
return $result;
}

#[\Override]
Expand Down
7 changes: 1 addition & 6 deletions lib/private/Files/SetupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,7 @@ public function setupForPath(string $path, bool $includeChildren = false): void
array_merge(...array_values($authoritativeCachedMounts)),
);

$rootsMetadata = [];
foreach (array_chunk($rootIds, 1000) as $chunk) {
foreach ($this->fileAccess->getByFileIds($chunk) as $id => $fileMetadata) {
$rootsMetadata[$id] = $fileMetadata;
}
}
$rootsMetadata = $this->fileAccess->getByFileIds($rootIds);
$this->setupMountProviderPaths[$mountPoint] = self::SETUP_WITH_CHILDREN;
foreach ($authoritativeCachedMounts as $providerClass => $cachedMounts) {
$providerArgs = array_values(array_filter(array_map(
Expand Down
65 changes: 65 additions & 0 deletions tests/lib/Files/Cache/FileAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,71 @@ private function setUpTestDatabaseForGetByAncestorInStorage(): void {
->executeStatement();
}

public function testGetByFileIds(): void {
$result = $this->fileAccess->getByFileIds([1, 2, 3]);

$this->assertCount(3, $result);
$this->assertArrayHasKey(1, $result);
$this->assertArrayHasKey(2, $result);
$this->assertArrayHasKey(3, $result);
}

public function testGetByFileIdsWithEmptyArray(): void {
$result = $this->fileAccess->getByFileIds([]);
$this->assertCount(0, $result);
}

public function testGetByFileIdsWithNonExistentIds(): void {
$result = $this->fileAccess->getByFileIds([9998, 9999]);
$this->assertCount(0, $result);
}

public function testGetByFileIdsSpanningChunkBoundary(): void {
// 1001 IDs exceeds Oracle's 1000-element IN limit — verifies chunked queries return correct results
$ids = range(1, 1001);
$result = $this->fileAccess->getByFileIds($ids);

// Only fileids 1–7 exist in the test data
$this->assertCount(7, $result);
foreach (range(1, 7) as $id) {
$this->assertArrayHasKey($id, $result);
}
}

public function testGetByFileIdsInStorage(): void {
$result = $this->fileAccess->getByFileIdsInStorage([1, 2, 3], 1);

$this->assertCount(3, $result);
$this->assertArrayHasKey(1, $result);
$this->assertArrayHasKey(2, $result);
$this->assertArrayHasKey(3, $result);
}

public function testGetByFileIdsInStorageFiltersStorage(): void {
// fileids 6 and 7 belong to storage 2, not storage 1
$result = $this->fileAccess->getByFileIdsInStorage([1, 6, 7], 1);

$this->assertCount(1, $result);
$this->assertArrayHasKey(1, $result);
}

public function testGetByFileIdsInStorageWithEmptyArray(): void {
$result = $this->fileAccess->getByFileIdsInStorage([], 1);
$this->assertCount(0, $result);
}

public function testGetByFileIdsInStorageSpanningChunkBoundary(): void {
// 1001 IDs exceeds Oracle's 1000-element IN limit — verifies chunked queries return correct results
$ids = range(1, 1001);
$result = $this->fileAccess->getByFileIdsInStorage($ids, 1);

// fileids 1–5 are in storage 1; 6 and 7 are in storage 2
$this->assertCount(5, $result);
foreach (range(1, 5) as $id) {
$this->assertArrayHasKey($id, $result);
}
}

/**
* Test fetching files by ancestor in storage.
*/
Expand Down
Loading