Prev | Current Page 227 | Next

David Berube

"Practical Reporting with Ruby and Rails"

You
can speed up the queries in a few ways.
For example, the call to user.meetings.count means that you have one extra SQL query per
user. This could be a problem when you need to count a large number of records. Fortunately, Rails can
automatically cache the count of relationships for you. In the example, this approach won??™t work. That??™s
because SugarCRM won??™t update the cache for you, and since it will be updating the table, that would
leave you with an invalid cache. However, in situations where only your Rails application accesses the
database, adding a counter cache could speed up your report??™s performance significantly.
Counter caching has a few caveats. One is that the counter may be invalid if your database is
accessed outside your Rails applications. Also, it won??™t work if you manually set association IDs instead
of using association proxies. You can find out more about using counter caches at http://wiki.
rubyonrails.org/rails/pages/MagicFieldNames.
You can create a counter cache by adding a column called meetings_count, with a default value
of 0, to the users table.


Pages:
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
sprzedam psa muzyczka Marquess Sophie Milman baseny ogrodowe