Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable25] Add chunking in SystemTagObjectMapper::getTagIdsForObjects #37216

Merged
merged 1 commit into from
Mar 14, 2023
Merged
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
16 changes: 9 additions & 7 deletions lib/private/SystemTag/SystemTagObjectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,25 @@ public function getTagIdsForObjects($objIds, string $objectType): array {
->from(self::RELATION_TABLE)
->where($query->expr()->in('objectid', $query->createParameter('objectids')))
->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype')))
->setParameter('objectids', $objIds, IQueryBuilder::PARAM_STR_ARRAY)
->setParameter('objecttype', $objectType)
->addOrderBy('objectid', 'ASC')
->addOrderBy('systemtagid', 'ASC');

$chunks = array_chunk($objIds, 900, false);
$mapping = [];
foreach ($objIds as $objId) {
$mapping[$objId] = [];
}
foreach ($chunks as $chunk) {
$query->setParameter('objectids', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
$result = $query->executeQuery();
while ($row = $result->fetch()) {
$objectId = $row['objectid'];
$mapping[$objectId][] = $row['systemtagid'];
}

$result = $query->execute();
while ($row = $result->fetch()) {
$objectId = $row['objectid'];
$mapping[$objectId][] = $row['systemtagid'];
$result->closeCursor();
}

$result->closeCursor();

return $mapping;
}
Expand Down
21 changes: 16 additions & 5 deletions tests/lib/SystemTag/SystemTagObjectMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ public function testGetTagIdsForNoObjects() {
$this->assertEquals([], $tagIdMapping);
}

public function testGetTagIdsForALotOfObjects() {
$ids = range(1, 10500);
$tagIdMapping = $this->tagMapper->getTagIdsForObjects(
$ids,
'testtype'
);

$this->assertEquals(10500, count($tagIdMapping));
$this->assertEquals([$this->tag1->getId(), $this->tag2->getId()], $tagIdMapping[1]);
}

public function testGetObjectsForTags() {
$objectIds = $this->tagMapper->getObjectIdsForTags(
[$this->tag1->getId(), $this->tag2->getId(), $this->tag3->getId()],
Expand All @@ -166,7 +177,7 @@ public function testGetObjectsForTagsLimit() {
], $objectIds);
}


public function testGetObjectsForTagsLimitWithMultipleTags() {
$this->expectException(\InvalidArgumentException::class);

Expand All @@ -190,7 +201,7 @@ public function testGetObjectsForTagsLimitOffset() {
], $objectIds);
}


public function testGetObjectsForNonExistingTag() {
$this->expectException(\OCP\SystemTag\TagNotFoundException::class);

Expand Down Expand Up @@ -228,7 +239,7 @@ public function testReAssignUnassignTags() {
$this->assertTrue(true, 'No error when reassigning/unassigning');
}


public function testAssignNonExistingTags() {
$this->expectException(\OCP\SystemTag\TagNotFoundException::class);

Expand All @@ -255,7 +266,7 @@ public function testAssignNonExistingTagInArray() {
], $tagIdMapping, 'None of the tags got assigned');
}


public function testUnassignNonExistingTags() {
$this->expectException(\OCP\SystemTag\TagNotFoundException::class);

Expand Down Expand Up @@ -386,7 +397,7 @@ public function testHaveTagAtLeastOneMatch() {
);
}


public function testHaveTagNonExisting() {
$this->expectException(\OCP\SystemTag\TagNotFoundException::class);

Expand Down