Skip to content

Commit

Permalink
[mob] Discover improvements (#3421)
Browse files Browse the repository at this point in the history
## Description

## Tests
  • Loading branch information
ua741 authored Sep 23, 2024
2 parents 76e4d53 + c036c8c commit bb23c75
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 7 deletions.
4 changes: 3 additions & 1 deletion mobile/lib/generated/intl/messages_cs.dart

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

20 changes: 20 additions & 0 deletions mobile/lib/generated/intl/messages_de.dart

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

23 changes: 22 additions & 1 deletion mobile/lib/generated/intl/messages_it.dart

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

21 changes: 21 additions & 0 deletions mobile/lib/generated/intl/messages_pt.dart

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

3 changes: 3 additions & 0 deletions mobile/lib/generated/intl/messages_sv.dart

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

16 changes: 16 additions & 0 deletions mobile/lib/generated/intl/messages_zh.dart

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

7 changes: 7 additions & 0 deletions mobile/lib/services/machine_learning/ml_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ class MLService {
);
await clusterAllImages();
}
if (_mlControllerStatus == true) {
// refresh discover section
MagicCacheService.instance.updateCache().ignore();
}
await indexAllImages();
if ((await MLDataDB.instance.getUnclusteredFaceCount()) > 0) {
await clusterAllImages();
Expand Down Expand Up @@ -208,6 +212,9 @@ class MLService {
);
fileAnalyzedCount += sumFutures;
}
if (fileAnalyzedCount > 0) {
MagicCacheService.instance.queueUpdate('fileIndexed');
}
_logger.info(
"`indexAllImages()` finished. Analyzed $fileAnalyzedCount images, in ${stopwatch.elapsed.inSeconds} seconds (avg of ${stopwatch.elapsed.inSeconds / fileAnalyzedCount} seconds per image)",
);
Expand Down
15 changes: 11 additions & 4 deletions mobile/lib/services/magic_cache_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class MagicCacheService {
_updateCacheIfTheTimeHasCome();
});
Bus.instance.on<FileUploadedEvent>().listen((event) {
_pendingUpdateReason.add("File uploaded");
queueUpdate("File uploaded");
});
}

Expand All @@ -191,19 +191,23 @@ class MagicCacheService {

bool get enableDiscover => localSettings.isMLIndexingEnabled;

void queueUpdate(String reason) {
_pendingUpdateReason.add(reason);
}

Future<void> _updateCacheIfTheTimeHasCome() async {
if (!enableDiscover) {
return;
}
final updatedJSONFile = await RemoteAssetsService.instance
.getAssetIfUpdated(_kMagicPromptsDataUrl);
if (updatedJSONFile != null) {
_pendingUpdateReason.add("Prompts data updated");
queueUpdate("Prompts data updated");
} else if (lastMagicCacheUpdateTime <
DateTime.now()
.subtract(const Duration(days: 1))
.millisecondsSinceEpoch) {
_pendingUpdateReason.add("Cache is old");
queueUpdate("Cache is old");
}
}

Expand All @@ -226,7 +230,6 @@ class MagicCacheService {
return;
}
_logger.info("updating magic cache ${_pendingUpdateReason.toList()}");
_pendingUpdateReason.clear();
_isUpdateInProgress = true;
final EnteWatch? w = kDebugMode ? EnteWatch("magicCacheWatch") : null;
w?.start();
Expand All @@ -245,6 +248,7 @@ class MagicCacheService {
w?.log("cacheWritten");
await _resetLastMagicCacheUpdateTime();
w?.logAndReset('done');
_pendingUpdateReason.clear();
Bus.instance.fire(MagicCacheUpdatedEvent());
} catch (e, s) {
_logger.info("Error updating magic cache", e, s);
Expand Down Expand Up @@ -376,6 +380,7 @@ class MagicCacheService {
List<Prompt> magicPromptsData,
) async {
final results = <MagicCache>[];
final List<int> matchCount = [];
for (Prompt prompt in magicPromptsData) {
final fileUploadedIDs =
await SemanticSearchService.instance.getMatchingFileIDs(
Expand All @@ -387,7 +392,9 @@ class MagicCacheService {
MagicCache(prompt.title, fileUploadedIDs),
);
}
matchCount.add(fileUploadedIDs.length);
}
_logger.info('magic result count $matchCount');
return results;
}
}
2 changes: 1 addition & 1 deletion mobile/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description: ente photos application
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html

version: 0.9.43+943
version: 0.9.44+944
publish_to: none

environment:
Expand Down

0 comments on commit bb23c75

Please sign in to comment.