[mob][photos] Moving more methods to sqlite async
This commit is contained in:
parent
3828fa328e
commit
b2a2078045
4 changed files with 21 additions and 21 deletions
|
@ -98,7 +98,7 @@ class FaceMLDataDB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateClusterIdToFaceId(
|
Future<void> updateFaceIdToClusterId(
|
||||||
Map<String, int> faceIDToClusterID,
|
Map<String, int> faceIDToClusterID,
|
||||||
) async {
|
) async {
|
||||||
final db = await instance.database;
|
final db = await instance.database;
|
||||||
|
@ -197,8 +197,8 @@ class FaceMLDataDB {
|
||||||
int clusterID, {
|
int clusterID, {
|
||||||
int? limit,
|
int? limit,
|
||||||
}) async {
|
}) async {
|
||||||
final db = await instance.database;
|
final db = await instance.sqliteAsyncDB;
|
||||||
final List<Map<String, dynamic>> maps = await db.rawQuery(
|
final List<Map<String, dynamic>> maps = await db.getAll(
|
||||||
'SELECT $faceEmbeddingBlob FROM $facesTable WHERE $faceIDColumn in (SELECT $fcFaceId from $faceClustersTable where $fcClusterID = ?) ${limit != null ? 'LIMIT $limit' : ''}',
|
'SELECT $faceEmbeddingBlob FROM $facesTable WHERE $faceIDColumn in (SELECT $fcFaceId from $faceClustersTable where $fcClusterID = ?) ${limit != null ? 'LIMIT $limit' : ''}',
|
||||||
[clusterID],
|
[clusterID],
|
||||||
);
|
);
|
||||||
|
@ -209,7 +209,7 @@ class FaceMLDataDB {
|
||||||
Iterable<int> clusterIDs, {
|
Iterable<int> clusterIDs, {
|
||||||
int? limit,
|
int? limit,
|
||||||
}) async {
|
}) async {
|
||||||
final db = await instance.database;
|
final db = await instance.sqliteAsyncDB;
|
||||||
final Map<int, List<Uint8List>> result = {};
|
final Map<int, List<Uint8List>> result = {};
|
||||||
|
|
||||||
final selectQuery = '''
|
final selectQuery = '''
|
||||||
|
@ -220,7 +220,7 @@ class FaceMLDataDB {
|
||||||
${limit != null ? 'LIMIT $limit' : ''}
|
${limit != null ? 'LIMIT $limit' : ''}
|
||||||
''';
|
''';
|
||||||
|
|
||||||
final List<Map<String, dynamic>> maps = await db.rawQuery(selectQuery);
|
final List<Map<String, dynamic>> maps = await db.getAll(selectQuery);
|
||||||
|
|
||||||
for (final map in maps) {
|
for (final map in maps) {
|
||||||
final clusterID = map[fcClusterID] as int;
|
final clusterID = map[fcClusterID] as int;
|
||||||
|
@ -321,8 +321,8 @@ class FaceMLDataDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Face?> getFaceForFaceID(String faceID) async {
|
Future<Face?> getFaceForFaceID(String faceID) async {
|
||||||
final db = await instance.database;
|
final db = await instance.sqliteAsyncDB;
|
||||||
final result = await db.rawQuery(
|
final result = await db.getAll(
|
||||||
'SELECT * FROM $facesTable where $faceIDColumn = ?',
|
'SELECT * FROM $facesTable where $faceIDColumn = ?',
|
||||||
[faceID],
|
[faceID],
|
||||||
);
|
);
|
||||||
|
@ -420,8 +420,8 @@ class FaceMLDataDB {
|
||||||
Future<Map<String, int?>> getFaceIdsToClusterIds(
|
Future<Map<String, int?>> getFaceIdsToClusterIds(
|
||||||
Iterable<String> faceIds,
|
Iterable<String> faceIds,
|
||||||
) async {
|
) async {
|
||||||
final db = await instance.database;
|
final db = await instance.sqliteAsyncDB;
|
||||||
final List<Map<String, dynamic>> maps = await db.rawQuery(
|
final List<Map<String, dynamic>> maps = await db.getAll(
|
||||||
'SELECT $fcFaceId, $fcClusterID FROM $faceClustersTable where $fcFaceId IN (${faceIds.map((id) => "'$id'").join(",")})',
|
'SELECT $fcFaceId, $fcClusterID FROM $faceClustersTable where $fcFaceId IN (${faceIds.map((id) => "'$id'").join(",")})',
|
||||||
);
|
);
|
||||||
final Map<String, int?> result = {};
|
final Map<String, int?> result = {};
|
||||||
|
@ -433,8 +433,8 @@ class FaceMLDataDB {
|
||||||
|
|
||||||
Future<Map<int, Set<int>>> getFileIdToClusterIds() async {
|
Future<Map<int, Set<int>>> getFileIdToClusterIds() async {
|
||||||
final Map<int, Set<int>> result = {};
|
final Map<int, Set<int>> result = {};
|
||||||
final db = await instance.database;
|
final db = await instance.sqliteAsyncDB;
|
||||||
final List<Map<String, dynamic>> maps = await db.rawQuery(
|
final List<Map<String, dynamic>> maps = await db.getAll(
|
||||||
'SELECT $fcClusterID, $fcFaceId FROM $faceClustersTable',
|
'SELECT $fcClusterID, $fcFaceId FROM $faceClustersTable',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -791,9 +791,9 @@ class FaceMLDataDB {
|
||||||
|
|
||||||
// for a given personID, return a map of clusterID to fileIDs using join query
|
// for a given personID, return a map of clusterID to fileIDs using join query
|
||||||
Future<Map<int, Set<int>>> getFileIdToClusterIDSet(String personID) {
|
Future<Map<int, Set<int>>> getFileIdToClusterIDSet(String personID) {
|
||||||
final db = instance.database;
|
final db = instance.sqliteAsyncDB;
|
||||||
return db.then((db) async {
|
return db.then((db) async {
|
||||||
final List<Map<String, dynamic>> maps = await db.rawQuery(
|
final List<Map<String, dynamic>> maps = await db.getAll(
|
||||||
'SELECT $faceClustersTable.$fcClusterID, $fcFaceId FROM $faceClustersTable '
|
'SELECT $faceClustersTable.$fcClusterID, $fcFaceId FROM $faceClustersTable '
|
||||||
'INNER JOIN $clusterPersonTable '
|
'INNER JOIN $clusterPersonTable '
|
||||||
'ON $faceClustersTable.$fcClusterID = $clusterPersonTable.$clusterIDColumn '
|
'ON $faceClustersTable.$fcClusterID = $clusterPersonTable.$clusterIDColumn '
|
||||||
|
@ -814,9 +814,9 @@ class FaceMLDataDB {
|
||||||
Future<Map<int, Set<int>>> getFileIdToClusterIDSetForCluster(
|
Future<Map<int, Set<int>>> getFileIdToClusterIDSetForCluster(
|
||||||
Set<int> clusterIDs,
|
Set<int> clusterIDs,
|
||||||
) {
|
) {
|
||||||
final db = instance.database;
|
final db = instance.sqliteAsyncDB;
|
||||||
return db.then((db) async {
|
return db.then((db) async {
|
||||||
final List<Map<String, dynamic>> maps = await db.rawQuery(
|
final List<Map<String, dynamic>> maps = await db.getAll(
|
||||||
'SELECT $fcClusterID, $fcFaceId FROM $faceClustersTable '
|
'SELECT $fcClusterID, $fcFaceId FROM $faceClustersTable '
|
||||||
'WHERE $fcClusterID IN (${clusterIDs.join(",")})',
|
'WHERE $fcClusterID IN (${clusterIDs.join(",")})',
|
||||||
);
|
);
|
||||||
|
@ -894,8 +894,8 @@ class FaceMLDataDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<int, String>> getClusterIDToPersonID() async {
|
Future<Map<int, String>> getClusterIDToPersonID() async {
|
||||||
final db = await instance.database;
|
final db = await instance.sqliteAsyncDB;
|
||||||
final List<Map<String, dynamic>> maps = await db.rawQuery(
|
final List<Map<String, dynamic>> maps = await db.getAll(
|
||||||
'SELECT $personIdColumn, $clusterIDColumn FROM $clusterPersonTable',
|
'SELECT $personIdColumn, $clusterIDColumn FROM $clusterPersonTable',
|
||||||
);
|
);
|
||||||
final Map<int, String> result = {};
|
final Map<int, String> result = {};
|
||||||
|
|
|
@ -350,7 +350,7 @@ class FaceMlService {
|
||||||
}
|
}
|
||||||
|
|
||||||
await FaceMLDataDB.instance
|
await FaceMLDataDB.instance
|
||||||
.updateClusterIdToFaceId(clusteringResult.newFaceIdToCluster);
|
.updateFaceIdToClusterId(clusteringResult.newFaceIdToCluster);
|
||||||
await FaceMLDataDB.instance
|
await FaceMLDataDB.instance
|
||||||
.clusterSummaryUpdate(clusteringResult.newClusterSummaries!);
|
.clusterSummaryUpdate(clusteringResult.newClusterSummaries!);
|
||||||
_logger.info(
|
_logger.info(
|
||||||
|
@ -403,7 +403,7 @@ class FaceMlService {
|
||||||
'Updating ${clusteringResult.newFaceIdToCluster.length} FaceIDs with clusterIDs in the DB',
|
'Updating ${clusteringResult.newFaceIdToCluster.length} FaceIDs with clusterIDs in the DB',
|
||||||
);
|
);
|
||||||
await FaceMLDataDB.instance
|
await FaceMLDataDB.instance
|
||||||
.updateClusterIdToFaceId(clusteringResult.newFaceIdToCluster);
|
.updateFaceIdToClusterId(clusteringResult.newFaceIdToCluster);
|
||||||
await FaceMLDataDB.instance
|
await FaceMLDataDB.instance
|
||||||
.clusterSummaryUpdate(clusteringResult.newClusterSummaries!);
|
.clusterSummaryUpdate(clusteringResult.newClusterSummaries!);
|
||||||
_logger.info('Done updating FaceIDs with clusterIDs in the DB, in '
|
_logger.info('Done updating FaceIDs with clusterIDs in the DB, in '
|
||||||
|
|
|
@ -412,7 +412,7 @@ class ClusterFeedbackService {
|
||||||
final newClusterID = startClusterID + blurValue ~/ 10;
|
final newClusterID = startClusterID + blurValue ~/ 10;
|
||||||
faceIdToCluster[faceID] = newClusterID;
|
faceIdToCluster[faceID] = newClusterID;
|
||||||
}
|
}
|
||||||
await FaceMLDataDB.instance.updateClusterIdToFaceId(faceIdToCluster);
|
await FaceMLDataDB.instance.updateFaceIdToClusterId(faceIdToCluster);
|
||||||
|
|
||||||
Bus.instance.fire(PeopleChangedEvent());
|
Bus.instance.fire(PeopleChangedEvent());
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
|
|
|
@ -193,7 +193,7 @@ class PersonService {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Storing feedback for ${faceIdToClusterID.length} faces");
|
logger.info("Storing feedback for ${faceIdToClusterID.length} faces");
|
||||||
await faceMLDataDB.updateClusterIdToFaceId(faceIdToClusterID);
|
await faceMLDataDB.updateFaceIdToClusterId(faceIdToClusterID);
|
||||||
await faceMLDataDB.bulkAssignClusterToPersonID(clusterToPersonID);
|
await faceMLDataDB.bulkAssignClusterToPersonID(clusterToPersonID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue