I have done it. Just make sure you retrieve it once and cache. Do not
retrieve every value only when needed.

On Sep 7, 12:13 pm, Rufus <[email protected]> wrote:
> For site persistant data, is it customary to put it
> in a database table with one large record?
>
> There are some statistical things I'd  like to keep track of on the
> site.   Is it standard practice to define one data table that has
> one large record containing the information?, for instance:
>
> Number visitors since inception
> emails sent
> uploaded bytes stored
> ...
>
> You don't want to pump through all your data base data for these
> numbers, so it's probably more efficient to just keep them in a
> file.
>
> Is it normal to do this with a database table called something
> like site_stats (or maybe app_stats, to stay in the application's
> space), and simply do update_record with the changed field?
> This is what I did:
> ---- in models/sitedb.py -----
> db.define_table('app_stats',
>     Field('visitors', type='integer'),
>     Field('emails_sent', type='integer', default=0)    )
> ----------------------------------
>
> and in my controller I had (I left in the first misfire and comment
> as a future warning to others....):
> --------------------------------------
> #    stat_rec = db().select(db.app_stats.visitors).last()
> # the above line generates a KeyError for stat_rec.update_record
> # the line below worked fine
>     stat_rec = db(db.app_stats).select().last()
>     if stat_rec:
>        stat_rec.update_record(visitors = stat_rec.visitors + 1)
>     else:
>        stat_rec = db.app_stats(db.app_stats.insert(visitors=1))
>     db.commit()
> -------------------------------------------------
>
> Are there other ways people save this kind of data?

Reply via email to