Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide methods to find names of the snapshot collections. #16

Closed
dblock opened this issue Jan 28, 2016 · 1 comment
Closed

Provide methods to find names of the snapshot collections. #16

dblock opened this issue Jan 28, 2016 · 1 comment

Comments

@dblock
Copy link
Contributor

dblock commented Jan 28, 2016

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.

      # 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 = ... client
      recent_indexes = {}
      Mongoid.models.select do |model|
        model.new.respond_to?(:import_version)
      end.each do |model|
        snapshot = from[model.collection.name].find.sort(_id: -1).first
        recent_indexes[model.collection.name] = snapshot['_slugs'].first
      end
      # 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-857
      from_imports = ... client
      collections = from_imports.collections.map(&:name).select do |name|
        recent_indexes.detect do |base_name, slug|
          name =~ /^#{base_name}\.([^\.]+\.)?#{slug}$/
        end
      end

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.

@dblock
Copy link
Contributor Author

dblock commented Jan 20, 2017

Closing in favor of mongoid#5

@dblock dblock closed this as completed Jan 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant