Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Million Numbers - Own the Number of Your Dreams (parody)

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Showcase
View previous topic :: View next topic  
Author Message
mankyd
Smarty Regular


Joined: 04 May 2006
Posts: 92
Location: Boston MA

PostPosted: Tue Apr 24, 2007 9:41 pm    Post subject: Million Numbers - Own the Number of Your Dreams (parody) Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Apr 25, 2007 8:03 am    Post subject: Reply with quote

this is quite funny. Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Apr 25, 2007 1:48 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mankyd
Smarty Regular


Joined: 04 May 2006
Posts: 92
Location: Boston MA

PostPosted: Wed Apr 25, 2007 2:11 pm    Post subject: Reply with quote

Thanks guys Smile

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
View user's profile Send private message
mankyd
Smarty Regular


Joined: 04 May 2006
Posts: 92
Location: Boston MA

PostPosted: Wed Apr 25, 2007 2:41 pm    Post subject: Reply with quote

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 Smile ?

edit: all fixed!
Back to top
View user's profile Send private message
blackhawkmx
Smarty Regular


Joined: 20 May 2005
Posts: 76

PostPosted: Mon Jun 02, 2008 9:52 pm    Post subject: Reply with quote

awesome and funny

hehe
_________________
Bring it back to basics. You and I can make it right!
Back to top
View user's profile Send private message
stardom111
Smarty n00b


Joined: 16 Apr 2010
Posts: 3

PostPosted: Fri Apr 16, 2010 3:20 am    Post subject: haha Reply with quote

lol now that is a laugh
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Showcase All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP