@@ -748,47 +748,19 @@ OpResult<JsonCallbackResult<T>> JsonReadOnlyOperation(const OpArgs& op_args, std
748
748
return json_path.ExecuteReadOnlyCallback <T>(json_val, cb, options.cb_result_options );
749
749
}
750
750
751
- struct MutateOperationOptions {
752
- using PostMutateCallback = absl::FunctionRef<OpStatus(JsonType*)>;
753
-
754
- std::optional<PostMutateCallback> post_mutate_cb;
755
- CallbackResultOptions cb_result_options = CallbackResultOptions::DefaultMutateOptions();
756
- };
757
-
758
751
template <typename T>
759
- OpResult<JsonCallbackResult<optional<T>>> JsonMutateOperation (const OpArgs& op_args,
760
- std::string_view key,
761
- const WrappedJsonPath& json_path,
762
- JsonPathMutateCallback<T> cb,
763
- MutateOperationOptions options = {}) {
752
+ OpResult<JsonCallbackResult<optional<T>>> JsonMutateOperation (
753
+ const OpArgs& op_args, std::string_view key, const WrappedJsonPath& json_path,
754
+ JsonPathMutateCallback<T> cb,
755
+ CallbackResultOptions cb_result_options = CallbackResultOptions::DefaultMutateOptions()) {
764
756
auto it_res = op_args.GetDbSlice ().FindMutable (op_args.db_cntx , key, OBJ_JSON);
765
757
RETURN_ON_BAD_STATUS (it_res);
766
758
767
- JsonMemTracker mem_tracker;
768
-
769
- PrimeValue& pv = it_res->it ->second ;
770
-
771
- JsonType* json_val = pv.GetJson ();
772
- DCHECK (json_val) << " should have a valid JSON object for key '" << key << " ' the type for it is '"
773
- << pv.ObjType () << " '" ;
774
-
775
- op_args.shard ->search_indices ()->RemoveDoc (key, op_args.db_cntx , pv);
776
-
777
- auto mutate_res = json_path.ExecuteMutateCallback (json_val, cb, options.cb_result_options );
759
+ JsonAutoUpdater updater (op_args, key, *std::move (it_res));
778
760
779
- // Call post mutate callback
780
- if (mutate_res && options.post_mutate_cb ) {
781
- auto res = options.post_mutate_cb .value ()(json_val);
782
- // We can not return result here, because we need to update the size
783
- if (res != OpStatus::OK) {
784
- mutate_res = res;
785
- }
786
- }
761
+ auto mutate_res = json_path.ExecuteMutateCallback (updater.GetJson (), cb, cb_result_options);
787
762
788
- // we need to manually run this before the PostUpdater run
789
- mem_tracker.SetJsonSize (pv, false );
790
- it_res->post_updater .Run ();
791
- op_args.shard ->search_indices ()->AddDoc (key, op_args.db_cntx , pv);
763
+ updater.SetJsonSize ();
792
764
793
765
return mutate_res;
794
766
}
@@ -1223,7 +1195,7 @@ auto OpArrPop(const OpArgs& op_args, string_view key, WrappedJsonPath& path, int
1223
1195
return {false , std::move (str)};
1224
1196
};
1225
1197
return JsonMutateOperation<std::string>(op_args, key, path, std::move (cb),
1226
- {{}, CallbackResultOptions{OnEmpty::kSendNil } });
1198
+ CallbackResultOptions{OnEmpty::kSendNil });
1227
1199
}
1228
1200
1229
1201
// Returns numeric vector that represents the new length of the array at each path.
0 commit comments