Re: shortening the cart

This WebDNA talk-list message is from

1998


It keeps the original formatting.
numero = 18290
interpreted = N
texte = At 6:23 AM 6/17/98, Peter Ostry wrote: >You have to generate it on your own. >Cart numbers can be shorter than 7 digits so I guess the easiest way is to >generate a long number and use the first 7 digits: >[GetChars start=1&end=7][cart][cart][/GetChars]The problem with this approach is that you'll end up with many duplicate cart numbers over the course of a day. A WebCat cart number is simply the date (expressed as days since 00/00/0000) concantinated with the time (seconds since midnight) and number of ticks. So, by taking the first seven digits, you'd be getting the date portion (which is six digits in 1998) and the first digit of the time. Thus, there are only 10 possible cart values for each day, each one possibly being used many times during the day. (see Peter's related post entitled calculating unique time)A more secure approach would be to use the time as base for your cart numbers. Assuming you're expiring the carts in a reasonably short period of time, I would generate the seven-digit number as follows:[Date %w][format .5d][math]{[Time %H:%M:%S]}[/math][/format][format 1s][math][random]-1[/math][/format][Date %w] is the day of the week (1 digit), [format .5d][math]{[Time %H:%M:%S]}[/math][/format] is the time since midnight (5 digits), and [format 1s][math][random]-1[/math][/format] is a random number (1 digit).This will give you (theoretically) up to 10 unique carts per second and allows you to keep your carts for up to a week. If you are expiring carts after 24 hours, you can get rid of the [Date %w] and move from a 1-digit random number to a 2-digit random number, which gives a theoretical limit of 100 unique carts per second.An alternate approach is to keep a database with all of your cart numbers (or even just the most recently assigned cart number). To generate a new cart, you do a search for the greatest cart number in the database and add one to that number (and be sure to update the database). You can start the sequence at whatever number you want and not worry about duplicates until it rolls over.-Daveo--------------- Dave MacLeay --+ o----------- Digital Frontier --+ o--- dave@digitalfrontier.com --+ Associated Messages, from the most recent to the oldest:

    
  1. Re: shortening the cart (Peter Ostry 1998)
  2. Re: shortening the cart (Dave MacLeay 1998)
  3. Re: shortening the cart (Peter Ostry 1998)
  4. Re: shortening the cart (Peter Ostry 1998)
  5. shortening the cart (Kevin Furuta 1998)
At 6:23 AM 6/17/98, Peter Ostry wrote: >You have to generate it on your own. >Cart numbers can be shorter than 7 digits so I guess the easiest way is to >generate a long number and use the first 7 digits: >[GetChars start=1&end=7][cart][cart][/GetChars]The problem with this approach is that you'll end up with many duplicate cart numbers over the course of a day. A WebCat cart number is simply the date (expressed as days since 00/00/0000) concantinated with the time (seconds since midnight) and number of ticks. So, by taking the first seven digits, you'd be getting the date portion (which is six digits in 1998) and the first digit of the time. Thus, there are only 10 possible cart values for each day, each one possibly being used many times during the day. (see Peter's related post entitled calculating unique time)A more secure approach would be to use the time as base for your cart numbers. Assuming you're expiring the carts in a reasonably short period of time, I would generate the seven-digit number as follows:[Date %w][format .5d][math]{[Time %H:%M:%S]}[/math][/format][format 1s][math][random]-1[/math][/format][Date %w] is the day of the week (1 digit), [format .5d][math]{[Time %H:%M:%S]}[/math][/format] is the time since midnight (5 digits), and [format 1s][math][random]-1[/math][/format] is a random number (1 digit).This will give you (theoretically) up to 10 unique carts per second and allows you to keep your carts for up to a week. If you are expiring carts after 24 hours, you can get rid of the [Date %w] and move from a 1-digit random number to a 2-digit random number, which gives a theoretical limit of 100 unique carts per second.An alternate approach is to keep a database with all of your cart numbers (or even just the most recently assigned cart number). To generate a new cart, you do a search for the greatest cart number in the database and add one to that number (and be sure to update the database). You can start the sequence at whatever number you want and not worry about duplicates until it rolls over.-Daveo--------------- Dave MacLeay --+ o----------- Digital Frontier --+ o--- dave@digitalfrontier.com --+ Dave MacLeay

DOWNLOAD WEBDNA NOW!

Top Articles:

Talk List

The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...

Related Readings:

Follow-Up to: Removing [showif] makes a big difference in speed (1997) New public beta available (1997) Re:Merging databases (1997) international time (1997) Search Question (2003) WebCatb15 Mac CGI -- [purchase] (1997) Sorting (2005) [Sum] function? (1997) Help name our technology! I found it (1997) Show shoppingcart after remove last item (1997) problem: mail changed (1997) Serving images from databases (1998) PIXO (1997) Re2: AAgghh!! Help, please. SSL strikes again. (1997) Upgrading old WebCat Database Files (1997) IE Cache Problems... (1999) Listing Words Backwords (2001) Problems with [Applescript] (1997) wc 2 pro users - sites, quotes wanted (1997) [WebDNA] checking for mixed case text (2009)