Use name for face fetching

cache
Varun Patil 2022-10-07 23:26:09 -07:00
parent bfee339bc9
commit 6fcb3ba457
7 changed files with 29 additions and 13 deletions

View File

@ -87,9 +87,9 @@ class ApiController extends Controller {
// Filter only for one face
if ($this->recognizeIsEnabled()) {
$faceId = $this->request->getParam('face');
if ($faceId) {
$transforms[] = array($this->timelineQuery, 'transformFaceFilter', intval($faceId));
$face = $this->request->getParam('face');
if ($face) {
$transforms[] = array($this->timelineQuery, 'transformFaceFilter', $face);
}
}

View File

@ -10,10 +10,25 @@ use OCP\Files\Folder;
trait TimelineQueryFaces {
protected IDBConnection $connection;
public function transformFaceFilter(IQueryBuilder &$query, string $userId, int $faceId) {
public function transformFaceFilter(IQueryBuilder &$query, string $userId, string $faceName) {
// Get title and uid of face user
$faceNames = explode('/', $faceName);
if (count($faceNames) !== 2) return;
$faceUid = $faceNames[0];
$faceName = $faceNames[1];
// Get cluster ID
$sq = $query->getConnection()->getQueryBuilder();
$id = $sq->select('id')->from('recognize_face_clusters')
->where($query->expr()->eq('user_id', $sq->createNamedParameter($faceUid)))
->andWhere($query->expr()->eq('title', $sq->createNamedParameter($faceName)))
->executeQuery()->fetchOne();
if (!$id) return;
// Join with cluster
$query->innerJoin('m', 'recognize_face_detections', 'rfd', $query->expr()->andX(
$query->expr()->eq('rfd.file_id', 'm.fileid'),
$query->expr()->eq('rfd.cluster_id', $query->createNamedParameter($faceId)),
$query->expr()->eq('rfd.cluster_id', $query->createNamedParameter($id)),
));
}
@ -22,7 +37,7 @@ trait TimelineQueryFaces {
// SELECT all face clusters
$count = $query->func()->count($query->createFunction('DISTINCT m.fileid'), 'count');
$query->select('rfc.id', 'rfc.title', $count)->from('recognize_face_clusters', 'rfc');
$query->select('rfc.id', 'rfc.user_id', 'rfc.title', $count)->from('recognize_face_clusters', 'rfc');
// WHERE there are faces with this cluster
$query->innerJoin('rfc', 'recognize_face_detections', 'rfd', $query->expr()->eq('rfc.id', 'rfd.cluster_id'));

View File

@ -114,7 +114,9 @@ export default class Tag extends Mixins(GlobalMixin) {
/** Open tag */
openTag() {
if (this.isFace) {
this.$router.push({ name: 'people', params: { name: this.data.faceid.toString() }});
const name = this.data.name;
const user = this.data.user_id;
this.$router.push({ name: 'people', params: { name, user }});
} else {
this.$router.push({ name: 'tags', params: { name: this.data.name }});
}

View File

@ -521,8 +521,8 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) {
}
// People
if (this.$route.name === 'people' && this.$route.params.name) {
query.set('face', this.$route.params.name);
if (this.$route.name === 'people' && this.$route.params.user && this.$route.params.name) {
query.set('face', `${this.$route.params.user}/${this.$route.params.name}`);
}
// Tags

View File

@ -101,7 +101,7 @@
},
{
path: '/people/:name*',
path: '/people/:user?/:name?',
component: Timeline,
name: 'people',
props: route => ({

View File

@ -489,7 +489,6 @@ export async function getTagsData(): Promise<IDay[]> {
detail: data.map((face) => ({
...face,
fileid: hashCode(face.name),
faceid: face.id,
istag: true,
isface: true,
} as any)),

View File

@ -69,8 +69,8 @@ export interface ITag extends IPhoto {
name: string;
/** Number of images in this tag */
count: number;
/** ID of face if this is a face */
faceid?: number;
/** User for face if face */
user_id?: string;
/** Cache of previews */
previews?: IPhoto[];
}