@@ -69,27 +69,18 @@ use crate::{
6969 TableIterator ,
7070} ;
7171
72- pub const KB : u64 = 1 << 10 ;
73-
74- pub fn round_up ( n : u64 , k : u64 ) -> u64 {
75- ( n + k - 1 ) / k * k
76- }
77-
7872#[ derive( Debug , Clone , PartialEq , Eq ) ]
7973pub struct TableSummary {
8074 inferred_type : CountedShape < ProdConfigWithOptionalFields > ,
8175 total_size : i64 ,
82- // Used for metered billing, we charge for database storage rounded up to
83- // the nearest KB per document
84- total_size_rounded : Option < i64 > ,
8576}
8677
8778impl fmt:: Display for TableSummary {
8879 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
8980 write ! (
9081 f,
91- "TableSummary {{ inferred_type: {}, total_size: {} , total_size_rounded: {:?} }}" ,
92- self . inferred_type, self . total_size, self . total_size_rounded
82+ "TableSummary {{ inferred_type: {}, total_size: {} }}" ,
83+ self . inferred_type, self . total_size
9384 )
9485 }
9586}
@@ -99,7 +90,6 @@ impl TableSummary {
9990 Self {
10091 inferred_type : Shape :: empty ( ) ,
10192 total_size : 0 ,
102- total_size_rounded : None ,
10393 }
10494 }
10595
@@ -121,36 +111,17 @@ impl TableSummary {
121111
122112 pub fn insert ( & self , object : & ConvexObject ) -> Self {
123113 let total_size = self . total_size + object. size ( ) as i64 ;
124- let total_size_rounded = match self . total_size_rounded {
125- Some ( total_size_rounded) => {
126- Some ( total_size_rounded + round_up ( object. size ( ) as u64 , KB ) as i64 )
127- } ,
128- None => None ,
129- } ;
130114 Self {
131115 inferred_type : self . inferred_type . insert ( object) ,
132116 total_size,
133- total_size_rounded,
134117 }
135118 }
136119
137120 pub fn remove ( & self , object : & ConvexObject ) -> anyhow:: Result < Self > {
138121 let size = object. size ( ) as i64 ;
139- let total_size_rounded = match self . total_size_rounded {
140- Some ( total_size_rounded) => {
141- let size_rounded = round_up ( object. size ( ) as u64 , KB ) as i64 ;
142- anyhow:: ensure!(
143- total_size_rounded >= size_rounded,
144- "Negative size due to {object}"
145- ) ;
146- Some ( total_size_rounded - size_rounded)
147- } ,
148- None => None ,
149- } ;
150122 Ok ( Self {
151123 inferred_type : self . inferred_type . remove ( object) ?,
152124 total_size : self . total_size - size,
153- total_size_rounded,
154125 } )
155126 }
156127
@@ -165,17 +136,10 @@ impl TableSummary {
165136
166137impl From < & TableSummary > for JsonValue {
167138 fn from ( summary : & TableSummary ) -> Self {
168- match summary. total_size_rounded {
169- Some ( total_size_rounded) => json ! ( {
170- "totalSize" : JsonInteger :: encode( summary. total_size) ,
171- "totalSizeRounded" : JsonInteger :: encode( total_size_rounded) ,
172- "inferredTypeWithOptionalFields" : JsonValue :: from( & summary. inferred_type)
173- } ) ,
174- None => json ! ( {
175- "totalSize" : JsonInteger :: encode( summary. total_size) ,
176- "inferredTypeWithOptionalFields" : JsonValue :: from( & summary. inferred_type)
177- } ) ,
178- }
139+ json ! ( {
140+ "totalSize" : JsonInteger :: encode( summary. total_size) ,
141+ "inferredTypeWithOptionalFields" : JsonValue :: from( & summary. inferred_type)
142+ } )
179143 }
180144}
181145
@@ -190,22 +154,13 @@ impl TryFrom<JsonValue> for TableSummary {
190154 _ => anyhow:: bail!( "Invalid totalSize" ) ,
191155 } ;
192156 anyhow:: ensure!( total_size >= 0 ) ;
193- let total_size_rounded = match v. remove ( "totalSizeRounded" ) {
194- Some ( JsonValue :: String ( s) ) => {
195- let total_size_rounded = JsonInteger :: decode ( s) ?;
196- anyhow:: ensure!( total_size_rounded >= 0 ) ;
197- Some ( total_size_rounded)
198- } ,
199- _ => None ,
200- } ;
201157 let inferred_type = match v. remove ( "inferredTypeWithOptionalFields" ) {
202158 Some ( v) => CountedShape :: < ProdConfigWithOptionalFields > :: try_from ( v) ?,
203159 None => anyhow:: bail!( "Missing field inferredTypeWithOptionalFields" ) ,
204160 } ;
205161 Ok ( TableSummary {
206162 inferred_type,
207163 total_size,
208- total_size_rounded,
209164 } )
210165 } ,
211166 _ => anyhow:: bail!( "Wrong type of json value for TableSummaryJson" ) ,
0 commit comments