Commit d22a52d
Refactor ManagedEntry serialization with adapter pattern
This commit implements a comprehensive refactoring of ManagedEntry
serialization to address inconsistencies across stores and wrappers.
Changes:
- Created SerializationAdapter base class with three implementations:
- FullJsonAdapter: For Redis/Valkey (full JSON string)
- StringifiedDictAdapter: For MongoDB (dict with stringified value)
- ElasticsearchAdapter: For Elasticsearch (native or stringified)
- Updated stores to use serialization adapters:
- MongoDB: Uses StringifiedDictAdapter
- Elasticsearch: Uses ElasticsearchAdapter with native_storage flag
- Redis: Uses FullJsonAdapter
- Fixed wrapper size calculation inefficiency:
- Added estimate_serialized_size() utility function
- Updated CompressionWrapper and LimitSizeWrapper to use utility
- Eliminates unnecessary ManagedEntry instantiation
- Removed deprecated helper functions:
- Removed managed_entry_to_document/document_to_managed_entry from MongoDB
- Removed managed_entry_to_document/source_to_managed_entry from Elasticsearch
- Removed managed_entry_to_json/json_to_managed_entry from Redis
- Updated test files to use new adapter-based approach
Benefits:
- Consistent serialization interface across all stores
- Separation of concerns (serialization logic in adapters)
- Easier to add new stores or modify serialization
- More efficient size calculations in wrappers
- Better testability and maintainability
Related to issue #165
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: William Easton <[email protected]>1 parent 23f4a9c commit d22a52d
File tree
18 files changed
+333
-300
lines changed- key-value
- key-value-aio
- src/key_value/aio
- stores
- elasticsearch
- mongodb
- redis
- wrappers
- compression
- limit_size
- tests/stores
- elasticsearch
- mongodb
- redis
- key-value-sync
- src/key_value/sync/code_gen
- stores
- elasticsearch
- mongodb
- redis
- wrappers
- compression
- limit_size
- tests/code_gen/stores
- elasticsearch
- mongodb
- redis
18 files changed
+333
-300
lines changedLines changed: 18 additions & 58 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | 88 | | |
136 | 89 | | |
137 | 90 | | |
| |||
145 | 98 | | |
146 | 99 | | |
147 | 100 | | |
| 101 | + | |
| 102 | + | |
148 | 103 | | |
149 | 104 | | |
150 | 105 | | |
| |||
208 | 163 | | |
209 | 164 | | |
210 | 165 | | |
| 166 | + | |
211 | 167 | | |
212 | 168 | | |
213 | 169 | | |
| |||
260 | 216 | | |
261 | 217 | | |
262 | 218 | | |
263 | | - | |
| 219 | + | |
264 | 220 | | |
265 | 221 | | |
266 | 222 | | |
| |||
293 | 249 | | |
294 | 250 | | |
295 | 251 | | |
296 | | - | |
| 252 | + | |
297 | 253 | | |
298 | 254 | | |
299 | 255 | | |
| |||
324 | 280 | | |
325 | 281 | | |
326 | 282 | | |
327 | | - | |
328 | | - | |
329 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
330 | 288 | | |
331 | 289 | | |
332 | 290 | | |
| |||
364 | 322 | | |
365 | 323 | | |
366 | 324 | | |
367 | | - | |
368 | | - | |
369 | | - | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
370 | 330 | | |
371 | 331 | | |
372 | 332 | | |
| |||
Lines changed: 15 additions & 40 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | 37 | | |
73 | 38 | | |
74 | 39 | | |
75 | 40 | | |
76 | 41 | | |
77 | 42 | | |
| 43 | + | |
78 | 44 | | |
79 | 45 | | |
80 | 46 | | |
| |||
131 | 97 | | |
132 | 98 | | |
133 | 99 | | |
| 100 | + | |
134 | 101 | | |
135 | 102 | | |
136 | 103 | | |
| |||
187 | 154 | | |
188 | 155 | | |
189 | 156 | | |
190 | | - | |
| 157 | + | |
191 | 158 | | |
192 | 159 | | |
193 | 160 | | |
| |||
205 | 172 | | |
206 | 173 | | |
207 | 174 | | |
208 | | - | |
| 175 | + | |
209 | 176 | | |
210 | 177 | | |
211 | 178 | | |
| |||
217 | 184 | | |
218 | 185 | | |
219 | 186 | | |
220 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
221 | 192 | | |
222 | 193 | | |
223 | 194 | | |
| |||
248 | 219 | | |
249 | 220 | | |
250 | 221 | | |
251 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
252 | 227 | | |
253 | 228 | | |
254 | 229 | | |
| |||
Lines changed: 22 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | 24 | | |
55 | 25 | | |
56 | 26 | | |
57 | 27 | | |
| 28 | + | |
58 | 29 | | |
59 | 30 | | |
60 | 31 | | |
| |||
111 | 82 | | |
112 | 83 | | |
113 | 84 | | |
| 85 | + | |
114 | 86 | | |
115 | 87 | | |
116 | 88 | | |
| |||
123 | 95 | | |
124 | 96 | | |
125 | 97 | | |
126 | | - | |
| 98 | + | |
127 | 99 | | |
128 | 100 | | |
129 | 101 | | |
| |||
139 | 111 | | |
140 | 112 | | |
141 | 113 | | |
142 | | - | |
| 114 | + | |
143 | 115 | | |
144 | 116 | | |
145 | 117 | | |
| |||
155 | 127 | | |
156 | 128 | | |
157 | 129 | | |
158 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
159 | 135 | | |
160 | 136 | | |
161 | 137 | | |
| |||
181 | 157 | | |
182 | 158 | | |
183 | 159 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
188 | 167 | | |
189 | 168 | | |
190 | 169 | | |
| |||
198 | 177 | | |
199 | 178 | | |
200 | 179 | | |
201 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
202 | 185 | | |
203 | 186 | | |
204 | 187 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
0 commit comments