4 ms·
Smart. Still, the db request SELECT name FROM friends WHERE source = %(source) should probably be pretty cheap given proper indexes, and could be done inline, w
by jamesaguilar 16y ago
Smart. Still, the db request SELECT name FROM friends WHERE source = %(source) should probably be pretty cheap given proper indexes, and could be done inline, whereas lookups for each person are likely much more expensive. You could still send the JSON in the same request by composing the cached page with the dynamic friendlist. Now all we need is for someone to make it happen.
*Pardon my broken SQL, I don't actually know the language.
- jonknee 16y agoWhat I was suggesting is do the SELECT name FROM friends query as part of the initial page load, not as a secondary AJAX request. Store the results as JSON that gets put into the page, then use JS to manipulate the comments client side. As you noted it should be cheap and as others noted, quite cacheable (friends don't change frequently).
- aarongough 16y agoUnfortunately if you are sending the friend list as part of the cached page then you won't be able to use that cached page for all users. I believe the original comment was that each comments page should be cached globally and then each user can have their friend list & dynamic data fetched separately and added to the page using javascript.
- jemfinch 16y agoThe comments page would be cached globally; the json friends list would just be inserted as the cached page is served to the user.
- jonknee 16y agoAh, my bad then. I don't think the comments pages cache well though--the votes are always going up and down. My understanding that in addition to pulling all the comments for each request they were also pulling the friend relationships for the current user with all the participants.
- gridspy 16y agoWho cares if the votes are say 1 minute out of date? Even caching a 2000 comment thread for a minute would significantly speed up that page.
- jonknee 16y agoI think it would be confusing to post a comment and have it disappear after a refresh. Same for votes.
- jemfinch 16y agoThe page would be regenerated on each new comment, of course. Votes should be done the same way friends' lists are: on the client side, via javascript. The cached page with its comments would include Javascript to grab the most current scores for all its posts (one request) and modify the DOM appropriately.
- joevandyk 16y agoYou could if using SSI (say, with nginx or varnish). <html> <cached comments here> <!ssi include="/load-json" /> </html>