Use single query for day preload

old-stable24
Varun Patil 2022-10-26 11:10:24 -07:00
parent d9a4f9e090
commit 9ddab71370
1 changed files with 24 additions and 6 deletions

View File

@ -669,20 +669,38 @@ class ApiController extends Controller
$uid = $this->userSession->getUser()->getUID(); $uid = $this->userSession->getUser()->getUID();
$transforms = $this->getTransformations(false); $transforms = $this->getTransformations(false);
$preloaded = 0; $preloaded = 0;
$preloadDayIds = [];
$preloadDays = [];
foreach ($days as &$day) { foreach ($days as &$day) {
$day['detail'] = $this->timelineQuery->getDay( $preloaded += $day['count'];
$preloadDayIds[] = $day['dayid'];
$preloadDays[] = &$day;
if ($preloaded >= 50) { // should be enough
break;
}
}
if (\count($preloadDayIds) > 0) {
$allDetails = $this->timelineQuery->getDay(
$folder, $folder,
$uid, $uid,
[$day['dayid']], $preloadDayIds,
$recursive, $recursive,
$archive, $archive,
$transforms, $transforms,
); );
$day['count'] = \count($day['detail']); // make sure count is accurate
$preloaded += $day['count'];
if ($preloaded >= 50) { // should be enough // Group into dayid
break; $detailMap = [];
foreach ($allDetails as &$detail) {
$detailMap[$detail['dayid']][] = &$detail;
}
foreach ($preloadDays as &$day) {
$m = $detailMap[$day['dayid']];
if (isset($m) && null !== $m && \count($m) > 0) {
$day['detail'] = $m;
}
} }
} }
} }