Hey Guys,
I’m fairly new to Rails, so my guess is that I’m just doing this
wrong. I have a site that I’m building that uses ajax to update a
list of items depending on what tab a user clicks. Unfortunately, it
isn’t live yet so I can’t send a link directly to the site, but I have
it all working using straight HTML/JS/XML. Where the problems start
is when I try to use Rails to generate the update.
At first I tried to use RJS to push a partial template that loops
through each item to generate the html block that I need to push to
the list. I figured this would be easy and straight forward, but even
though I only have 2 items in the DB currently (will eventually be
hundreds) the list was taking 2+ seconds to update even locally. I
even tried changing my technique to use :update on a link_to_remote
instead of the RJS template with no increase performance.
Next I tried leaving the javascript that I was using before in place,
but used a partial template to build the xml file that was requested.
This seemed to help the performance, but I still wasn’t able to
decrease the load time to an acceptable amount.
Lastly, I’m trying to use an rxml template to build the xml instead of
looping within a partial template:
xml.items do
for p in @products
xml.item(:tags => p.tags, :id => p.id) do
xml.title(p.title)
xml.subtitle(truncate(p.description, 100))
xml.summary(truncate(p.description, 100))
xml.description(p.description)
xml.postedby(“Lance 43”, :id=>“12343”)
xml.postedtimestamp(“1144537625”)
xml.images do
xml.image(:id=>1) do
xml.fullsize(p.image)
xml.small(p.image_small)
xml.thumb(p.image_thumb)
end
end
xml.trashed(“990”)
xml.reported(“34”)
xml.views(“1000”)
xml.score(p.overall_score)
xml.points(“40”)
xml.stars(“5”)
xml.links do
xml.link(“link 1”, :id=>“1”, :href=>“http://www.link1.com”)
xml.link(“link 2”, :id=>“2”, :href=>“http://www.link2.com”)
end
xml.comments do
xml.comment(:id=>“1”) do
xml.postedby(“Ross C.”, :id=>“123”)
xml.postedtimestamp(“1144537625”)
xml.content(“This item works well elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Ut wisi enim ad minim veniam, quis”)
end
xml.comment(:id=>“2”) do
xml.postedby(“Peter J.”, :id=>“356”)
xml.postedtimestamp(“1144537172”)
xml.content(“Made some fixes to the wording and did some
other cleaning up. Man people sure spell bad. We should get a grade 10
class to go through this as a challenge.”)
end
end
end
end
end
Most of the above is still static as I haven’t updated the database
schema yet to include a lot of the fields. I want to try to get this
up and running properly before I go any further on other development.
This seems to get an initial load time of about a second, but then it
caches and goes blazingly fast. I’m currently on Dreamhost, and am
wondering if the slowness may be a factor of the host and not the
code.
Please guys, any help would be GREATLY appreciated as I’m getting
close to ditching rails for this project all together and moving back
to PHP.
Matt