Re: find() performance

askegg
Sun, 17 Dec 2006 23:22:09 -0000

That seems like a reasonable approach to me, assuming you configure the
routes accordingly.
Performance will be slower due to the nature of the search, but not by
much.  I would suggest dropping an index onto the name field.

On Dec 18, 10:16 am, "Chad Arimura"
<carim...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> I want my application URL''s to have the name of products in the
URL as
> opposed to the id, like so:
>
> /product/windows+xp instead of /product/view/1
> /product/windows+xp/edit instead of /product/edit/1
>
> I assume the best way then would be in the controller to use:
>
> def view
>   @product = Product.find_by_name(params[:name])
> end
>
> instead of
>
> def view
>   @product = Product.find(params[:id])
> end
>
> So my question is:
>
> 1) Would find_by_name degrade performance significantly because
I''m
> searching by name now and not by row?
>
> If so, 2) is there a better way to handle the find in a more efficient way
> and still use the string name in the URL''s?
>
> Happy holidays,
> Chad