Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mob] Prioritize fetch for already indexed files #3967

Merged
merged 16 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions auth/assets/custom-icons/_data/custom-icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -875,9 +875,6 @@
"Registro.br"
]
},
{
"title": "Render"
},
{
"title": "Restorecord"
},
Expand Down
5 changes: 0 additions & 5 deletions auth/assets/custom-icons/icons/Render.svg

This file was deleted.

26 changes: 0 additions & 26 deletions mobile/lib/db/ml/clip_db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ import "package:photos/models/ml/ml_versions.dart";
import "package:photos/models/ml/vector.dart";

extension ClipDB on MLDataDB {
static const databaseName = "ente.embeddings.db";

Future<List<ClipEmbedding>> getAllClipEmbeddings() async {
final db = await MLDataDB.instance.asyncDB;
final results = await db.getAll('SELECT * FROM $clipTable');
return _convertToEmbeddings(results);
}

Future<List<EmbeddingVector>> getAllClipVectors() async {
Logger("ClipDB").info("reading all embeddings from DB");
final db = await MLDataDB.instance.asyncDB;
Expand Down Expand Up @@ -82,16 +74,6 @@ extension ClipDB on MLDataDB {
Bus.instance.fire(EmbeddingUpdatedEvent());
}

List<ClipEmbedding> _convertToEmbeddings(List<Map<String, dynamic>> results) {
final List<ClipEmbedding> embeddings = [];
for (final result in results) {
final embedding = _getEmbeddingFromRow(result);
if (embedding.isEmpty) continue;
embeddings.add(embedding);
}
return embeddings;
}

List<EmbeddingVector> _convertToVectors(List<Map<String, dynamic>> results) {
final List<EmbeddingVector> embeddings = [];
for (final result in results) {
Expand All @@ -102,14 +84,6 @@ extension ClipDB on MLDataDB {
return embeddings;
}

ClipEmbedding _getEmbeddingFromRow(Map<String, dynamic> row) {
final fileID = row[fileIDColumn] as int;
final bytes = row[embeddingColumn] as Uint8List;
final version = row[mlVersionColumn] as int;
final list = Float32List.view(bytes.buffer);
return ClipEmbedding(fileID: fileID, embedding: list, version: version);
}

EmbeddingVector _getVectorFromRow(Map<String, dynamic> row) {
final fileID = row[fileIDColumn] as int;
final bytes = row[embeddingColumn] as Uint8List;
Expand Down
2 changes: 2 additions & 0 deletions mobile/lib/db/ml/db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class MLDataDB {
createNotPersonFeedbackTable,
fcClusterIDIndex,
createClipEmbeddingsTable,
createFileDataTable,
];

// only have a single app-wide reference to the database
Expand Down Expand Up @@ -237,6 +238,7 @@ class MLDataDB {
await db.execute(deleteClusterSummaryTable);
await db.execute(deleteNotPersonFeedbackTable);
await db.execute(deleteClipEmbeddingsTable);
await db.execute(deleteFileDataTable);
}

Future<Iterable<Uint8List>> getFaceEmbeddingsForCluster(
Expand Down
16 changes: 16 additions & 0 deletions mobile/lib/db/ml/db_fields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,19 @@ CREATE TABLE IF NOT EXISTS $clipTable (
''';

const deleteClipEmbeddingsTable = 'DELETE FROM $clipTable';

const fileDataTable = 'filedata';
const createFileDataTable = '''
CREATE TABLE IF NOT EXISTS $fileDataTable (
$fileIDColumn INTEGER NOT NULL,
user_id INTEGER NOT NULL,
type TEXT NOT NULL,
size INTEGER NOT NULL,
obj_id TEXT,
obj_nonce TEXT,
updated_at INTEGER NOT NULL,
PRIMARY KEY ($fileIDColumn, type)
);
''';

const deleteFileDataTable = 'DELETE FROM $fileDataTable';
34 changes: 34 additions & 0 deletions mobile/lib/db/ml/filedata.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import "package:photos/db/ml/db.dart";
import "package:photos/db/ml/db_fields.dart";
import "package:photos/services/filedata/model/file_data.dart";

extension FileDataTable on MLDataDB {
Future<void> putFDStatus(List<FDStatus> fdStatusList) async {
if (fdStatusList.isEmpty) return;
final db = await MLDataDB.instance.asyncDB;
final inputs = <List<Object?>>[];
for (var status in fdStatusList) {
inputs.add(
[
status.fileID,
status.userID,
status.type,
status.size,
status.objectID,
status.objectNonce,
status.updatedAt,
],
);
}
await db.executeBatch(
'INSERT OR REPLACE INTO $fileDataTable ($fileIDColumn, user_id, type, size, obj_id, obj_nonce, updated_at ) values(?, ?, ?, ?, ?, ?, ?)',
inputs,
);
}

Future<Set<int>> getFileIDsWithFDData() async {
final db = await MLDataDB.instance.asyncDB;
final res = await db.execute('SELECT $fileIDColumn FROM $fileDataTable');
return res.map((e) => e[fileIDColumn] as int).toSet();
}
}
12 changes: 6 additions & 6 deletions mobile/lib/generated/intl/messages_da.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading