为查询添加缓存
All checks were successful
Dart CI / build (push) Successful in 28s

This commit is contained in:
2026-04-04 17:24:46 +08:00
parent 2a6c9ba8c2
commit 01cbb287ab
2 changed files with 24 additions and 3 deletions

View File

@@ -6,10 +6,17 @@ import '../entities/album.dart';
class AlbumRepository {
final String basePath;
final List<Album> _albums = List.empty(growable: true);
DateTime _updated = DateTime.utc(1970);
AlbumRepository({required this.basePath});
Future<List<Album>> getAllAlbums() async {
if (DateTime.now().difference(_updated).inSeconds <= 60) {
return _albums;
}
_updated = DateTime.now();
final dir = Directory(basePath);
if (!await dir.exists()) {
return [];
@@ -29,7 +36,8 @@ class AlbumRepository {
);
})
.toList();
_albums.clear();
_albums.addAll(albums);
return albums;
}