~whynothugo/vdirsyncer-rs

09313411b47dd82c5c093bb1698b9a9ce39306ad — Hugo Osvaldo Barrera 2 months ago 1f05f0f
Use libdav's get_properties in vstorage

Reduces the amount of http requests for querying properties from 4x per
calendar to 1x per calendar.
3 files changed, 38 insertions(+), 20 deletions(-)

M libdav/src/dav.rs
M vstorage/src/caldav.rs
M vstorage/src/carddav.rs
M libdav/src/dav.rs => libdav/src/dav.rs +2 -0
@@ 298,6 298,8 @@ where

    /// Fetch multiple properties for a single resource.
    ///
    /// Values in the returned `Vec` are in the same order as the `properties` parameter.
    ///
    /// # Quirks
    ///
    /// Same as [`WebDavClient::get_property`].

M vstorage/src/caldav.rs => vstorage/src/caldav.rs +18 -10
@@ 369,18 369,26 @@ where
        &self,
        collection_href: &str,
    ) -> Result<Vec<ListedProperty<CalendarProperty>>> {
        let mut props = Vec::new();
        for property in CalendarProperty::known_properties() {
            let prop_value = self.get_property(collection_href, property.clone()).await?;
            if let Some(value) = prop_value {
                props.push(ListedProperty {
        let prop_names = CalendarProperty::known_properties()
            .iter()
            .map(|p| p.dav_propname())
            .collect::<Vec<_>>();
        let result = self
            .client
            .get_properties(collection_href, &prop_names)
            .await?
            .into_iter()
            .zip(CalendarProperty::known_properties())
            .filter_map(|((_, v), p)| {
                v.map(|value| ListedProperty {
                    resource: PropertyTarget::Collection(collection_href.to_owned()),
                    property: property.clone(),
                    property: p.clone(),
                    value,
                });
            };
        }
        return Ok(props);
                })
            })
            .collect::<Vec<_>>();

        return Ok(result);
    }
}


M vstorage/src/carddav.rs => vstorage/src/carddav.rs +18 -10
@@ 357,18 357,26 @@ where
        &self,
        collection_href: &str,
    ) -> Result<Vec<ListedProperty<AddressBookProperty>>> {
        let mut props = Vec::new();
        for property in AddressBookProperty::known_properties() {
            let prop_value = self.get_property(collection_href, property.clone()).await?;
            if let Some(value) = prop_value {
                props.push(ListedProperty {
        let prop_names = AddressBookProperty::known_properties()
            .iter()
            .map(|p| p.dav_propname())
            .collect::<Vec<_>>();
        let result = self
            .client
            .get_properties(collection_href, &prop_names)
            .await?
            .into_iter()
            .zip(AddressBookProperty::known_properties())
            .filter_map(|((_, v), p)| {
                v.map(|value| ListedProperty {
                    resource: PropertyTarget::Collection(collection_href.to_owned()),
                    property: property.clone(),
                    property: p.clone(),
                    value,
                });
            };
        }
        return Ok(props);
                })
            })
            .collect::<Vec<_>>();

        return Ok(result);
    }
}