Conversation
|
|
||
| def id | ||
| _model.public_send(self.class._primary_key) | ||
| @id ||= _model.public_send(self.class._primary_key) |
There was a problem hiding this comment.
Off topic-- we'll want to handle composite primary keys here
There was a problem hiding this comment.
That's an interesting point. I don't see anything in the spec to provide support for a multi attribute composite key in the JSONAPI section on identification. We could attempt to support this in JR by combining the composite key components, but I suspect it's going to run into the same issues I encountered trying to find a way to support an alternate public key field (one different from the primary key in the database). It was a harder problem than I initially thought it would be.
There was a problem hiding this comment.
I figure someone could also just override this method. Since keys need to be consistently ordered, a custom synthetic key would be fine and keep the risk of a spec error off of jsonapi.
There was a problem hiding this comment.
I think that's the way I would handle it too. To work with rails we would need an identity class to convert the composite string keys to an array and back. It would an interesting thing to test.
lib/jsonapi/resource_common.rb
Outdated
| end | ||
|
|
||
| def _clear_cached_resource_types_for_model | ||
| @_cached_resource_types_for_model = {} |
There was a problem hiding this comment.
No sure how allocations differ re garbage collection to set a new ivar vs calling clear
There was a problem hiding this comment.
I'm not sure either. I assume, probably a bad thing to do, that a Set or Has would be cleaned up the same as the values it holds when no longer referenced. But I took a look at the code and reworked how the class variables for the caches are initialized and cleared. Probably doesn't matter much since this is code that's only run at startup. Still I hope it makes it a little clearer.
* Reduce number of string allocations in LinkBuilder * Consistently access `include_related` * Remove unused class variable * Cache `id` after retrieving it from the model * Cache `module_path` * Cache resource_klass_for and resource_type_for * Remove no longer used method _setup_relationship * Delete nil values without creating a new object * Rework resource naming for method caches
Implements some caching of frequently computed values. Significantly reduces allocations and run times for larger requests.
All Submissions:
New Feature Submissions:
Bug fixes and Changes to Core Features:
Test Plan:
Reviewer Checklist: