Skip to content

Commit

Permalink
Merge pull request #1504 from nextcloud/perf/nextcloud/immutable_webd…
Browse files Browse the repository at this point in the history
…av_props

perf(nextcloud): make webdav props immutable and add constant constru…
  • Loading branch information
Leptopoda authored Jan 24, 2024
2 parents 87eb873 + 59a5ea9 commit 4490e77
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 143 deletions.
2 changes: 1 addition & 1 deletion packages/neon/neon_files/lib/src/blocs/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class _FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBloc {
files,
() => account.client.webdav.propfind(
uri.value,
prop: WebDavPropWithoutValues.fromBools(
prop: const WebDavPropWithoutValues.fromBools(
davgetcontenttype: true,
davgetetag: true,
davgetlastmodified: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/neon/neon_files/lib/src/blocs/files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class _FilesBloc extends InteractiveBloc implements FilesBloc {
wrapAction(
() async => account.client.webdav.proppatch(
uri,
set: WebDavProp(ocfavorite: 1),
set: const WebDavProp(ocfavorite: 1),
),
);
}
Expand Down Expand Up @@ -151,7 +151,7 @@ class _FilesBloc extends InteractiveBloc implements FilesBloc {
wrapAction(
() async => account.client.webdav.proppatch(
uri,
set: WebDavProp(ocfavorite: 0),
set: const WebDavProp(ocfavorite: 0),
),
);
}
Expand Down
12 changes: 7 additions & 5 deletions packages/nextcloud/generate_props.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ void main() {
final name = prop[1];
final variable = namespacePrefix + name.toLowerCase().replaceAll(RegExp('[^a-z]'), '');
valueProps.add(
"@annotation.XmlElement(name: '$name', namespace: $namespaceVariable, includeIfNull: false,)\n $type? $variable;",
"@annotation.XmlElement(name: '$name', namespace: $namespaceVariable, includeIfNull: false,)\n final $type? $variable;",
);
findProps.add(
"@annotation.XmlElement(name: '$name', namespace: $namespaceVariable, includeIfNull: true, isSelfClosing: true,)\n List<String?>? $variable;",
"@annotation.XmlElement(name: '$name', namespace: $namespaceVariable, includeIfNull: true, isSelfClosing: true,)\n final List<String?>? $variable;",
);
variables.add(variable);
}
File('lib/src/webdav/props.dart').writeAsStringSync(
[
'// ignore_for_file: public_member_api_docs',
'// coverage:ignore-file',
"import 'package:meta/meta.dart';",
"import 'package:nextcloud/src/webdav/webdav.dart';",
"import 'package:xml/xml.dart';",
"import 'package:xml_annotation/xml_annotation.dart' as annotation;",
Expand Down Expand Up @@ -66,17 +67,18 @@ List<String> generateClass(
required bool isPropfind,
}) =>
[
'@immutable',
'@annotation.XmlSerializable(createMixin: true)',
"@annotation.XmlRootElement(name: '$elementName', namespace: $namespace)",
'class $name with _\$${name}XmlSerializableMixin {',
' $name({',
' const $name({',
...variables.map((variable) => ' this.$variable,'),
' });',
'',
if (isPropfind) ...[
' $name.fromBools({',
' const $name.fromBools({',
...variables.map((variable) => ' bool $variable = false,'),
' }) : ${variables.map((variable) => '$variable = $variable ? [null] : null').join(', ')};',
' }) : ${variables.map((variable) => '$variable = $variable ? const [null] : null').join(', ')};',
'',
],
' factory $name.fromXmlElement(XmlElement element) => _\$${name}FromXmlElement(element);',
Expand Down
6 changes: 4 additions & 2 deletions packages/nextcloud/lib/src/webdav/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ class WebDavClient {
'PROPFIND',
_constructUri(path),
data: utf8.encode(
WebDavPropfind(prop: prop ?? WebDavPropWithoutValues()).toXmlElement(namespaces: namespaces).toXmlString(),
WebDavPropfind(prop: prop ?? const WebDavPropWithoutValues())
.toXmlElement(namespaces: namespaces)
.toXmlString(),
),
headers: depth != null ? {'Depth': depth.value} : null,
),
Expand All @@ -296,7 +298,7 @@ class WebDavClient {
data: utf8.encode(
WebDavOcFilterFiles(
filterRules: filterRules,
prop: prop ?? WebDavPropWithoutValues(), // coverage:ignore-line
prop: prop ?? const WebDavPropWithoutValues(), // coverage:ignore-line
).toXmlElement(namespaces: namespaces).toXmlString(),
),
),
Expand Down
Loading

0 comments on commit 4490e77

Please sign in to comment.