You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a Rake task that copies data from a production database to staging. We only want to copy the most recent snapshots, not everything.
Solution
Reimplement the following, but better.
# find the names of the collections for the most recent index# this generates a hash with entries like {"artist_gene_value_indices"=>"snapshot-794"}from= ... clientrecent_indexes={}Mongoid.models.selectdo |model|
model.new.respond_to?(:import_version)end.eachdo |model|
snapshot=from[model.collection.name].find.sort(_id: -1).firstrecent_indexes[model.collection.name]=snapshot['_slugs'].firstend# select actual collection names# this returns a list like# tag_partitioned_artwork_similarity_indices.output.snapshot-857# tag_partitioned_artwork_similarity_indices.ranked_partitions.snapshot-857from_imports= ... clientcollections=from_imports.collections.map(&:name).selectdo |name|
recent_indexes.detectdo |base_name,slug|
name =~ /^#{base_name}\.([^\.]+\.)?#{slug}$/endend
I think I want to have AverageArtistPrice.latest.collections that returns mongoid collections for each of which we can do documents(collection.name).
Note that we cannot be looking at document_classes because that's constructed on-demand.
The text was updated successfully, but these errors were encountered:
Problem
We have a Rake task that copies data from a production database to staging. We only want to copy the most recent snapshots, not everything.
Solution
Reimplement the following, but better.
I think I want to have
AverageArtistPrice.latest.collections
that returns mongoid collections for each of which we can dodocuments(collection.name)
.Note that we cannot be looking at
document_classes
because that's constructed on-demand.The text was updated successfully, but these errors were encountered: