|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
mankyd Smarty Regular
Joined: 04 May 2006 Posts: 92 Location: Boston MA
|
Posted: Tue Apr 24, 2007 9:41 pm Post subject: Million Numbers - Own the Number of Your Dreams (parody) |
|
|
Some of you may get a kick out of this:
http://millionnumbers.com/
It's a parody site that I made of some other websites out there that sell numbers, (or paintings of numbers.) I really did it as a one-off weekend project.
It has provided good practice for me with regard to Smarty's caching system. All pages on Million Numbers are cached with caching = 2 and cache_lifetime = -1, (page contents don't change without user interaction.) It also has a non-cached plugin at the top where it shows a random available number. When someone buys a number, changing what's on the site, I call clear_cache() on the appropriate template and cache_id. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Apr 25, 2007 8:03 am Post subject: |
|
|
this is quite funny. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Apr 25, 2007 1:48 pm Post subject: |
|
|
Yes! 101 was available!
For some reason, the front page takes several seconds to come up. I'm not sure whats going on there, maybe it's your random number picker? |
|
Back to top |
|
mankyd Smarty Regular
Joined: 04 May 2006 Posts: 92 Location: Boston MA
|
Posted: Wed Apr 25, 2007 2:11 pm Post subject: |
|
|
Thanks guys
morht: Yeah, that's part of it, (using PostgreSQL.) I think the actual query is
Code: | SELECT number FROM number WHERE state_id = (SELECT id FROM number_state WHERE label = 'AVAILABLE') AND RANDOM() > 0.999 ORDER BY RANDOM(); |
I am going to do some tweaking to optimize it. I think a simple call to mt_rand() paired with a do-while loop for safety would be more efficient since the odds are against choosing a number that's already been purchased.
It's also the fact that not all that not all the browse pages are cached at the moment. When you visit the main page, it randomly returns one of 10,000 browse pages. Each one requires a db call to check on the status of the 100 numbers on the page.
I'm not entirely sure why it goes as slow as it does, though. Each new page has at most 4 db calls (newly purchased, available, popular, and a single query to grab the states of the 100 numbers on the page.) ::shrugs::
If you visit a cached page, it generally loads faster: http://millionnumbers.com/1/ |
|
Back to top |
|
mankyd Smarty Regular
Joined: 04 May 2006 Posts: 92 Location: Boston MA
|
Posted: Wed Apr 25, 2007 2:41 pm Post subject: |
|
|
Actually, upon closer inspection, its not really the random number at all. It has to do with the way PostgreSQL is handling LIMIT/OFFSET. For small offsets, (e.g., http://millionnumbers/1/ or http://millionnumbers.com/10/,) it works just fine. With larger offsets, (e.g., http://millionnumbers.com/8000/,) PostgreSQL starts bogging down, taking several seconds to pull out just 100 records. Once the page is cached, it becomes a non-issue.
Anyone here a query optimization expert ?
edit: all fixed! |
|
Back to top |
|
blackhawkmx Smarty Regular
Joined: 20 May 2005 Posts: 76
|
Posted: Mon Jun 02, 2008 9:52 pm Post subject: |
|
|
awesome and funny
hehe _________________ Bring it back to basics. You and I can make it right! |
|
Back to top |
|
stardom111 Smarty n00b
Joined: 16 Apr 2010 Posts: 3
|
Posted: Fri Apr 16, 2010 3:20 am Post subject: haha |
|
|
lol now that is a laugh |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|