samvera / active_fedora

A Rails interface to the Fedora repository, akin to ActiveModel
Other
54 stars 63 forks source link

Implement enumeration for `Relation#each` #1353

Closed no-reply closed 6 years ago

no-reply commented 6 years ago

Relation#each had previously delegated to Relation#to_a, which sends N requests to Fedora (plus one to Solr) and loads all the objects into memory before beginning work.

This introduces an Enumerator based implementation, using #find_each. When #to_a has already been called, we take advantage of the existing caching; otherwise we yield items individually.

We also delegate certain other methods to #each instead of #to_a, extending the same benefits to #collect, and getting massively better performance from #blank?, #present?, #include? and #any?. There are probably other optimizations to be explored based on this.

#map is kept as is, since delegating it to #each breaks ordering code. Since it would be rasonable to assume that #map would have effient access properties and not cast to an Array, this should be investigated.