*Cliff* 

Thanks for the suggestion, but unfortuantely I need it to work on Windows 
as well, so I'll probably look for a code-organization based solution.

*Bruce*

I would certainly be interested to see what you've done.  I've been 
distilling Bruno's model-less 
demo<http://movu.ca/demo/article/show/11/model-less-apps-using-data-models-and-modules-in-web2py>down
 to the essential components that I need, and I came up with some that 
works like this:

*Model:*
app = MyApp()  # This is based on Bruno's concept of an app that contains 
all the database connection settings as well as member variables for db, 
mail, and crud

*Modules:*
- Base data-model module based on Bruno's basemodel.py that acts as a 
common data-model interface 
- All data models inherited from the based data-model.  Each defines its 
own fields, validators, etc...

*Controller:*
Now in the first line of each of my controllers I just need to declare the 
database variable.  It's not terribly pretty that I have to do that I 
suppose, but, since I've opted for declaring which models I need and which 
I don't, I'm going to have declare them *somewhere*. I guess it's sort of 
like an inverted decorator (below the definition instead of above).

from datamodels.user import UserModel
from datamodels.post import PostModel
from datamodels.comment import CommentModel

def user():
    db = app.db([UserModel, PostModel, CommentModel])  # Connect to the 
database and define the models specified
    # Do whatever processing is required for this controller

*Discussion:*
*
*
This solution could be nice for a couple of reasons:
1) MyApp holds the instance of the database so I it can be smart about not 
defining tables that have already been defined (because programmers make 
mistakes)
2) I could conditionally declare models based on request conditions and 
ramp up which tables are declared as I need them.  (Maybe that'll help for 
caching with logged-in users -- don't know yet)
3) Models are separate.  Combined with gluino it means I could possibly 
reuse the code to make a desktop app with PySide, or as the back-end for an 
iOS or Android app.

This solution isn't so nice because:
1) It's fairly verbose.

*Future:*
*
*
If I like this solution I could make it a little more clear with a closure 
that has a better name.

*Model: *
app = MyApp()
requires = app.requires()

*Controller:*
from datamodels.user import UserModel
from datamodels.post import PostModel
from datamodels.comment import CommentModel

def user():
    requires([UserModel, PostModel, CommentModel])


Anyway... that's what I've done so far.  Can't wait to see yours!


On Sunday, May 27, 2012 5:52:21 PM UTC+1, Bruce Wade wrote:
>
> Yes you can soft link however when you get to the point of multiple 
> servers and upgrading code on each it is a pain.
>
> The site I`m working in is very large. I am now rewriting the code with a 
> new technique in modules and using conditional if statements in side each 
> module so you have 100% control of what loads when and where. 
>
> I should have the new code live soon and will follow up if there was a 
> huge improvement or not. Locally I have seen a huge improvement on one page 
> the loading time went from 0.128 to 0.045 seconds and a functioin call drop 
> from 85845 to 31380 calls and this example is from a page with a single 
> query to a single record in the db. You can imagine the improvement on a 
> complicated page.
> On May 27, 2012 8:56 AM, "Cliff Kachinske" <cjk...@gmail.com> wrote:
>
>> Yes, you can soft link individual files within the file system.  You can 
>> even rename the target files so the tables load in the right order.
>>
>> It will work on Linux and OS-X and should work on all unix flavors.
>>
>> On Friday, May 25, 2012 3:25:37 PM UTC-4, David McKeone wrote:
>>>
>>> Cliff,
>>>
>>> Certainly an interesting idea.  I'm assuming that you mean soft-linking 
>>> the file system? Would that work on Windows (I have to be able to deploy to 
>>> Windows and Mac)?
>>>
>>> -David
>>>
>>> On Friday, May 25, 2012 8:05:06 PM UTC+1, Cliff Kachinske wrote:
>>>>
>>>> Maybe you could soft link the model files.
>>>>
>>>> For controller foo you would have a file models/foo/foo.py
>>>>
>>>> If controller bar needs needs data from table foo, you would create a 
>>>> soft link in you models/bar directory to models/foo/foo.py.
>>>>
>>>> Note if you link it in as foo.py, it will run after bar.py, so you 
>>>> would want to name the link according to the necessary sequence.
>>>>
>>>> Don't know what this would do for migrations on the production box, 
>>>> though.
>>>>
>>>> On Friday, May 25, 2012 11:49:51 AM UTC-4, David McKeone wrote:
>>>>>
>>>>> Hi Massimo,
>>>>>
>>>>> "You probably do not need 100 models defined for each request." 
>>>>> and "Make sure you turn migrations off and bytecode compile your apps."
>>>>>
>>>>> No, I certainly don't need all 100 at all times.  That was really just 
>>>>> a test to see where the boundaries were going to be.  It likely wasn't 
>>>>> the 
>>>>> optimal configuration (migrations were off, wasn't byte-compiled), but it 
>>>>> did highlight that as the app grows that's an area I have to watch for 
>>>>> and 
>>>>> one that will affect the user experience.  Once I saw that a boundary 
>>>>> existed I found Bruno's model-less design and that brought things back to 
>>>>> great performance levels.  So I think that design will fit my needs 
>>>>> performance wise.
>>>>>
>>>>> I'll investigate the conditional model system, but my understanding of 
>>>>> that was that you would be restricted to specific controllers.  As in, I 
>>>>> can't use a single table (model) across multiple controllers. Would that 
>>>>> be 
>>>>> true?
>>>>>
>>>>> -David
>>>>>
>>>>
>>> On Friday, May 25, 2012 8:05:06 PM UTC+1, Cliff Kachinske wrote:
>>>>
>>>> Maybe you could soft link the model files.
>>>>
>>>> For controller foo you would have a file models/foo/foo.py
>>>>
>>>> If controller bar needs needs data from table foo, you would create a 
>>>> soft link in you models/bar directory to models/foo/foo.py.
>>>>
>>>> Note if you link it in as foo.py, it will run after bar.py, so you 
>>>> would want to name the link according to the necessary sequence.
>>>>
>>>> Don't know what this would do for migrations on the production box, 
>>>> though.
>>>>
>>>> On Friday, May 25, 2012 11:49:51 AM UTC-4, David McKeone wrote:
>>>>>
>>>>> Hi Massimo,
>>>>>
>>>>> "You probably do not need 100 models defined for each request." 
>>>>> and "Make sure you turn migrations off and bytecode compile your apps."
>>>>>
>>>>> No, I certainly don't need all 100 at all times.  That was really just 
>>>>> a test to see where the boundaries were going to be.  It likely wasn't 
>>>>> the 
>>>>> optimal configuration (migrations were off, wasn't byte-compiled), but it 
>>>>> did highlight that as the app grows that's an area I have to watch for 
>>>>> and 
>>>>> one that will affect the user experience.  Once I saw that a boundary 
>>>>> existed I found Bruno's model-less design and that brought things back to 
>>>>> great performance levels.  So I think that design will fit my needs 
>>>>> performance wise.
>>>>>
>>>>> I'll investigate the conditional model system, but my understanding of 
>>>>> that was that you would be restricted to specific controllers.  As in, I 
>>>>> can't use a single table (model) across multiple controllers. Would that 
>>>>> be 
>>>>> true?
>>>>>
>>>>> -David
>>>>>
>>>>

Reply via email to