@@ -32,7 +32,7 @@ impl GridController {
32
32
}
33
33
34
34
/// Rolls back unsaved transactions to apply earlier transactions received from the server.
35
- fn rollback_unsaved_transactions ( & mut self ) {
35
+ fn rollback_unsaved_transactions ( & mut self , transaction : & mut PendingTransaction ) {
36
36
if self . transactions . unsaved_transactions . is_empty ( ) {
37
37
return ;
38
38
}
@@ -50,10 +50,11 @@ impl GridController {
50
50
} ;
51
51
self . start_transaction ( & mut rollback) ;
52
52
rollback. send_transaction ( ) ;
53
+ transaction. add_updates_from_transaction ( rollback) ;
53
54
}
54
55
55
56
/// Reapplies the rolled-back unsaved transactions after adding earlier transactions.
56
- fn reapply_unsaved_transactions ( & mut self ) {
57
+ fn reapply_unsaved_transactions ( & mut self , transaction : & mut PendingTransaction ) {
57
58
if self . transactions . unsaved_transactions . is_empty ( ) {
58
59
return ;
59
60
}
@@ -74,6 +75,7 @@ impl GridController {
74
75
} ;
75
76
self . start_transaction ( & mut reapply) ;
76
77
reapply. send_transaction ( ) ;
78
+ transaction. add_updates_from_transaction ( reapply) ;
77
79
}
78
80
79
81
/// Used by the server to apply transactions. Since the server owns the sequence_num,
@@ -123,7 +125,11 @@ impl GridController {
123
125
124
126
/// Check the out_of_order_transactions to see if they are next in order. If so, we remove them from
125
127
/// out_of_order_transactions and apply their operations.
126
- fn apply_out_of_order_transactions ( & mut self , mut sequence_num : u64 ) {
128
+ fn apply_out_of_order_transactions (
129
+ & mut self ,
130
+ transaction : & mut PendingTransaction ,
131
+ mut sequence_num : u64 ,
132
+ ) {
127
133
// nothing to do here
128
134
if self . transactions . out_of_order_transactions . is_empty ( ) {
129
135
self . transactions . last_sequence_num = sequence_num;
@@ -154,7 +160,7 @@ impl GridController {
154
160
} ;
155
161
self . start_transaction ( & mut out_of_order_transaction) ;
156
162
out_of_order_transaction. send_transaction ( ) ;
157
-
163
+ transaction . add_updates_from_transaction ( out_of_order_transaction ) ;
158
164
self . transactions . last_sequence_num = sequence_num;
159
165
}
160
166
@@ -176,23 +182,23 @@ impl GridController {
176
182
if index == 0 {
177
183
self . transactions . unsaved_transactions . remove ( index) ;
178
184
self . mark_transaction_sent ( transaction. id ) ;
179
- self . apply_out_of_order_transactions ( sequence_num) ;
185
+ self . apply_out_of_order_transactions ( transaction , sequence_num) ;
180
186
}
181
187
// otherwise we need to rollback all transaction and properly apply it
182
188
else {
183
- self . rollback_unsaved_transactions ( ) ;
189
+ self . rollback_unsaved_transactions ( transaction ) ;
184
190
self . transactions . unsaved_transactions . remove ( index) ;
185
191
self . mark_transaction_sent ( transaction. id ) ;
186
192
self . start_transaction ( transaction) ;
187
- self . apply_out_of_order_transactions ( sequence_num) ;
188
- self . reapply_unsaved_transactions ( ) ;
193
+ self . apply_out_of_order_transactions ( transaction , sequence_num) ;
194
+ self . reapply_unsaved_transactions ( transaction ) ;
189
195
}
190
196
} else {
191
197
// If the transaction is not one of ours, then we just apply the transaction after rolling back any unsaved transactions
192
- self . rollback_unsaved_transactions ( ) ;
198
+ self . rollback_unsaved_transactions ( transaction ) ;
193
199
self . start_transaction ( transaction) ;
194
- self . apply_out_of_order_transactions ( sequence_num) ;
195
- self . reapply_unsaved_transactions ( ) ;
200
+ self . apply_out_of_order_transactions ( transaction , sequence_num) ;
201
+ self . reapply_unsaved_transactions ( transaction ) ;
196
202
197
203
// We do not need to render a thumbnail unless we have outstanding unsaved transactions.
198
204
// Note: this may result in a thumbnail being unnecessarily generated by a user who's
@@ -228,7 +234,7 @@ impl GridController {
228
234
transaction_type : TransactionType :: Multiplayer ,
229
235
..Default :: default ( )
230
236
} ;
231
- self . rollback_unsaved_transactions ( ) ;
237
+ self . rollback_unsaved_transactions ( & mut results ) ;
232
238
233
239
// combine all transaction into one transaction
234
240
transactions. into_iter ( ) . for_each ( |t| {
@@ -245,25 +251,14 @@ impl GridController {
245
251
} ;
246
252
247
253
self . client_apply_transaction ( & mut transaction, t. sequence_num ) ;
248
- results. generate_thumbnail |= transaction. generate_thumbnail ;
249
- results. validations . extend ( transaction. validations ) ;
250
- results. dirty_hashes . extend ( transaction. dirty_hashes ) ;
251
- results. sheet_borders . extend ( transaction. sheet_borders ) ;
252
- results. code_cells . extend ( transaction. code_cells ) ;
253
- results. html_cells . extend ( transaction. html_cells ) ;
254
- results. image_cells . extend ( transaction. image_cells ) ;
255
- results. fill_cells . extend ( transaction. fill_cells ) ;
256
- results. sheet_info . extend ( transaction. sheet_info ) ;
257
- results
258
- . offsets_modified
259
- . extend ( transaction. offsets_modified ) ;
254
+ results. add_updates_from_transaction ( transaction) ;
260
255
} else {
261
256
dbgjs ! (
262
257
"Unable to decompress and deserialize operations in received_transactions()"
263
258
) ;
264
259
}
265
260
} ) ;
266
- self . reapply_unsaved_transactions ( ) ;
261
+ self . reapply_unsaved_transactions ( & mut results ) ;
267
262
self . finalize_transaction ( results) ;
268
263
}
269
264
0 commit comments