ml wait initial load
This commit is contained in:
@@ -15,6 +15,8 @@ part 'container_topic.g.dart';
|
||||
class ContainerTopicRepository extends _$ContainerTopicRepository {
|
||||
final _service = GeckoMlService();
|
||||
|
||||
//Wait for first complete page laod of any website after startup to ensure everything is ready
|
||||
final _initialLoadComplete = Completer();
|
||||
final _lock = Lock();
|
||||
|
||||
final _cache = LRUCache<Set<String>, String>(
|
||||
@@ -27,6 +29,12 @@ class ContainerTopicRepository extends _$ContainerTopicRepository {
|
||||
},
|
||||
);
|
||||
|
||||
void markInitialLoadComplete() {
|
||||
if (!_initialLoadComplete.isCompleted) {
|
||||
_initialLoadComplete.complete();
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> getContainerTopic(Set<String> titles) async {
|
||||
if (titles.isNotEmpty) {
|
||||
if (_cache.get(titles) case final String title) {
|
||||
@@ -35,6 +43,8 @@ class ContainerTopicRepository extends _$ContainerTopicRepository {
|
||||
|
||||
try {
|
||||
final title = await _lock.synchronized(() async {
|
||||
await _initialLoadComplete.future;
|
||||
|
||||
final title = await _service.getContainerTopic(titles);
|
||||
|
||||
return _cache.set(titles, title);
|
||||
|
||||
@@ -147,7 +147,7 @@ class _ContainerTopicProviderElement extends FutureProviderElement<String?>
|
||||
}
|
||||
|
||||
String _$containerTopicRepositoryHash() =>
|
||||
r'20ae14772821ac8a4ec0c16bc551e29098556189';
|
||||
r'8dfc0bc8b4953b5230a1faa24c8b2f0a94ab1f04';
|
||||
|
||||
/// See also [ContainerTopicRepository].
|
||||
@ProviderFor(ContainerTopicRepository)
|
||||
|
||||
Reference in New Issue
Block a user