Data Model

57 views
Skip to first unread message

golauty

unread,
Apr 28, 2016, 11:50:11 AM4/28/16
to pylons-discuss
Hi Guys,

i want to add a Data Model to my pyramid Web Application. Currently i create the Data Model everytime when a view is accessed.
This does not work in my Application due performance problems. I want to have a Data Model that is always accessable, for all views i have.
Now i wonder what the best way is to transport my data model to the view. I researched that i can use the
config.add_request_method to add a Property or a callable. But as i understand the request Object creates the new Property/Callable everytime it is accessed.
That would be the same thing i already have. I just want to create the Data Model at the startup and then use it for all my Views.
So any suggestions what i can use?

Bert JW Regeer

unread,
Apr 28, 2016, 11:56:26 AM4/28/16
to pylons-...@googlegroups.com
You could create your data model once, and then attach it to the registry. Then add a request method that fetches the result from the registry.

Bert
> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
> To post to this group, send email to pylons-...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/1b29789e-f83f-448b-8054-17bb873120e3%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jonathan Vanasco

unread,
Apr 28, 2016, 1:51:24 PM4/28/16
to pylons-discuss
Can you explain what the "Data Model" is?

Bert's simple suggestion will work perfectly if it is some sort of "read only" object.  If it is something else, there could be issues due to forking, processes and threads.

golauty

unread,
Apr 29, 2016, 1:11:25 AM4/29/16
to pylons-discuss
My data model would fetch data from a couple of sources via rest api, this data would then be used by the views.
Ocassionaly(very rare) i want to push data to my model and finally do post requests.

Joe Steeve

unread,
May 2, 2016, 1:12:48 AM5/2/16
to pylons-...@googlegroups.com
Do you want to cache the data from the REST API, and thereby save on
round-trip time in a request cycle? If so, would dropping another daemon
in the middle help?

--
Joe Steeve
HiPro IT Solutions Private Limited
http://hipro.co.in/
signature.asc

Jonathan Vanasco

unread,
May 2, 2016, 4:26:14 PM5/2/16
to pylons-discuss


On Friday, April 29, 2016 at 1:11:25 AM UTC-4, golauty wrote:
My data model would fetch data from a couple of sources via rest api, this data would then be used by the views.
Ocassionaly(very rare) i want to push data to my model and finally do post requests.

This strategy won't work under Pyramid or most other frameworks due to thread local variables.  You can learn more here http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/threadlocals.html

Any data you stash in the registry should be considered "read only".  This includes data your app reads/generates and connections to databases.  If you want to update data, you can read/write from an external memory storage system like Redis or Memcached.  
Reply all
Reply to author
Forward
0 new messages