single-item: fix post-processing (fix #470)

Signed-off-by: Varun Patil <varunpatil@ucla.edu>
pull/563/head
Varun Patil 2023-03-25 07:58:03 -07:00
parent 81708a4de7
commit dae5785462
4 changed files with 45 additions and 36 deletions

View File

@ -215,10 +215,8 @@ class PublicController extends AuthPublicShareController
} }
/** Get initial state of single item */ /** Get initial state of single item */
private function getSingleItemInitialState(\OCP\Files\File $file): string private function getSingleItemInitialState(\OCP\Files\File $file): array
{ {
$photo = $this->timelineQuery->getSingleItem($file->getId()); return $this->timelineQuery->getSingleItem($file->getId());
return json_encode($photo);
} }
} }

View File

@ -168,11 +168,15 @@ trait TimelineQueryDays
// Apply all transformations // Apply all transformations
$this->applyAllTransforms($queryTransforms, $query, false); $this->applyAllTransforms($queryTransforms, $query, false);
$cursor = $this->executeQueryWithCTEs($query); // FETCH all photos in this day
$rows = $cursor->fetchAll(); $day = $this->executeQueryWithCTEs($query)->fetchAll();
$cursor->closeCursor();
return $this->processDay($rows); // Post process the day in-place
foreach ($day as &$photo) {
$this->processDayPhoto($photo);
}
return $day;
} }
public function executeQueryWithCTEs(IQueryBuilder $query, string $psql = '') public function executeQueryWithCTEs(IQueryBuilder $query, string $psql = '')
@ -253,9 +257,8 @@ trait TimelineQueryDays
/** /**
* Process the single day response. * Process the single day response.
*/ */
private function processDay(array $day) private function processDayPhoto(array &$row)
{ {
foreach ($day as &$row) {
// Convert field types // Convert field types
$row['fileid'] = (int) $row['fileid']; $row['fileid'] = (int) $row['fileid'];
$row['isvideo'] = (int) $row['isvideo']; $row['isvideo'] = (int) $row['isvideo'];
@ -281,9 +284,6 @@ trait TimelineQueryDays
unset($row['datetaken']); unset($row['datetaken']);
} }
return $day;
}
/** /**
* Get all folders inside a top folder. * Get all folders inside a top folder.
*/ */

View File

@ -25,7 +25,13 @@ trait TimelineQuerySingleItem
// JOIN with mimetypes to get the mimetype // JOIN with mimetypes to get the mimetype
$query->join('f', 'mimetypes', 'mimetypes', $query->expr()->eq('f.mimetype', 'mimetypes.id')); $query->join('f', 'mimetypes', 'mimetypes', $query->expr()->eq('f.mimetype', 'mimetypes.id'));
return $query->executeQuery()->fetch(); // FETCH the photo
$photo = $query->executeQuery()->fetch();
// Post process the record
$this->processDayPhoto($photo);
return $photo;
} }
public function getInfoById(int $id, bool $basic): array public function getInfoById(int $id, bool $basic): array

View File

@ -1,7 +1,12 @@
import { IDay } from "../../types"; import { IDay } from "../../types";
import { loadState } from "@nextcloud/initial-state"; import { loadState } from "@nextcloud/initial-state";
const singleItem = JSON.parse(loadState("memories", "single_item", "{}")); let singleItem = null;
try {
singleItem = loadState("memories", "single_item", {});
} catch (e) {
console.error("Could not load single item", e);
}
export function isSingleItem(): boolean { export function isSingleItem(): boolean {
return Boolean(singleItem?.fileid); return Boolean(singleItem?.fileid);