-
Notifications
You must be signed in to change notification settings - Fork 807
Description
I noticed a few problems with the update callback on models with #as_indexed_json
defined.
Fairly minor, but if you look at this line you'll notice that #as_indexed_json
is called once for each changed field, which is pretty suboptimal if #as_indexed_json
is at all complex. This is clearly solvable fairly easily.
A little more concerning is that with #as_indexed_json
defined, the optimization of checking for changes only saves bandwidth when sending to elasticsearch which is probably a rather minor concern, especially because if you defined #as_indexed_json
, it's probably so that you can index associated objects, and the DB requests to fetch those objects will take far longer than sending an extra few bytes to elasticsearch.
Without #as_indexed_json
defined, you're not saving any DB requests, since I believe the entire object must necessarily be loaded already and there's no possibility of associated objects being defined. I won't question this case here.
The major issue, and why I'm writing this at all, is that the dirty checking completely breaks updates to any fields that are not named the same as or directly map to a database attribute in the indexed json. Say you have a #name
method in your model that forms the full name from #first_name
and #last_name
, and you add this as the name
field in #as_indexed_json
. As far as I can tell, there's no way #name
will ever get updated by the callbacks, and there's not even an override option that I can see.
I propose we just disable the dirty-checking optimization when #as_indexed_json
is defined. What do you think?