I think there are two types of web applications; one is for admin-
site, and the other is for front-site. For admin-site, CPU-usage would
be relatively not so critical, and rich man's programming (fat models
in web2py) could be allowed. Front-site, on the other hand, needs
optimization as far as possible, which put developers some works.

Kenji

On 12月2日, 午後1:43, Bruno Rocha <[email protected]> wrote:
> Actually you dont need even an ajax callback.
>
> Take this example:
>
> ## models/script.py ##
>
> db.define_table("mytable", Field("picture", "upload"))
> print "models executed!"
>
> ## controllers/default.py ##
>
> def index():
>     pictures = db(db.mytable).select()
>     return dict(pictures=pictures)
>
> def download():
>     return response.download(request, db)
>
> ## views/default/index.html ##
>
> {{for picture in pictures:}}
>     <img src="{{=URL('default', 'download', args=picture.picture)}}">
> {{pass}}
>
> Let's say the table has 200 records and I want to show 200 thumbnails in
> the page.
>
> Q: How many times you will see "models executed!" in terminal? and how many
> times the table will be defined? the Auth, Crud, Service etc will be
> instantiated?
>
> A: 201 times. 1 for the first request and 200 for each image which calls
> the 'download' function.
>
> Now imagine a system which huge model files, too many tables and calling
> long running funtions.
>
> my tips:
>
> 1. Avoid models, use modules and import what you need in controller.
>
> 2. Avoid the download function, put uploadfolder='static' and build
> URL('static') when need an image. Or put your download function in a
> separate application which have access to the file system and database.
> --
>
> Bruno Rocha
> [http://rochacbruno.com.br]

Reply via email to