pyramid_sqlalchemy_sessions add-on

41 views
Skip to first unread message

Andrey Tretyakov

unread,
Jun 25, 2017, 2:07:19 PM6/25/17
to pylons-discuss
Hello everyone,
I created new pyramid add-on and would appreciate any feedback.

https://github.com/corehack/pyramid_sqlalchemy_sessions

Haven't published on PyPI yet as I want to get initial feedback so that I can break a few things before the first release.


Thanks!
Andrey

Jonathan Vanasco

unread,
Jun 25, 2017, 4:59:53 PM6/25/17
to pylons-discuss
FWIW i'm not sure if this applies to your code or not, but a few things to look out for in writing server-side libraries in pyramid:

1. make sure you're only 'writing' the session once (a few libraries had written on each change)
2. a few libraries have done a preliminary check to see if a session exists. it's best to just "load", and create a new session on a load exception
3. it's also best to only write/create a session if you have data to store (or edit).  a handful of libraries will create a session by simply accessing/inspecting the `request.session` property.  
4. i found it useful to fingerprint a serialized version of the session, and detect changes on nested data by that. that overhead was much smaller than the load on Redis to store sessions that didn't really change.

i've had problems in the past with spiders/bots nearly taking a site offline from the effect of 100k+ hits in the span of a few minutes... each one generating a new session.



Andrey Tretyakov

unread,
Jun 25, 2017, 5:14:02 PM6/25/17
to pylons-discuss
Hi Jonathan,

1. Is done by alchemy automatically
2. If you mean running SELECT EXISTS query, I don't do that
3. It's called lazy session, my library provides one
4. I had this on my mind, and might implement it, I just did not think it's very important

Regarding bots I can't comment - generally you have to assume that DB will always perform worse.
I had one feature in mind to implement hybrid mode where you could run cookie sesison for anonymous
and DB session for authenticated users, but it would require significant amount of code so I'm not sure.

Andrey Tretyakov

unread,
Jun 28, 2017, 10:27:06 AM6/28/17
to pylons-discuss
I just went ahead and published it on PyPI

Reply all
Reply to author
Forward
0 new messages