refactor: use selectAlias

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/783/head
Varun Patil 2023-08-17 10:48:43 -07:00
parent 4e3ed6fc49
commit 9fe1c02076
3 changed files with 27 additions and 27 deletions

View File

@ -94,14 +94,13 @@ class FaceRecognitionBackend extends Backend
// Add face rect // Add face rect
if (!$aggregate && $this->request->getParam('facerect')) { if (!$aggregate && $this->request->getParam('facerect')) {
$query->addSelect( $query->selectAlias('frf.x', 'face_x')
'frf.x AS face_x', ->selectAlias('frf.y', 'face_y')
'frf.y AS face_y', ->selectAlias('frf.width', 'face_width')
'frf.width AS face_width', ->selectAlias('frf.height', 'face_height')
'frf.height AS face_height', ->selectAlias('m.w', 'image_width')
'm.w AS image_width', ->selectAlias('m.h', 'image_height')
'm.h AS image_height', ;
);
} }
} }

View File

@ -78,16 +78,15 @@ class RecognizeBackend extends Backend
if (!$aggregate) { if (!$aggregate) {
// Multiple detections for the same image // Multiple detections for the same image
$query->addSelect('rfd.id AS faceid'); $query->selectAlias('rfd.id', 'faceid');
// Face Rect // Face Rect
if ($this->request->getParam('facerect')) { if ($this->request->getParam('facerect')) {
$query->addSelect( $query->selectAlias('rfd.width', 'face_w')
'rfd.width AS face_w', ->selectAlias('rfd.height', 'face_h')
'rfd.height AS face_h', ->selectAlias('rfd.x', 'face_x')
'rfd.x AS face_x', ->selectAlias('rfd.y', 'face_y')
'rfd.y AS face_y', ;
);
} }
} }

View File

@ -40,19 +40,18 @@ trait TimelineQueryMap
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
// Get the average location of each cluster // Get the average location of each cluster
$id = $query->createFunction('MAX(c.id) as id'); $query->selectAlias($query->createFunction('MAX(c.id)'), 'id')
$ct = $query->createFunction('COUNT(m.fileid) AS count'); ->selectAlias($query->createFunction('COUNT(m.fileid)'), 'count')
$lat = $query->createFunction('AVG(c.lat) AS lat'); ->selectAlias($query->createFunction('AVG(c.lat)'), 'lat')
$lon = $query->createFunction('AVG(c.lon) AS lon'); ->selectAlias($query->createFunction('AVG(c.lon)'), 'lon')
$query->select($id, $ct, $lat, $lon)
->from('memories_mapclusters', 'c') ->from('memories_mapclusters', 'c')
; ;
// Coarse grouping // Coarse grouping
$gridParam = $query->createNamedParameter($gridLen, IQueryBuilder::PARAM_STR); $gridParam = $query->createNamedParameter($gridLen, IQueryBuilder::PARAM_STR);
$query->addGroupBy($query->createFunction("FLOOR(c.lat / {$gridParam})")); $query->addGroupBy($query->createFunction("FLOOR(c.lat / {$gridParam})"))
$query->addGroupBy($query->createFunction("FLOOR(c.lon / {$gridParam})")); ->addGroupBy($query->createFunction("FLOOR(c.lon / {$gridParam})"))
;
// JOIN with memories for files from the current user // JOIN with memories for files from the current user
$query->innerJoin('c', 'memories', 'm', $query->expr()->eq('c.id', 'm.mapcluster')); $query->innerJoin('c', 'memories', 'm', $query->expr()->eq('c.id', 'm.mapcluster'));
@ -90,10 +89,13 @@ trait TimelineQueryMap
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
// SELECT all photos with this tag // SELECT all photos with this tag
$fileid = $query->createFunction('MAX(m.fileid) AS fileid'); $query->selectAlias($query->createFunction('MAX(m.fileid)'), 'fileid')
$query->select($fileid)->from('memories', 'm')->where( ->from('memories', 'm')
$query->expr()->in('m.mapcluster', $query->createNamedParameter($clusterIds, IQueryBuilder::PARAM_INT_ARRAY)) ->where($query->expr()->in('m.mapcluster', $query->createNamedParameter(
); $clusterIds,
IQueryBuilder::PARAM_INT_ARRAY
)))
;
// WHERE these photos are in the user's requested folder recursively // WHERE these photos are in the user's requested folder recursively
$query = $this->joinFilecache($query); $query = $this->joinFilecache($query);