[mob] Minor fixes (#1724)

## Description
In case of semantic search, the cache update was taking time due to
debouncer.
It was resulting in re-indexing of certain files. Also, the status of
indexing was stale as we were relying on same event to schedule update
of cache and refresh status (which relies on cache).
## Tests
This commit is contained in:
Neeraj Gupta 2024-05-14 19:01:56 +05:30 committed by GitHub
commit 3adadee82b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 32 additions and 13 deletions

View file

@ -63,6 +63,19 @@ class EmbeddingsDB {
return _convertToEmbeddings(results);
}
// Get FileIDs for a specific model
Future<Set<int>> getFileIDs(Model model) async {
final db = await _database;
final results = await db.getAll(
'SELECT $columnFileID FROM $tableName WHERE $columnModel = ?',
[modelToInt(model)!],
);
if (results.isEmpty) {
return <int>{};
}
return results.map((e) => e[columnFileID] as int).toSet();
}
Future<void> put(Embedding embedding) async {
final db = await _database;
await db.execute(

View file

@ -90,7 +90,7 @@ class UploadLocksDB {
static List<String> _createTrackUploadsTable() {
return [
'''
CREATE TABLE ${_trackUploadTable.table} (
CREATE TABLE IF NOT EXISTS ${_trackUploadTable.table} (
${_trackUploadTable.columnID} INTEGER PRIMARY KEY,
${_trackUploadTable.columnLocalID} TEXT NOT NULL,
${_trackUploadTable.columnFileHash} TEXT NOT NULL,
@ -109,7 +109,7 @@ class UploadLocksDB {
)
''',
'''
CREATE TABLE ${_partsTable.table} (
CREATE TABLE IF NOT EXISTS ${_partsTable.table} (
${_partsTable.columnObjectKey} TEXT NOT NULL REFERENCES ${_trackUploadTable.table}(${_trackUploadTable.columnObjectKey}) ON DELETE CASCADE,
${_partsTable.columnPartNumber} INTEGER NOT NULL,
${_partsTable.columnPartUrl} TEXT NOT NULL,

View file

@ -1,3 +1,5 @@
import "package:photos/events/event.dart";
class EmbeddingUpdatedEvent extends Event {}
class EmbeddingCacheUpdatedEvent extends Event {}

View file

@ -631,8 +631,9 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Dobre seu armazenamento"),
"download": MessageLookupByLibrary.simpleMessage("Baixar"),
"downloadFailed":
MessageLookupByLibrary.simpleMessage("Falha ao baixar"),
"downloading": MessageLookupByLibrary.simpleMessage("Baixando..."),
MessageLookupByLibrary.simpleMessage("Falha no download"),
"downloading":
MessageLookupByLibrary.simpleMessage("Fazendo download..."),
"dropSupportEmail": m17,
"duplicateFileCountWithStorageSaved": m18,
"duplicateItemsGroup": m19,
@ -718,8 +719,8 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Falha ao aplicar o código"),
"failedToCancel":
MessageLookupByLibrary.simpleMessage("Falha ao cancelar"),
"failedToDownloadVideo":
MessageLookupByLibrary.simpleMessage("Falha ao baixar vídeo"),
"failedToDownloadVideo": MessageLookupByLibrary.simpleMessage(
"Falha ao fazer download do vídeo"),
"failedToFetchOriginalForEdit": MessageLookupByLibrary.simpleMessage(
"Falha ao obter original para edição"),
"failedToFetchReferralDetails": MessageLookupByLibrary.simpleMessage(
@ -737,7 +738,7 @@ class MessageLookup extends MessageLookupByLibrary {
"familyPlans": MessageLookupByLibrary.simpleMessage("Plano familiar"),
"faq": MessageLookupByLibrary.simpleMessage("Perguntas frequentes"),
"faqs": MessageLookupByLibrary.simpleMessage("Perguntas frequentes"),
"favorite": MessageLookupByLibrary.simpleMessage("Favoritar"),
"favorite": MessageLookupByLibrary.simpleMessage("Favorito"),
"feedback": MessageLookupByLibrary.simpleMessage("Comentários"),
"fileFailedToSaveToGallery": MessageLookupByLibrary.simpleMessage(
"Falha ao salvar o arquivo na galeria"),
@ -904,8 +905,8 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Carregando galeria..."),
"loadingMessage":
MessageLookupByLibrary.simpleMessage("Carregando suas fotos..."),
"loadingModel":
MessageLookupByLibrary.simpleMessage("Baixando modelos..."),
"loadingModel": MessageLookupByLibrary.simpleMessage(
"Fazendo download de modelos..."),
"localGallery": MessageLookupByLibrary.simpleMessage("Galeria local"),
"location": MessageLookupByLibrary.simpleMessage("Local"),
"locationName": MessageLookupByLibrary.simpleMessage("Nome do Local"),

View file

@ -124,7 +124,7 @@ class MessageLookup extends MessageLookupByLibrary {
static String m37(providerName) => "如果您被收取费用,请用英语与 ${providerName} 的客服聊天";
static String m38(endDate) => "免费试用有效期至 ${endDate}\n之后您可以选择付费计划。";
static String m38(endDate) => "免费试用有效期至 ${endDate}\n您可以随后购买付费计划。";
static String m39(toEmail) => "请给我们发送电子邮件至 ${toEmail}";

View file

@ -190,6 +190,7 @@ class SemanticSearchService {
_logger.info(
"Loading ${_cachedEmbeddings.length} took: ${(endTime.millisecondsSinceEpoch - startTime.millisecondsSinceEpoch)}ms",
);
Bus.instance.fire(EmbeddingCacheUpdatedEvent());
_logger.info("Cached embeddings: " + _cachedEmbeddings.length.toString());
}
@ -225,7 +226,9 @@ class SemanticSearchService {
Future<List<int>> _getFileIDsToBeIndexed() async {
final uploadedFileIDs = await FilesDB.instance
.getOwnedFileIDs(Configuration.instance.getUserID()!);
final embeddedFileIDs = _cachedEmbeddings.map((e) => e.fileID).toSet();
final embeddedFileIDs =
await EmbeddingsDB.instance.getFileIDs(_currentModel);
uploadedFileIDs.removeWhere(
(id) => embeddedFileIDs.contains(id),
);

View file

@ -228,13 +228,13 @@ class MagicSearchIndexStatsWidget extends StatefulWidget {
class _MagicSearchIndexStatsWidgetState
extends State<MagicSearchIndexStatsWidget> {
IndexStatus? _status;
late StreamSubscription<EmbeddingUpdatedEvent> _eventSubscription;
late StreamSubscription<EmbeddingCacheUpdatedEvent> _eventSubscription;
@override
void initState() {
super.initState();
_eventSubscription =
Bus.instance.on<EmbeddingUpdatedEvent>().listen((event) {
Bus.instance.on<EmbeddingCacheUpdatedEvent>().listen((event) {
_fetchIndexStatus();
});
_fetchIndexStatus();