@@ -69,27 +69,18 @@ use crate::{
69
69
TableIterator ,
70
70
} ;
71
71
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
-
78
72
#[ derive( Debug , Clone , PartialEq , Eq ) ]
79
73
pub struct TableSummary {
80
74
inferred_type : CountedShape < ProdConfigWithOptionalFields > ,
81
75
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 > ,
85
76
}
86
77
87
78
impl fmt:: Display for TableSummary {
88
79
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
89
80
write ! (
90
81
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
93
84
)
94
85
}
95
86
}
@@ -99,7 +90,6 @@ impl TableSummary {
99
90
Self {
100
91
inferred_type : Shape :: empty ( ) ,
101
92
total_size : 0 ,
102
- total_size_rounded : None ,
103
93
}
104
94
}
105
95
@@ -121,36 +111,17 @@ impl TableSummary {
121
111
122
112
pub fn insert ( & self , object : & ConvexObject ) -> Self {
123
113
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
- } ;
130
114
Self {
131
115
inferred_type : self . inferred_type . insert ( object) ,
132
116
total_size,
133
- total_size_rounded,
134
117
}
135
118
}
136
119
137
120
pub fn remove ( & self , object : & ConvexObject ) -> anyhow:: Result < Self > {
138
121
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
- } ;
150
122
Ok ( Self {
151
123
inferred_type : self . inferred_type . remove ( object) ?,
152
124
total_size : self . total_size - size,
153
- total_size_rounded,
154
125
} )
155
126
}
156
127
@@ -165,17 +136,10 @@ impl TableSummary {
165
136
166
137
impl From < & TableSummary > for JsonValue {
167
138
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
+ } )
179
143
}
180
144
}
181
145
@@ -190,22 +154,13 @@ impl TryFrom<JsonValue> for TableSummary {
190
154
_ => anyhow:: bail!( "Invalid totalSize" ) ,
191
155
} ;
192
156
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
- } ;
201
157
let inferred_type = match v. remove ( "inferredTypeWithOptionalFields" ) {
202
158
Some ( v) => CountedShape :: < ProdConfigWithOptionalFields > :: try_from ( v) ?,
203
159
None => anyhow:: bail!( "Missing field inferredTypeWithOptionalFields" ) ,
204
160
} ;
205
161
Ok ( TableSummary {
206
162
inferred_type,
207
163
total_size,
208
- total_size_rounded,
209
164
} )
210
165
} ,
211
166
_ => anyhow:: bail!( "Wrong type of json value for TableSummaryJson" ) ,
0 commit comments