Re: How to track # of file downloads (DB or File)

2009-02-17 Thread Mike Cook

On Feb 17, 3:23 pm, Samuel DeVore  wrote:
> Of course if all you want is stats on the file downloads and your
> server does that anyway, why not just filter/ collect stats from the
> log files?
>
> Sam D

Even if I don't initially start out recording other data, it's
probably worth me creating a setup now which can be easily extended
later.

Adding extra fields would naturally be easier than having to add an
extra table and all the related code at that later date.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to track # of file downloads (DB or File)

2009-02-17 Thread Samuel DeVore

Of course if all you want is stats on the file downloads and your
server does that anyway, why not just filter/ collect stats from the
log files?

Sam D

On Tue, Feb 17, 2009 at 2:04 AM, Mike Cook  wrote:
>
> Okay, definitely some food for thought here.
>
> @Miles J :: As brian states, this would be for stats. It's okay
> knowing you have 10 downloads, but knowing the time, day, week, and
> month can help in understanding your visitors better. If I do get to
> the point of implementing an API then I should also be able to record
> which party is drawing which downloads. So on and so forth.
> Recording milestones could work, but then I would loose all that
> lovely data. To help in page load time I guess I could just gather the
> file and author totals for the frontend on a daily/weekly basis - I
> don't suppose my visitors would mind/notice  :)
>
> @Alfredo Quiroga-Villamil :: I've only done some small DB projects
> before so I'd have to look into this further, but if I want to start
> recording other data then this might become a mute point.
>
> @brian
>
>> Tens of thousands of updates in a month shouldn't be a problem. I know
>> it's all relative, but a table with several thousand records is quite
>> tiny, btw. There are apps out there running Postgres or MySQL that
>> have many hundreds of millions of records. And, which have tens of
>> thousands of updates in a day, if not an hour.
>
> My DB experience is quite limited so this is good to know.
>
>> If you're using MySQL, you could consider the innodb engine. The
>> myisam engine is very fast for reading but innodb is better suited to
>> lots of updates.
>
> My DB was set up as InnoDB from the outset :-D
>
>> If you only ever have a single data point for a month you'd limit your
>> ability to generate stats. All you'd have is that one total. Anyway,
>> in order to do this, you'd still need to save a record for each
>> download, rather than incrementing a field for a particular files row.
>
> I looks like this is the best approach for sure, particularly now
> you've got me thinking about recording other data in there too.
>
>
> Thanks
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to track # of file downloads (DB or File)

2009-02-17 Thread Mike Cook

Okay, definitely some food for thought here.

@Miles J :: As brian states, this would be for stats. It's okay
knowing you have 10 downloads, but knowing the time, day, week, and
month can help in understanding your visitors better. If I do get to
the point of implementing an API then I should also be able to record
which party is drawing which downloads. So on and so forth.
Recording milestones could work, but then I would loose all that
lovely data. To help in page load time I guess I could just gather the
file and author totals for the frontend on a daily/weekly basis - I
don't suppose my visitors would mind/notice  :)

@Alfredo Quiroga-Villamil :: I've only done some small DB projects
before so I'd have to look into this further, but if I want to start
recording other data then this might become a mute point.

@brian

> Tens of thousands of updates in a month shouldn't be a problem. I know
> it's all relative, but a table with several thousand records is quite
> tiny, btw. There are apps out there running Postgres or MySQL that
> have many hundreds of millions of records. And, which have tens of
> thousands of updates in a day, if not an hour.

My DB experience is quite limited so this is good to know.

> If you're using MySQL, you could consider the innodb engine. The
> myisam engine is very fast for reading but innodb is better suited to
> lots of updates.

My DB was set up as InnoDB from the outset :-D

> If you only ever have a single data point for a month you'd limit your
> ability to generate stats. All you'd have is that one total. Anyway,
> in order to do this, you'd still need to save a record for each
> download, rather than incrementing a field for a particular files row.

I looks like this is the best approach for sure, particularly now
you've got me thinking about recording other data in there too.


Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to track # of file downloads (DB or File)

2009-02-16 Thread brian

On Mon, Feb 16, 2009 at 7:18 PM, Miles J  wrote:
>
> Well you could save each download with a date...

Yeah, this is what I'm saying--that, if a date is required, then
simply incrementing a single field in the files table will not work
and there needs to be a downloads table. The bonus is that you can
then save all sorts of other info, as well.

> and have a monthly
> cron that runs, calculates the total for that month and saves it to
> another table for monthly statistics, then erase all the previous
> single date records. But unless your doing by day, week, time etc,
> that wouldn't work.

If you only ever have a single data point for a month you'd limit your
ability to generate stats. All you'd have is that one total. Anyway,
in order to do this, you'd still need to save a record for each
download, rather than incrementing a field for a particular files row.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to track # of file downloads (DB or File)

2009-02-16 Thread Miles J

Well you could save each download with a date... and have a monthly
cron that runs, calculates the total for that month and saves it to
another table for monthly statistics, then erase all the previous
single date records. But unless your doing by day, week, time etc,
that wouldn't work.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to track # of file downloads (DB or File)

2009-02-16 Thread Alfredo Quiroga-Villamil

An approach to this could also be setting up a trigger in your
database. This way you wouldn't need any code. You would let mysql for
example do the work for you. Then you can use a neat little trick in
mysql and call a "group by with rollup" and get the grouping plus the
count.

I hope that helps.

Regards,

Alfredo


On Mon, Feb 16, 2009 at 5:49 PM, brian  wrote:
>
> On Mon, Feb 16, 2009 at 5:44 PM, Miles J  wrote:
>>
>> Well just think of it this way. What are you going to do with the
>> dates for each recorded download?
>
> statistics
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to track # of file downloads (DB or File)

2009-02-16 Thread brian

On Mon, Feb 16, 2009 at 5:44 PM, Miles J  wrote:
>
> Well just think of it this way. What are you going to do with the
> dates for each recorded download?

statistics

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to track # of file downloads (DB or File)

2009-02-16 Thread Miles J

Well just think of it this way. What are you going to do with the
dates for each recorded download?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to track # of file downloads (DB or File)

2009-02-16 Thread brian

On Mon, Feb 16, 2009 at 5:02 PM, Mike Cook  wrote:
>
> There's never guarantees of having huge traffic but I do expect to get
> a considerable amount, the number of files available will also grow to
> several thousand within a year or so - there's certainly potential of
> having tens of thousands of downloads per month.

Tens of thousands of updates in a month shouldn't be a problem. I know
it's all relative, but a table with several thousand records is quite
tiny, btw. There are apps out there running Postgres or MySQL that
have many hundreds of millions of records. And, which have tens of
thousands of updates in a day, if not an hour.


> This actually makes me wonder if I should be recording the date of
> each - how would the DB handle reading/writing such a large table each
> time someone views the details? Perhaps I should consider just
> recording milestones with dates.

If you're using MySQL, you could consider the innodb engine. The
myisam engine is very fast for reading but innodb is better suited to
lots of updates. However, if you just want to insert a record for each
download that's made, myisam should be fine. I doubt you'd see any
performance difference between inserting a new record into a
doewnloads table (because you want to store each individual datetime)
or updating/incrementing a field in the files table.


>> > NOTE: there's a good chance I will provide an API in the future for
>> > third-parties to access the file database. Would this affect the
>> > design decisions now?
>>
>> Do you mean the model/controller, or the actual table?
>
> There are third-parties (iPhone/Web) who could take a feed of my files
> and make them downloadable directly to their own app. Exactly how this
> would be programmed I'm not sure yet, this is something I've never
> done before and I am also new to Cake. I guess we shall see how I
> tackle that one :)


It would still need to go through your controller to get the file.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to track # of file downloads (DB or File)

2009-02-16 Thread Mike Cook

There's never guarantees of having huge traffic but I do expect to get
a considerable amount, the number of files available will also grow to
several thousand within a year or so - there's certainly potential of
having tens of thousands of downloads per month.

This actually makes me wonder if I should be recording the date of
each - how would the DB handle reading/writing such a large table each
time someone views the details? Perhaps I should consider just
recording milestones with dates.


> > NOTE: there's a good chance I will provide an API in the future for
> > third-parties to access the file database. Would this affect the
> > design decisions now?
>
> Do you mean the model/controller, or the actual table?

There are third-parties (iPhone/Web) who could take a feed of my files
and make them downloadable directly to their own app. Exactly how this
would be programmed I'm not sure yet, this is something I've never
done before and I am also new to Cake. I guess we shall see how I
tackle that one :)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to track # of file downloads (DB or File)

2009-02-16 Thread brian

On Mon, Feb 16, 2009 at 3:45 PM, Mike Cook  wrote:
>
> I want to track the number of file downloads and I'm wondering if any
> here have thoughts on how best to do this.
>
> At the moment I have a separate Files table for the details that
> stores information such as; filename, filesize, version,
> first_downloaded and downloads.
>
> Is incrementing the 'downloads' field here the best way to record it?

In a really basic, low-traffic setup, this might be ok.

> Should I use a completely separate table or perhaps even a flat file?

You've already got a database so a file would be needlessly
complicating things as well as slowing things down.

> I'm considering recording the date/time of each download, would this
> affect the decision?

The key here is "each download". So, you'll want to record them all,
individually, in their own table.

> Now, not only do I want to record file downloads but I also want to
> know how may total downloads a particular author has achieved. Should
> I increment a field in the author table at the time of the file
> download or, process the 'Files' table to calculate this number on the
> fly? - I guess that would mean adding an author_id to the Files table.

Create a downloads table to store the datetime and file_id. You can
total all downloads for files associated with a particular author by
getting the IDs for all files with a particular author_id, and the sum
for each in the downloads table.

> NOTE: there's a good chance I will provide an API in the future for
> third-parties to access the file database. Would this affect the
> design decisions now?

Do you mean the model/controller, or the actual table?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to track # of file downloads (DB or File)

2009-02-16 Thread Miles J

I do the same thing with my downloads. 
http://www.milesj.me/resources/script/commentia

On the "download" action. I find the file in the database, I increment
its download count if it exists and then I use the Media view to force
a download. Your on the right track.

As for the author part, if the downloads have a user_id, you can just
do a SUM() on all downloads that belong to a user.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---