make search history entry count configurable
This commit is contained in:
@@ -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