ORDER BY RAND() is notoriously slow for larger data sets.  I'm not sure if
Rails in general has a good solution but here is a database-specific article
about it.

http://www.mysqlperformanceblog.com/2006/09/01/order-by-limit-performance-optimization/

The problem is that this will become a problem as the friends table grows,
not just the number of friends of a specific user.

-Adam

On Mon, Oct 20, 2008 at 8:07 AM, Steven A Bristol
<[EMAIL PROTECTED]>wrote:

>
> On Sun, Oct 19, 2008 at 10:20 PM, Joe Van Dyk <[EMAIL PROTECTED]> wrote:
> >
> > Fixed.
> >
> > diff --git a/app/views/friends/_list.html.erb b/app/views/friends/
> > _list.html.erb
> > index 9578948..edb1e9f 100644
> > --- a/app/views/friends/_list.html.erb
> > +++ b/app/views/friends/_list.html.erb
> > @@ -2,7 +2,7 @@
> >  profile ||= @profile
> >  type ||= 'friends'
> >  size ||= 20
> > -list = profile.send(type).find(:all, :limit => size, :order =>
> > 'RAND()') rescue []
> > +list = profile.send(type).find(:all, :limit => size, :order =>
> > 'RANDOM()') rescue []
> >  total = profile.send(type).count
> >  with_friending ||= false
> >
> >
> > RAND() isn't in postgresql.
> >
> > Joe
> >
> > On Oct 19, 2:36 pm, Joe Van Dyk <[EMAIL PROTECTED]> wrote:
> >> Does anyone else get these test errors?
> >>
> >> Joe
> >>
> >> On Oct 12, 5:20 pm, Joe Van Dyk <[EMAIL PROTECTED]> wrote:
> >>
> >> > Using postgresql on a fresh install of LovdByLess.  Get a bunch of
> >> > these errors when running the tests.  Any ideas?  That query does
> >> > succeed when I run it manually in psql.
> >>
> >> >  25) Error:
> >> > test: rendering an avatar should use the user's icon if it exists.
> >> > (ProfilesControllerTest):
> >> > ActionView::TemplateError: PGError: ERROR:  current transaction is
> >> > aborted, commands ignored until end of transaction block
> >> > : SELECT count(*) AS count_all FROM "profiles"  INNER JOIN friends ON
> >> > profiles.id = friends.invited_id      WHERE (("friends".inviter_id =
> >> > 8950599) AND ((status = 1)))
> >> >     On line #6 of friends/_list.html.erb
> >>
> >> >     3: type ||= 'friends'
> >> >     4: size ||= 20
> >> >     5: list = profile.send(type).find(:all, :limit => size, :order =>
> >> > 'RAND()') rescue []
> >> >     6: total = profile.send(type).count
> >> >     7: with_friending ||= false
> >> >     8:
> >> >     9:
> >>
> >> >     vendor/plugins/rows_logger/init.rb:36:in `log'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/connection_adapters/postgresql_adapter.rb:484:in
> >> > `execute'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/connection_adapters/postgresql_adapter.rb:929:in
> >> > `select_raw'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/connection_adapters/postgresql_adapter.rb:916:in
> >> > `select'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/connection_adapters/abstract/database_statements.rb:7:in
> >> > `select_all_without_query_cache'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/connection_adapters/abstract/query_cache.rb:59:in
> >> > `select_all'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/connection_adapters/abstract/query_cache.rb:80:in
> >> > `cache_sql'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/connection_adapters/abstract/query_cache.rb:59:in
> >> > `select_all'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/connection_adapters/abstract/database_statements.rb:
> >> > 13:in `select_one'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/connection_adapters/abstract/database_statements.rb:
> >> > 19:in `select_value'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/calculations.rb:225:in `execute_simple_calculation'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/calculations.rb:126:in `calculate'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/calculations.rb:122:in `catch'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/calculations.rb:122:in `calculate'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/calculations.rb:48:in `count'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/associations/has_many_through_association.rb:41:in
> >> > `count'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/base.rb:1857:in `with_scope'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/associations/has_many_through_association.rb:41:in
> >> > `send'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/associations/has_many_through_association.rb:41:in
> >> > `count'
> >> >     app/views/friends/_list.html.erb:6:in
> >> > `_run_erb_47app47views47friends47_list46html46erb'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > base.rb:342:in `send'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > base.rb:342:in `execute'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > template_handlers/compilable.rb:29:in `send'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > template_handlers/compilable.rb:29:in `render'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > partial_template.rb:20:in `render'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/benchmarking.rb:26:in `benchmark'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/
> >> > active_support/core_ext/benchmark.rb:8:in `realtime'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/benchmarking.rb:26:in `benchmark'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > partial_template.rb:19:in `render'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > template.rb:22:in `render_template'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > partials.rb:110:in `render_partial'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > base.rb:277:in `render'
> >> >     app/views/profiles/_public.html.erb:64:in
> >> > `_run_erb_47app47views47profiles47_public46html46erb'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > base.rb:342:in `send'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > base.rb:342:in `execute'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > template_handlers/compilable.rb:29:in `send'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > template_handlers/compilable.rb:29:in `render'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > partial_template.rb:20:in `render'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/benchmarking.rb:26:in `benchmark'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/
> >> > active_support/core_ext/benchmark.rb:8:in `realtime'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/benchmarking.rb:26:in `benchmark'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > partial_template.rb:19:in `render'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > template.rb:22:in `render_template'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > partials.rb:110:in `render_partial'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > base.rb:277:in `render'
> >> >     app/views/profiles/show.html.erb:16:in
> >> > `_run_erb_47app47views47profiles47show46html46erb'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > base.rb:342:in `send'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > base.rb:342:in `execute'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > template_handlers/compilable.rb:29:in `send'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > template_handlers/compilable.rb:29:in `render'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > template.rb:35:in `render'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > template.rb:22:in `render_template'
> >> >
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/
> >> > base.rb:248:in `render_file'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/base.rb:1112:in `render_for_file'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/base.rb:845:in `render_with_no_layout'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/layout.rb:251:in `render_without_benchmark'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/benchmarking.rb:51:in `render'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/
> >> > active_support/core_ext/benchmark.rb:8:in `realtime'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/benchmarking.rb:51:in `render'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/base.rb:1161:in `default_render'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/base.rb:1167:in `perform_action_without_filters'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/filters.rb:579:in `call_filters'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/filters.rb:572:in `perform_action_without_benchmark'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/benchmarking.rb:68:in
> >> > `perform_action_without_rescue'
> >> >     /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/benchmarking.rb:68:in
> >> > `perform_action_without_rescue'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/rescue.rb:201:in `perform_action_without_caching'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/caching/sql_cache.rb:13:in `perform_action'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/connection_adapters/abstract/query_cache.rb:33:in
> >> > `cache'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
> >> > active_record/query_cache.rb:8:in `cache'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/caching/sql_cache.rb:12:in `perform_action'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/base.rb:529:in `send'
> >> >     /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
> >> > action_controller/base.rb:529:in `process_without_filters'
> >> >
> >>
> >> ...
> >>
>
>
> got it, thanks!
>
>
> steven bristol
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Lovd by Less" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/lovdbyless?hl=en
Who loves ya baby?
-~----------~----~----~----~------~----~------~--~---

Reply via email to