I have created my first auto-complete fields
(text_field_with_auto_complete) and I find the feature a little slow.
It takes about a second to see the values pop up on screen. I have
tried to play with the :frequency option but I don’t see any
appreciable difference with anything I do to increase the speed of
the feature.
Hi,
Check your database query speed (Check your development.log). If the
database retrieval speed is less, it might bog down the auto-complete
popup.
Add appropriate indexes if that is the case.
Do as little to respond to the auto-complete request. For example, if
you use sessions, turn them off for that request. Pull the results from
a cache if you can.
I have actually tried pretty much everything I could with my limited
knowledge of RoR. One thing I did was to store the results of the
queries in arrays the first time they were loaded and then use the
arrays instead of going to the table again. I have not noticed any
difference in speed in that case. One reason might be that my test
tables don’t have much data.
Thank you for the insight.
Pepe
On Jul 25, 12:07 pm, Jeremy Weiskotten <rails-mailing-l…@andreas-
Certainly also avoid complex SQL queries like table joins and eager
loading to get the content of the auto-complete field. And as
mentioned be absolutely sure that any field used in the WHERE clause
is indexed on the database table.
On Jul 25, 12:07 pm, Jeremy Weiskotten <rails-mailing-l…@andreas-
At any case if you doing ajax request to server autocomplete WILL be
slow. You need to look into AutoCompleter.Local if you have limited
number of options (more than hundred will be overload).
Is this a development environment? If so, in development mode, Rails
does a bunch of work on every request, such as reloading all of the
classes, which doesn’t happen in a production environment.
Try starting your server in production mode (such as mongrel_rails start
-e -production). You’ll need to edit database.yml to point the
production config to your dev database, or set up a production db.
I new that I could use Javascript to hold the values and make the
process faster by letting the browser itself handle the requests but I
am not an expert in web development and I know the minimal Javascript
to go by. One thing I don’t want to do is hard code the values in a
Javascript array like this example shows:
Would it be possible to get some information as to how to load a
Javascript array with the data from model when the action is first
invoked? That would probably be the best way to go.
I am aware of the difference in speed between development and
production environments. You’re right that in production it should be
faster. In addition I am running WEBrick, not Mongrel in my machine.
You’re right, I should switch between environments and see what the
difference might be in production mode and installing Mongrel might
also help.
Thanks.
Pepe
On Jul 25, 10:39 pm, Jeremy Weiskotten <rails-mailing-l…@andreas-
looks like what you want, except that you don’t want to hard code the
array in javascript. I would suggest that you save the information
that you fetch from your database in a javascript array and then use
the local autocompleter from above.
For example, let’s say that you want to autocomplete bands like in the
local autocompleter example. You might have fetched all your band
names in to the variable @band_names, with something like:
@band_names = Band.all.collect {|b| b.name }
And then in your view you can use this javascript to set the
autocompleter array (I’m assuming you are using erb templates):
The speed (or lack of) I’m noticing is during my own testing. I just
would like it to be instantaneous so when somebody types a letter the
list comes up right away instead of waiting for about a second or so.
My test tables contain very little information (4 or 5 records in most
cases) but I still have to wait for that second or so.