Guest User

Untitled

a guest
May 9th, 2018
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #Embedded vs link
  2.  
  3. #I'm looking for the fastest way to search a Newsletter document for a connected Email. So far I have used
  4. #MongoMapper with one document for Newsletter and another for Email. This is getting really slow with +100k
  5. #Emails.
  6.  
  7. #I was thinking maybe its faster to embed the emails in an array inside Newsletter
  8. #since I'm really only interested in the email ('someemail@email.com')
  9. #and not any logic around it.
  10.  
  11. #1) Is it possible at all to embed as much as 100k-500k emails in one document?
  12. #2) Is Mongoid better/faster for this?
  13.  
  14. #I'm adding the email if it is not already in the collection by asking
  15.  
  16. email = newsletter.emails.first(:email => 'someemail@email.com')
  17. unless email
  18. email = Email.new(:email => 'someemail@email.com', :newsletter_id => self.id)
  19. email.save
  20. end
  21.  
  22. #And I think this is where it all starts to hurt.
  23.  
  24. #Here is how they are connected
  25. Class Newsletter
  26. include MongoMapper::Document
  27. many :emails
  28. ...
  29. end
  30.  
  31. Class Email
  32. include MongoMapper::Document
  33. key :email, String
  34. key :newsletter_id, ObjectId
  35. belongs_to :newsletter
  36. end
  37.  
  38.  
  39. #would love for any help on this :)
Add Comment
Please, Sign In to add comment