Sounds like you need to break the logic into modules instead of having them
all in the models folders that is kind of bad design. And module can be
imported into a conditional model file when needed which will make it
accessed to all actions in the controller that needs them. You can also
make cold only load for specific actions.

Remember just by putting the code in a model it is loaded every time. Where
as if you move the same code into a module it is only loaded when you need
it.

On Wed, Aug 29, 2012 at 7:30 PM, Yarin <ykess...@gmail.com> wrote:

> Bruce- thanks for the example- it's a good approach to selectively loading
> tables. However I'm looking for a solution not only for avoiding
> unnecessary table definitions but for avoiding unnecessary loading and
> parsing of the model files themselves, as in my case they are big files
> that house extensive data processing logic that needs to be shared but that
> isn't applicable to the public-side of the site. I can't use your solution
> to make any gains there.
>
>
> On Wednesday, August 29, 2012 2:25:11 AM UTC-4, Bruce Wade wrote:
>
>> Ok see attached.
>>
>> 1) I left the default auth tables they can also be filtered out in the
>> same way.
>> 2) I added the load_tables method to the top of db.py this method could
>> be put anywhere and imported. However I put it here so it never needs to be
>> imported.
>> 3) When clicking the links at the top the page shows which tables are
>> loaded using message=db.tables. Looking closely at the bottom of the list
>> for the example URLs you can see that different tables are loaded.
>> 4) This is all handed in the models folder using conditional folders.
>> 5) As you can see there is ZERO duplication of model definition you only
>> ever define them ones. And if you moved this method into an api at the
>> route of web2py you can then use the same tables in ALL apps using the same
>> import proccess. IE: from custom_api.tables import load_tables etc....
>>
>> Hope this makes it more clear what I have been talking about and tried to
>> explain months ago :D.
>>
>> On Tue, Aug 28, 2012 at 10:50 PM, Bruce Wade <bruce...@gmail.com> wrote:
>>
>>> I am righting a quick example app as I don't think anyone is really
>>> understanding what I am saying :D I will email it within the next 30 mins.
>>>
>>>
>>> On Tue, Aug 28, 2012 at 10:36 PM, Bruce Wade <bruce...@gmail.com> wrote:
>>>
>>>> Conditional models will work, however not with the default design as
>>>> you may have noticed. In youadworld there are some controllers that
>>>> required access to 20 tables and others that required access to only a few
>>>> tables. The technique I used works perfect for that without ever
>>>> duplicating the model definitions in each folder/.py file. In fact there is
>>>> zero definitions to models in the models director they are separated into a
>>>> different location with a method where you pass in the models (table names)
>>>> you need. Using this way you just include the method into the conditional
>>>> model folders py file and load only the models you need for that specific
>>>> controller.
>>>>
>>>> However from your last statement you said you wish to use web2py to
>>>> determine if someone is logged in, in that case you will require at least
>>>> the auth tables loaded.
>>>>
>>>>
>>>> On Tue, Aug 28, 2012 at 9:26 PM, Yarin <ykes...@gmail.com> wrote:
>>>>
>>>>> pbreit- Yeah I thought about letting apache handle the public part,
>>>>> but that still leaves me in the lurch because I can't use web2py to
>>>>> determine whether the user is logged in, which is how we decide whether to
>>>>> deliver the public or private portion to begin with. So the only practical
>>>>> course is to optimize within the same app, in web2py...
>>>>>
>>>>> I think a combo of lazy tables and moving models into modules is where
>>>>> we'll end up.
>>>>>
>>>>> Thanks for all the suggestions--
>>>>>
>>>>>
>>>>> On Wednesday, August 29, 2012 12:14:21 AM UTC-4, pbreit wrote:
>>>>>>
>>>>>> Fair enough. If there's no processing at all, best to serve the
>>>>>> static site direct through Nginx/Apache. Otherwise, as you note,
>>>>>> conditional models may not work so waiting for "lazy tables" might be 
>>>>>> best
>>>>>> (should be any day now in 2.0).
>>>>>>
>>>>>> On Tuesday, August 28, 2012 8:55:35 PM UTC-7, Yarin wrote:
>>>>>>>
>>>>>>> Who said anything about premature? We want our app to run faster,
>>>>>>> and we are gonna worry about it.
>>>>>>>
>>>>>>> On Tuesday, August 28, 2012 11:49:22 PM UTC-4, pbreit wrote:
>>>>>>>>
>>>>>>>> If you haven't determined a performance issue, best to not worry
>>>>>>>> about it ("premature optimization -> evil").
>>>>>>>>
>>>>>>>>
>>>>>>>> On Tuesday, August 28, 2012 6:52:12 PM UTC-7, Yarin wrote:
>>>>>>>>>
>>>>>>>>> A basic architecture question:
>>>>>>>>>
>>>>>>>>> We're putting together a typical web app where non-logged in users
>>>>>>>>> reach a public-facing basic 'brochure' site, and then log in to reach 
>>>>>>>>> the
>>>>>>>>> 'real' application. With such a setup, it makes no sense to be loading
>>>>>>>>> models for the public portion of the site, as it's just some 
>>>>>>>>> semi-static
>>>>>>>>> pages and a login form. So I'm wondering
>>>>>>>>>
>>>>>>>>>    - a) Is there a way to prevent models loading at the request
>>>>>>>>>    or controller level?
>>>>>>>>>    - b) Should the 'public' site be part of the same application
>>>>>>>>>    at all, or should it be a separate light-weight application with a 
>>>>>>>>> login
>>>>>>>>>    form that then points to the 'real' application?
>>>>>>>>>
>>>>>>>>>  --
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> --
>>>> Regards,
>>>> Bruce Wade
>>>> http://ca.linkedin.com/in/**brucelwade<http://ca.linkedin.com/in/brucelwade>
>>>> http://www.wadecybertech.com
>>>> http://www.fittraineronline.**com <http://www.fittraineronline.com> -
>>>> Fitness Personal Trainers Online
>>>> http://www.warplydesigned.com
>>>>
>>>>
>>>
>>>
>>> --
>>> --
>>> Regards,
>>> Bruce Wade
>>> http://ca.linkedin.com/in/**brucelwade<http://ca.linkedin.com/in/brucelwade>
>>> http://www.wadecybertech.com
>>> http://www.fittraineronline.**com <http://www.fittraineronline.com> -
>>> Fitness Personal Trainers Online
>>> http://www.warplydesigned.com
>>>
>>>
>>
>>
>> --
>> --
>> Regards,
>> Bruce Wade
>> http://ca.linkedin.com/in/**brucelwade<http://ca.linkedin.com/in/brucelwade>
>> http://www.wadecybertech.com
>> http://www.fittraineronline.**com <http://www.fittraineronline.com> -
>> Fitness Personal Trainers Online
>> http://www.warplydesigned.com
>>
>>   --
>
>
>
>



-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.fittraineronline.com - Fitness Personal Trainers Online
http://www.warplydesigned.com

-- 



Reply via email to