Skip to content

Commit

Permalink
Merge pull request #996 from nextcloud/perf/neon_files/upload_task
Browse files Browse the repository at this point in the history
perf(neon_files): make displaying upload tasks more performant
  • Loading branch information
Leptopoda authored Oct 24, 2023
2 parents dcbfeef + 4c6e004 commit efb426a
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions packages/neon/neon_files/lib/widgets/browser_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,13 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
},
input: files,
builder: (final context, final sorted) {
final uploadingTasks = tasksSnapshot.requireData
.whereType<FilesUploadTask>()
.where(
(final task) =>
sorted.where((final file) => _pathMatchesFile(task.path, file.name)).isEmpty,
)
.toList();
final uploadingTaskTiles = buildUploadTasks(tasksSnapshot.requireData, sorted);

return NeonListView(
scrollKey: 'files-${pathSnapshot.requireData.join('/')}',
itemCount: uploadingTasks.length + sorted.length,
itemCount: sorted.length,
itemBuilder: (final context, final index) {
if (index < uploadingTasks.length) {
return FileListTile(
bloc: widget.filesBloc,
browserBloc: widget.bloc,
details: FileDetails.fromUploadTask(
task: uploadingTasks[index],
),
);
}
final file = sorted[index - uploadingTasks.length];
final file = sorted[index];
final matchingTask = tasksSnapshot.requireData
.firstWhereOrNull((final task) => _pathMatchesFile(task.path, file.name));

Expand Down Expand Up @@ -134,6 +119,7 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
path: pathSnapshot.requireData,
bloc: widget.bloc,
),
...uploadingTaskTiles,
],
);
},
Expand All @@ -146,6 +132,22 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
),
);

Iterable<Widget> buildUploadTasks(final List<FilesTask> tasks, final List<WebDavFile> files) sync* {
for (final task in tasks) {
if (task is! FilesUploadTask) {
continue;
}

yield FileListTile(
bloc: widget.filesBloc,
browserBloc: widget.bloc,
details: FileDetails.fromUploadTask(
task: task,
),
);
}
}

bool _pathMatchesFile(final List<String> path, final String name) => const ListEquality<String>().equals(
[...widget.bloc.path.value, name],
path,
Expand Down

0 comments on commit efb426a

Please sign in to comment.