mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 19:36:25 +08:00
NotesFolderFS: Avoid multiple load operations in parallel
This commit is contained in:
@ -3,6 +3,7 @@ import 'dart:io';
|
|||||||
import 'package:fimber/fimber.dart';
|
import 'package:fimber/fimber.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
import 'package:path/path.dart';
|
import 'package:path/path.dart';
|
||||||
|
import 'package:synchronized/synchronized.dart';
|
||||||
|
|
||||||
import 'note.dart';
|
import 'note.dart';
|
||||||
import 'notes_folder.dart';
|
import 'notes_folder.dart';
|
||||||
@ -11,6 +12,7 @@ import 'notes_folder_notifier.dart';
|
|||||||
class NotesFolderFS with NotesFolderNotifier implements NotesFolder {
|
class NotesFolderFS with NotesFolderNotifier implements NotesFolder {
|
||||||
final NotesFolderFS _parent;
|
final NotesFolderFS _parent;
|
||||||
String _folderPath;
|
String _folderPath;
|
||||||
|
var _lock = Lock();
|
||||||
|
|
||||||
List<Note> _notes = [];
|
List<Note> _notes = [];
|
||||||
List<NotesFolderFS> _folders = [];
|
List<NotesFolderFS> _folders = [];
|
||||||
@ -137,8 +139,14 @@ class NotesFolderFS with NotesFolderNotifier implements NotesFolder {
|
|||||||
return Future.wait(futures);
|
return Future.wait(futures);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: This should not reconstruct the Notes or NotesFolders once constructed.
|
|
||||||
Future<void> load() async {
|
Future<void> load() async {
|
||||||
|
return _lock.synchronized(() async {
|
||||||
|
return _load();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: This should not reconstruct the Notes or NotesFolders once constructed.
|
||||||
|
Future<void> _load() async {
|
||||||
Set<String> pathsFound = {};
|
Set<String> pathsFound = {};
|
||||||
|
|
||||||
final dir = Directory(folderPath);
|
final dir = Directory(folderPath);
|
||||||
|
Reference in New Issue
Block a user