ruby on rails - Optimizing queries which priortize non-empty text fields -


i'm working on large, long-running rails monolith using mongoid. i've been asked find , optimize slow running queries, i've started doing of mlab plugin in heroku.

this query (some column names redacted) comes number 1 slowest running function:

{   "status":"<val>",   "from":{"$regex":"<val>","$options":"<val>"},   "text":{"$regex":"<val>","$options":"<val>"},   "field_x":{"$gte":"<val>"},   "field_y":{"$gte":"<val>"},   "field_z":{"$gte":"<val>"} } 

mlab gives recommendations improve slow running queries , i've added index suggested, wonder if can make rails query better. looks (model names changed):

@reviews = object.reviews.active.and(:text.ne => nil, :text.ne => '').desc(:created_at) @reviews += object.reviews.active.any_of({text: nil}, {text: ''}).desc(:created_at) 

i did not write code, understand it, wants prioritize reviews text 5-star review text omg, totally amaze-ballz listed above 5-star review no text. there better, more efficient write this?


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -