mirror of
https://github.com/ente-io/ente.git
synced 2025-08-08 23:39:30 +00:00
[mob] Avoid refreshing cache unless search is initiated
This commit is contained in:
parent
b591f3d851
commit
268eeab094
@ -44,6 +44,7 @@ class SemanticSearchService {
|
|||||||
bool _hasInitialized = false;
|
bool _hasInitialized = false;
|
||||||
bool _textModelIsLoaded = false;
|
bool _textModelIsLoaded = false;
|
||||||
List<ClipEmbedding> _cachedImageEmbeddings = <ClipEmbedding>[];
|
List<ClipEmbedding> _cachedImageEmbeddings = <ClipEmbedding>[];
|
||||||
|
bool _isCacheRefreshPending = true;
|
||||||
Future<(String, List<EnteFile>)>? _searchScreenRequest;
|
Future<(String, List<EnteFile>)>? _searchScreenRequest;
|
||||||
String? _latestPendingQuery;
|
String? _latestPendingQuery;
|
||||||
|
|
||||||
@ -57,12 +58,9 @@ class SemanticSearchService {
|
|||||||
}
|
}
|
||||||
_hasInitialized = true;
|
_hasInitialized = true;
|
||||||
|
|
||||||
await _loadImageEmbeddings();
|
await _refreshClipCache();
|
||||||
Bus.instance.on<EmbeddingUpdatedEvent>().listen((event) {
|
Bus.instance.on<EmbeddingUpdatedEvent>().listen((event) {
|
||||||
if (!_hasInitialized) return;
|
_isCacheRefreshPending = true;
|
||||||
_reloadCacheDebouncer.run(() async {
|
|
||||||
await _loadImageEmbeddings();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
unawaited(_loadTextModel(delay: true));
|
unawaited(_loadTextModel(delay: true));
|
||||||
@ -77,6 +75,7 @@ class SemanticSearchService {
|
|||||||
// searchScreenQuery should only be used for the user initiate query on the search screen.
|
// searchScreenQuery should only be used for the user initiate query on the search screen.
|
||||||
// If there are multiple call tho this method, then for all the calls, the result will be the same as the last query.
|
// If there are multiple call tho this method, then for all the calls, the result will be the same as the last query.
|
||||||
Future<(String, List<EnteFile>)> searchScreenQuery(String query) async {
|
Future<(String, List<EnteFile>)> searchScreenQuery(String query) async {
|
||||||
|
await _refreshClipCache();
|
||||||
if (!isMagicSearchEnabledAndReady()) {
|
if (!isMagicSearchEnabledAndReady()) {
|
||||||
if (flagService.internalUser) {
|
if (flagService.internalUser) {
|
||||||
_logger.info(
|
_logger.info(
|
||||||
@ -114,7 +113,11 @@ class SemanticSearchService {
|
|||||||
_logger.info("Indexes cleared");
|
_logger.info("Indexes cleared");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadImageEmbeddings() async {
|
Future<void> _refreshClipCache() async {
|
||||||
|
if (_isCacheRefreshPending == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_isCacheRefreshPending = false;
|
||||||
_logger.info("Pulling cached embeddings");
|
_logger.info("Pulling cached embeddings");
|
||||||
final startTime = DateTime.now();
|
final startTime = DateTime.now();
|
||||||
_cachedImageEmbeddings = await MLDataDB.instance.getAll();
|
_cachedImageEmbeddings = await MLDataDB.instance.getAll();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user