diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 7d07c6e03..501ca5985 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -1283,14 +1283,8 @@ public function getSubmissions(int $formId, ?string $query = null, ?int $limit = // TRANSLATORS On Results when listing the single Responses to the form, this text is shown as heading of the Response. $submission['userDisplayName'] = $this->l10n->t('Anonymous response'); } else { - $userEntity = $this->userManager->get($submission['userId']); - - if ($userEntity instanceof IUser) { - $submission['userDisplayName'] = $userEntity->getDisplayName(); - } else { - // Fallback, should not occur regularly. - $submission['userDisplayName'] = $submission['userId']; - } + // Fallback to the userId, should not occur regularly. + $submission['userDisplayName'] = $this->userManager->getDisplayName($submission['userId']) ?? $submission['userId']; } return $submission; }, $submissions); @@ -1352,14 +1346,8 @@ public function getSubmission(int $formId, int $submissionId): DataResponse|Data // TRANSLATORS On Results when listing the single Responses to the form, this text is shown as heading of the Response. $submission['userDisplayName'] = $this->l10n->t('Anonymous response'); } else { - $userEntity = $this->userManager->get($submission['userId']); - - if ($userEntity instanceof IUser) { - $submission['userDisplayName'] = $userEntity->getDisplayName(); - } else { - // Fallback, should not occur regularly. - $submission['userDisplayName'] = $submission['userId']; - } + // Fallback to the userId, should not occur regularly. + $submission['userDisplayName'] = $this->userManager->getDisplayName($submission['userId']) ?? $submission['userId']; } return new DataResponse($submission); diff --git a/lib/Db/AnswerMapper.php b/lib/Db/AnswerMapper.php index 2420f6b34..6df740745 100644 --- a/lib/Db/AnswerMapper.php +++ b/lib/Db/AnswerMapper.php @@ -15,6 +15,7 @@ * @extends QBMapper */ class AnswerMapper extends QBMapper { + private const CHUNK_SIZE = 1000; /** * AnswerMapper constructor. @@ -41,6 +42,28 @@ public function findBySubmission(int $submissionId): array { return $this->findEntities($qb); } + /** + * @param list $submissionIds + * @return Answer[] + */ + public function findBySubmissions(array $submissionIds): array { + $answers = []; + + foreach (array_chunk(array_unique($submissionIds), self::CHUNK_SIZE) as $submissionIdsChunk) { + $qb = $this->db->getQueryBuilder(); + + $qb->select('*') + ->from($this->getTableName()) + ->where( + $qb->expr()->in('submission_id', $qb->createNamedParameter($submissionIdsChunk, IQueryBuilder::PARAM_INT_ARRAY)) + ); + + $answers[] = $this->findEntities($qb); + } + + return array_merge([], ...$answers); + } + /** * @param int $submissionId */ diff --git a/lib/Db/OptionMapper.php b/lib/Db/OptionMapper.php index 2e0140dbe..ad4b4f6fb 100644 --- a/lib/Db/OptionMapper.php +++ b/lib/Db/OptionMapper.php @@ -10,12 +10,14 @@ namespace OCA\Forms\Db; use OCP\AppFramework\Db\QBMapper; +use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; /** * @extends QBMapper