lists.arthurdejong.org
RSS feed

webcheck branch master updated. 1.10.4-79-gc31be03

[Date Prev][Date Next] [Thread Prev][Thread Next]

webcheck branch master updated. 1.10.4-79-gc31be03



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "webcheck".

The branch, master has been updated
       via  c31be0302aa5ee0ab496f017edfcbf6a4bd3cc92 (commit)
      from  54bb33a8f68704ee690352170040cbfb2aea10ea (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://arthurdejong.org/git/webcheck/commit/?id=c31be0302aa5ee0ab496f017edfcbf6a4bd3cc92

commit c31be0302aa5ee0ab496f017edfcbf6a4bd3cc92
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Sep 29 00:45:34 2013 +0200

    Optimise count_parents()
    
    This combines two queries using a union that already does distinct.
    
    This also removes the distinct from the parents() function because it
    uses a union which is supposed to use distinct already.

diff --git a/webcheck/db.py b/webcheck/db.py
index 5f9be3b..c1cda32 100644
--- a/webcheck/db.py
+++ b/webcheck/db.py
@@ -24,7 +24,7 @@ import logging
 import urlparse
 
 from sqlalchemy.ext.declarative import declarative_base
-from sqlalchemy import distinct, func
+from sqlalchemy import func
 from sqlalchemy import Table, Column, Integer, Boolean, String, DateTime, 
ForeignKey
 from sqlalchemy.orm import relationship, backref, sessionmaker
 from sqlalchemy.orm.session import object_session
@@ -225,22 +225,15 @@ class Link(Base):
     @property
     def count_parents(self):
         session = object_session(self)
-        p1 = 
session.query(func.count(distinct(children.c.parent_id))).filter(children.c.child_id
 == self.id)
-        p2 = 
session.query(func.count(distinct(embedded.c.parent_id))).filter(embedded.c.child_id
 == self.id)
-        return p1.scalar() + p2.scalar()
+        return session.query(children.c.parent_id).filter(children.c.child_id 
== self.id).union(
+            session.query(embedded.c.parent_id).filter(embedded.c.child_id == 
self.id)).count()
 
     @property
     def parents(self):
         session = object_session(self)
-        #links = object_session(self).query(Link)
-        #links = links.join(children, Link.id == children.c.parent_id)
-        #links = links.join(embedded, Link.id == embedded.c.parent_id)
-        #return links.filter((children.c.child_id == self.id) |
-        #                    (embedded.c.child_id == self.id)).distinct()
         parent_ids = 
union(session.query(children.c.parent_id).filter(children.c.child_id == 
self.id),
                            
session.query(embedded.c.parent_id).filter(embedded.c.child_id == self.id))
-
-        return session.query(Link).filter(Link.id == 
parent_ids.c.children_parent_id).distinct()
+        return session.query(Link).filter(Link.id == 
parent_ids.c.children_parent_id)
 
 
 class LinkProblem(Base):

-----------------------------------------------------------------------

Summary of changes:
 webcheck/db.py |   15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)


hooks/post-receive
-- 
webcheck
-- 
To unsubscribe send an email to
webcheck-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/webcheck-commits/