[ckan-changes] commit/ckan: kindly: [model] update session extenstion to not add revisions to object cache

Bitbucket commits-noreply at bitbucket.org
Wed Jul 13 10:49:35 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/ba14d090fc68/
changeset:   ba14d090fc68
branch:      feature-1211-drupal
user:        kindly
date:        2011-07-12 12:50:02
summary:     [model] update session extenstion to not add revisions to object cache
affected #:  2 files (403 bytes)

--- a/ckan/lib/dictization/model_save.py	Sun Jul 10 22:58:18 2011 +0100
+++ b/ckan/lib/dictization/model_save.py	Tue Jul 12 11:50:02 2011 +0100
@@ -105,7 +105,7 @@
         extra = old_extras[key]
         if extra.state == 'deleted':
             continue
-        state = 'pending-deleted' if context.get('pending') else 'delete'
+        state = 'pending-deleted' if context.get('pending') else 'deleted'
         extra.state = state
 
 def group_extras_save(extras_dicts, context):


--- a/ckan/model/meta.py	Sun Jul 10 22:58:18 2011 +0100
+++ b/ckan/model/meta.py	Tue Jul 12 11:50:02 2011 +0100
@@ -1,6 +1,7 @@
 import datetime
 """SQLAlchemy Metadata and Session object"""
 from sqlalchemy import MetaData, __version__ as sqav
+from sqlalchemy.orm import class_mapper
 from sqlalchemy.orm import scoped_session, sessionmaker
 import sqlalchemy.orm as orm
 from sqlalchemy.orm.session import SessionExtension
@@ -37,42 +38,42 @@
             revision = session.revision
         except AttributeError:
             return
-
         new = obj_cache['new']
         changed = obj_cache['changed']
         deleted = obj_cache['deleted']
-
         for obj in new | changed | deleted:
-            
             if not hasattr(obj, '__revision_class__'):
                 continue
-
             revision_cls = obj.__revision_class__
-
+            revision_table = class_mapper(revision_cls).mapped_table
             ## when a normal active transaction happens
             if 'pending' not in obj.state:
-                revision.approved_timestamp = datetime.datetime.now()
-                old = session.query(revision_cls).filter_by(
-                    current='1',
-                    id = obj.id
-                ).first()
-                if old:
-                    old.current = '0'
-                    session.add(old)
+                ### this is asql statement as we do not want it in object cache
+                session.execute(
+                    revision_table.update().where(
+                        and_(revision_table.c.id == obj.id,
+                             revision_table.c.current == '1')
+                    ).values(current='0')
+                )
 
             q = session.query(revision_cls)
             q = q.filter_by(expired_timestamp=datetime.datetime(9999, 12, 31), id=obj.id)
             results = q.all()
-
             for rev_obj in results:
+                values = {}
                 if rev_obj.revision_id == revision.id:
-                    rev_obj.revision_timestamp = revision.timestamp
+                    values['revision_timestamp'] = revision.timestamp
                     if 'pending' not in obj.state:
-                        rev_obj.current = '1'
+                        values['current'] = '1'
                 else:
-                    rev_obj.expired_id = revision.id
-                    rev_obj.expired_timestamp = revision.timestamp
-                session.add(rev_obj)
+                    values['expired_id'] = revision.id
+                    values['expired_timestamp'] = revision.timestamp
+                session.execute(
+                    revision_table.update().where(
+                        and_(revision_table.c.id == rev_obj.id,
+                             revision_table.c.revision_id == rev_obj.revision_id)
+                    ).values(**values)
+                )
 
     def after_commit(self, session):
         if hasattr(session, '_object_cache'):

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list