[ckan-changes] [ckan/ckan] a359bc: Stops Package.get avoiding the cache
GitHub
noreply at github.com
Fri Jan 8 15:31:57 UTC 2016
Branch: refs/heads/master
Home: https://github.com/ckan/ckan
Commit: a359bce80067569e4f2d0ca7b7c4e00665e11460
https://github.com/ckan/ckan/commit/a359bce80067569e4f2d0ca7b7c4e00665e11460
Author: Ross Jones <ross at servercode.co.uk>
Date: 2016-01-06 (Wed, 06 Jan 2016)
Changed paths:
M ckan/model/package.py
Log Message:
-----------
Stops Package.get avoiding the cache
SQLAlchemy has a session cache containing objects that it has retrieved
recently, which are stored in an identity map (pk->object). If you call
session.query(cls).get(pk) the object will be retrieved from the cache
(identity map), if you call session.query(cls).filter() then Sqlalchemy
has to query the database again.
In Package.get() the query to find by id (before looking by name) uses
filter and so will always bypass the session cache. Once upon a time it
used session.query(cls).get(reference), but this was lost in a change
(where eager loading was added, then removed in a later commit).
For a contrived, and probably sub-optimal example ...
for pkg in some_query_that_fetches_packages():
pkg_dict = logic.get_action('package_show')(context, {'id': pkg.id})
In these cases package_show is issuing another query to the
database, even though the package object is in the session cache
ready for retrieval.
There is more information on how the Session cache works at
http://docs.sqlalchemy.org/en/latest/orm/session_basics.html#is-the-session-a-cache
This should fix #2823 although there are likely other places this could
be done (e.g. group/user)
Commit: 8d52ecb9a62948833552bea406cb6a7a8d88ce69
https://github.com/ckan/ckan/commit/8d52ecb9a62948833552bea406cb6a7a8d88ce69
Author: Ian Ward <ian at excess.org>
Date: 2016-01-08 (Fri, 08 Jan 2016)
Changed paths:
M ckan/model/package.py
Log Message:
-----------
Merge pull request #2824 from ckan/2823-use-sqlalchemy-cache-for-packages
Stops Package.get avoiding the cache
Compare: https://github.com/ckan/ckan/compare/9596c5c95d5b...8d52ecb9a629
More information about the ckan-changes
mailing list