make search history entry count configurable
This commit is contained in:
@@ -81,7 +81,12 @@ Stream<List<BangData>> frequentBangList(Ref ref) {
|
||||
@Riverpod()
|
||||
Stream<List<SearchHistoryEntry>> searchHistory(Ref ref) {
|
||||
final repository = ref.watch(bangDataRepositoryProvider.notifier);
|
||||
return repository.watchSearchHistory(limit: 3); //TODO: make count dynamic
|
||||
final maxSearchHistoryEntries = ref.watch(
|
||||
generalSettingsWithDefaultsProvider.select(
|
||||
(s) => s.maxSearchHistoryEntries,
|
||||
),
|
||||
);
|
||||
return repository.watchSearchHistory(limit: maxSearchHistoryEntries);
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
|
||||
@@ -354,7 +354,7 @@ final class SearchHistoryProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$searchHistoryHash() => r'7b97798729643de8e44fd8024cdc02f35124b08b';
|
||||
String _$searchHistoryHash() => r'5f9508a6b286bfcd1b641bd429de46ad052a3dfe';
|
||||
|
||||
@ProviderFor(lastSyncOfGroup)
|
||||
final lastSyncOfGroupProvider = LastSyncOfGroupFamily._();
|
||||
|
||||
@@ -24,6 +24,7 @@ import 'package:weblibre/features/bangs/data/models/bang_data.dart';
|
||||
import 'package:weblibre/features/bangs/data/providers.dart';
|
||||
import 'package:weblibre/features/bangs/domain/providers/bangs.dart';
|
||||
import 'package:weblibre/features/bangs/domain/repositories/data.dart';
|
||||
import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
|
||||
|
||||
part 'search.g.dart';
|
||||
|
||||
@@ -33,14 +34,15 @@ class BangSearch extends _$BangSearch {
|
||||
|
||||
Future<Uri> triggerBangSearch(BangData bang, String searchQuery) async {
|
||||
final bangDataNotifier = ref.read(bangDataRepositoryProvider.notifier);
|
||||
final settings = ref.read(generalSettingsWithDefaultsProvider);
|
||||
|
||||
await bangDataNotifier.increaseFrequency(bang.toKey());
|
||||
await bangDataNotifier.addSearchEntry(
|
||||
bang.group,
|
||||
bang.trigger,
|
||||
searchQuery,
|
||||
maxEntryCount: 3,
|
||||
); //TODO: make count dynamic
|
||||
maxEntryCount: settings.maxSearchHistoryEntries,
|
||||
);
|
||||
|
||||
return bang.getTemplateUrl(searchQuery);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ final class BangSearchProvider
|
||||
BangSearch create() => BangSearch();
|
||||
}
|
||||
|
||||
String _$bangSearchHash() => r'cd8c6ec433a61979e5feb09014739be92180513b';
|
||||
String _$bangSearchHash() => r'7993bba3765d24ca9a7a17eca86ffdbc7c1b5e65';
|
||||
|
||||
abstract class _$BangSearch extends $StreamNotifier<List<BangData>> {
|
||||
Stream<List<BangData>> build();
|
||||
|
||||
@@ -115,7 +115,12 @@ class BangDataRepository extends _$BangDataRepository {
|
||||
String trigger,
|
||||
String searchQuery, {
|
||||
required int maxEntryCount,
|
||||
}) {
|
||||
}) async {
|
||||
// Skip capturing history if maxEntryCount is 0
|
||||
if (maxEntryCount <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final db = ref.read(bangDatabaseProvider);
|
||||
//Pack in a transaction to bundle rebuilds of watch() queries
|
||||
return db.transaction(() async {
|
||||
|
||||
@@ -42,7 +42,7 @@ final class BangDataRepositoryProvider
|
||||
}
|
||||
|
||||
String _$bangDataRepositoryHash() =>
|
||||
r'e3833d71ca51bfe51feb9f137e154dfebf8b053d';
|
||||
r'c562ef10d75ca6dee13805f84d2491cf2a89aaac';
|
||||
|
||||
abstract class _$BangDataRepository extends $Notifier<void> {
|
||||
void build();
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2025 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:riverpod/riverpod.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/features/bangs/data/providers.dart';
|
||||
import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
|
||||
|
||||
part 'search_history_cleanup.g.dart';
|
||||
|
||||
/// Service that listens to maxSearchHistoryEntries setting changes
|
||||
/// and cleans up search history when the limit is reduced.
|
||||
@Riverpod(keepAlive: true)
|
||||
class SearchHistoryCleanupService extends _$SearchHistoryCleanupService {
|
||||
@override
|
||||
void build() {
|
||||
ref.listen(
|
||||
generalSettingsWithDefaultsProvider.select(
|
||||
(settings) => settings.maxSearchHistoryEntries,
|
||||
),
|
||||
(previous, next) async {
|
||||
// Only cleanup when limit is reduced (including to 0)
|
||||
if (previous != null && next < previous) {
|
||||
final db = ref.read(bangDatabaseProvider);
|
||||
await db.definitionsDrift.evictHistoryEntries(limit: next);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'search_history_cleanup.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
/// Service that listens to maxSearchHistoryEntries setting changes
|
||||
/// and cleans up search history when the limit is reduced.
|
||||
|
||||
@ProviderFor(SearchHistoryCleanupService)
|
||||
final searchHistoryCleanupServiceProvider =
|
||||
SearchHistoryCleanupServiceProvider._();
|
||||
|
||||
/// Service that listens to maxSearchHistoryEntries setting changes
|
||||
/// and cleans up search history when the limit is reduced.
|
||||
final class SearchHistoryCleanupServiceProvider
|
||||
extends $NotifierProvider<SearchHistoryCleanupService, void> {
|
||||
/// Service that listens to maxSearchHistoryEntries setting changes
|
||||
/// and cleans up search history when the limit is reduced.
|
||||
SearchHistoryCleanupServiceProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'searchHistoryCleanupServiceProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$searchHistoryCleanupServiceHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
SearchHistoryCleanupService create() => SearchHistoryCleanupService();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(void value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<void>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$searchHistoryCleanupServiceHash() =>
|
||||
r'4e84ab50fa2ad55c615bb63a667c95383715570b';
|
||||
|
||||
/// Service that listens to maxSearchHistoryEntries setting changes
|
||||
/// and cleans up search history when the limit is reduced.
|
||||
|
||||
abstract class _$SearchHistoryCleanupService extends $Notifier<void> {
|
||||
void build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<void, void>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<void, void>,
|
||||
void,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user