Reduce I/O operations

getMangaChapterDirectory() now accepts an optional mangaMainDirectory
to avoid calling getMangaMainDirectory() and thus getDirectory() twice in places where both methods are called successively.
This commit is contained in:
NBA2K1 2025-04-29 18:47:43 +02:00
parent 46526c6b6b
commit 2698db6085
5 changed files with 25 additions and 7 deletions

View file

@ -1472,7 +1472,10 @@ class _LibraryScreenState extends ConsumerState<LibraryScreen>
final mangaDir = await storageProvider
.getMangaMainDirectory(chapter);
final path = await storageProvider
.getMangaChapterDirectory(chapter);
.getMangaChapterDirectory(
chapter,
mangaMainDirectory: mangaDir,
);
try {
try {

View file

@ -28,7 +28,10 @@ class ChapterPageDownload extends ConsumerWidget {
void _sendFile() async {
final storageProvider = StorageProvider();
final mangaDir = await storageProvider.getMangaMainDirectory(chapter);
final path = await storageProvider.getMangaChapterDirectory(chapter);
final path = await storageProvider.getMangaChapterDirectory(
chapter,
mangaMainDirectory: mangaDir,
);
List<XFile> files = [];
@ -57,7 +60,10 @@ class ChapterPageDownload extends ConsumerWidget {
void _deleteFile(int downloadId) async {
final storageProvider = StorageProvider();
final mangaDir = await storageProvider.getMangaMainDirectory(chapter);
final path = await storageProvider.getMangaChapterDirectory(chapter);
final path = await storageProvider.getMangaChapterDirectory(
chapter,
mangaMainDirectory: mangaDir,
);
try {
try {

View file

@ -57,7 +57,10 @@ Future<void> downloadChapter(
final chapterName = chapter.name!.replaceForbiddenCharacters(' ');
final itemType = chapter.manga.value!.itemType;
final chapterDirectory =
(await storageProvider.getMangaChapterDirectory(chapter))!;
(await storageProvider.getMangaChapterDirectory(
chapter,
mangaMainDirectory: mangaMainDirectory,
))!;
await Directory(chapterDirectory.path).create(recursive: true);
Map<String, String> videoHeader = {};
Map<String, String> htmlHeader = {

View file

@ -103,8 +103,11 @@ class StorageProvider {
);
}
Future<Directory?> getMangaChapterDirectory(Chapter chapter) async {
final basedir = await getMangaMainDirectory(chapter);
Future<Directory?> getMangaChapterDirectory(
Chapter chapter, {
Directory? mangaMainDirectory,
}) async {
final basedir = mangaMainDirectory ?? await getMangaMainDirectory(chapter);
String scanlator =
chapter.scanlator?.isNotEmpty ?? false
? "${chapter.scanlator!.replaceForbiddenCharacters('_')}_"

View file

@ -50,8 +50,11 @@ Future<GetChapterPagesModel> getChapterPages(
.firstOrNull;
final incognitoMode = ref.watch(incognitoModeStateProvider);
final storageProvider = StorageProvider();
path = await storageProvider.getMangaChapterDirectory(chapter);
final mangaDirectory = await storageProvider.getMangaMainDirectory(chapter);
path = await storageProvider.getMangaChapterDirectory(
chapter,
mangaMainDirectory: mangaDirectory,
);
List<Uint8List?> archiveImages = [];
final isLocalArchive = (chapter.archivePath ?? '').isNotEmpty;