@@ -76,19 +76,15 @@ pub fn notional_bag_for<T: Config>(weight: VoteWeight) -> VoteWeight {
7676pub struct List < T : Config > ( PhantomData < T > ) ;
7777
7878impl < T : Config > List < T > {
79- /// Remove all data associated with the list from storage. Parameter `items` is the number of
80- /// items to clear from the list.
79+ /// Remove all data associated with the list from storage.
8180 ///
8281 /// ## WARNING
8382 ///
84- /// `None` will clear all items and should generally not be used in production as it could lead
85- /// to a very large number of storage accesses.
86- pub ( crate ) fn clear ( maybe_count : Option < u32 > ) -> u32 {
87- crate :: ListBags :: < T > :: remove_all ( maybe_count) ;
88- let pre = crate :: ListNodes :: < T > :: count ( ) ;
89- crate :: ListNodes :: < T > :: remove_all ( maybe_count) ;
90- let post = crate :: ListNodes :: < T > :: count ( ) ;
91- pre. saturating_sub ( post)
83+ /// this function should generally not be used in production as it could lead to a very large
84+ /// number of storage accesses.
85+ pub ( crate ) fn unsafe_clear ( ) {
86+ crate :: ListBags :: < T > :: remove_all ( None ) ;
87+ crate :: ListNodes :: < T > :: remove_all ( ) ;
9288 }
9389
9490 /// Regenerate all of the data from the given ids.
@@ -100,11 +96,14 @@ impl<T: Config> List<T> {
10096 /// pallet using this `List`.
10197 ///
10298 /// Returns the number of ids migrated.
103- pub fn regenerate (
99+ pub fn unsafe_regenerate (
104100 all : impl IntoIterator < Item = T :: AccountId > ,
105101 weight_of : Box < dyn Fn ( & T :: AccountId ) -> VoteWeight > ,
106102 ) -> u32 {
107- Self :: clear ( None ) ;
103+ // NOTE: This call is unsafe for the same reason as SortedListProvider::unsafe_regenerate.
104+ // I.e. because it can lead to many storage accesses.
105+ // So it is ok to call it as caller must ensure the conditions.
106+ Self :: unsafe_clear ( ) ;
108107 Self :: insert_many ( all, weight_of)
109108 }
110109
0 commit comments