Changeset - 229437211bef
[Not reviewed]
beta
0 3 0
Marcin Kuzminski - 15 years ago 2011-02-06 00:27:45
marcin@python-works.com
Optimized queries on journal, and added quick stop following action button in journal
3 files changed with 11 insertions and 3 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/journal.py
Show inline comments
 
@@ -36,12 +36,13 @@ from rhodecode.lib.auth import LoginRequ
 
from rhodecode.lib.base import BaseController, render
 
from rhodecode.lib.helpers import get_token
 
from rhodecode.model.db import UserLog, UserFollowing
 
from rhodecode.model.scm import ScmModel
 

	
 
from paste.httpexceptions import HTTPInternalServerError
 
from sqlalchemy.orm import joinedload
 

	
 
log = logging.getLogger(__name__)
 

	
 
class JournalController(BaseController):
 

	
 

	
 
@@ -51,13 +52,15 @@ class JournalController(BaseController):
 
        super(JournalController, self).__before__()
 

	
 
    def index(self):
 
        # Return a rendered template
 

	
 
        c.following = self.sa.query(UserFollowing)\
 
            .filter(UserFollowing.user_id == c.rhodecode_user.user_id).all()
 
            .filter(UserFollowing.user_id == c.rhodecode_user.user_id)\
 
            .options(joinedload(UserFollowing.follows_repository))\
 
            .all()
 

	
 
        repo_ids = [x.follows_repository.repo_id for x in c.following
 
                    if x.follows_repository is not None]
 
        user_ids = [x.follows_user.user_id for x in c.following
 
                    if x.follows_user is not None]
 

	
rhodecode/model/db.py
Show inline comments
 
@@ -310,13 +310,13 @@ class UserFollowing(Base, BaseModel):
 
    follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
 
    follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
 

	
 
    user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id')
 

	
 
    follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
 
    follows_repository = relationship('Repository')
 
    follows_repository = relationship('Repository', order_by='Repository.repo_name')
 

	
 
class CacheInvalidation(Base, BaseModel):
 
    __tablename__ = 'cache_invalidation'
 
    __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True})
 
    cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
 
    cache_key = Column("cache_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
rhodecode/templates/journal/journal.html
Show inline comments
 
@@ -40,13 +40,18 @@
 
		            %if entry.follows_user_id:
 
		              <img title="${_('following user')}" alt="${_('user')}" src="/images/icons/user.png"/>
 
		              ${entry.follows_user.full_contact}
 
		            %endif
 
		            
 
		            %if entry.follows_repo_id:
 
		            
 
		              
 
		              <div style="float:left;padding-right:5px">
 
                      <span id="follow_toggle_${entry.follows_repository.repo_id}" class="following" title="${_('Stop following this repository')}"
 
                            onclick="javascript:toggleFollowingRepo(this,${entry.follows_repository.repo_id},'${str(h.get_token())}')">
 
                      </span>		            
 
		              </div>
 
		              %if entry.follows_repository.private:
 
		                <img class="icon" title="${_('private repository')}" alt="${_('private repository')}" src="/images/icons/lock.png"/>
 
		              %else:
 
		                <img class="icon" title="${_('public repository')}" alt="${_('public repository')}" src="/images/icons/lock_open.png"/>
 
		              %endif
 
		              
0 comments (0 inline, 0 general)