Skip to main content

smriti/db/face_repo/
mod.rs

1//! Face database repository
2//!
3//! Handles all database operations for faces and face clusters.
4
5mod gallery;
6mod read;
7mod undo;
8mod write;
9
10use rusqlite::Connection;
11
12pub use undo::{FaceSnapshot, FaceState};
13
14use crate::ml::FaceEmbedding;
15
16#[derive(Debug, Clone)]
17pub struct GalleryEmbedding {
18    pub cluster_id: i64,
19    pub face_id: i64,
20    pub embedding: FaceEmbedding,
21}
22
23/// Face cluster record from database
24#[derive(Debug, Clone)]
25pub struct FaceClusterRecord {
26    pub id: i64,
27    pub name: Option<String>,
28    pub representative_face_id: Option<i64>,
29    pub photo_count: i64,
30    /// Path to the representative face thumbnail (computed, not stored in DB)
31    pub face_thumbnail_path: Option<String>,
32}
33
34/// Face confirmation status filter for queries.
35#[derive(Debug, Clone)]
36pub enum FaceStatus {
37    Confirmed,
38    Unconfirmed,
39    All,
40}
41
42/// A face row with related metadata, used by face-list views.
43#[derive(Debug, Clone)]
44pub struct FaceDetail {
45    pub face_id: i64,
46    pub photo_id: i64,
47    pub cluster_id: Option<i64>,
48    pub confidence: f32,
49    pub user_confirmed: i32,
50}
51
52/// A face in one photo, as the photo's People panel shows it.
53#[derive(Debug, Clone, PartialEq)]
54pub struct PhotoFace {
55    pub face_id: i64,
56    /// Normalised (x, y, width, height) in display orientation.
57    pub bbox: (f32, f32, f32, f32),
58    pub cluster_id: Option<i64>,
59    /// The person's name, if they have one.
60    pub name: Option<String>,
61    /// The user said this face is this person.
62    pub confirmed: bool,
63}
64
65/// Face database repository
66/// What a merge changed, so it can be undone.
67#[derive(Debug, Clone, PartialEq, Eq)]
68pub struct MergeReceipt {
69    pub source_id: i64,
70    pub target_id: i64,
71    pub source_name: Option<String>,
72    pub source_user_named: bool,
73    /// Faces that moved from the source to the target.
74    pub face_ids: Vec<i64>,
75    /// The target was unnamed and took the source's name.
76    pub target_took_name: bool,
77}
78
79pub struct FaceRepo<'a> {
80    pub(crate) conn: &'a Connection,
81}
82
83impl<'a> FaceRepo<'a> {
84    pub fn new(conn: &'a Connection) -> Self {
85        Self { conn }
86    }
87}