简体   繁体   中英

Avoiding select * queries in meta_search

I'm using meta_search gem on a rails 3 site and I'm finding some performance problems with the select * queries generated by meta_search fetching the BLOB fields in the DB schema. I am not willing to migrate the underlying schema to solve this problem. Is there a way to include/exclude certain fields from the search query that get generated by meta_search?

The mechanism to define which fields are returned in a query within Rails Active Record is .select(...) which by default is * . Check this SO answer for a way of defining a default scope that includes everything except the one field.

A warning about this, however, is that you'll need to override the default scope when you want to write to the table -- once you use .select the fields are read-only.

I use the successor to meta_search called ransack , and given how brilliant its author Ernie Miller is, chances are there's a built in way to do this :-)

Blobs seemed like such a good idea when I first started using them ... but, eh, not so much.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM