Changeset 823

Show
Ignore:
Timestamp:
03/09/07 11:22:50
Author:
chervol
Message:

getObject calls reducing

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • SimpleBlog/branches/optimizations/SimpleBlogTool.py

    r822 r823  
    162162        # if we are higher in the tree than any Blog then we will end up in the portalobject itself 
    163163        # in that case we just search for categories starting in context. 
    164  
     164         
     165         
    165166        if not startpoint: 
    166167            startpoint = self.getStartpoint(context, fromHere=0) 
     168        categories = context.portal_catalog.uniqueValuesFor('EntryCategory') 
     169        path = self.getObjectPath(startpoint) 
    167170 
    168171        # now we have the starting point for our search 
    169172         
    170         result = startpoint.portal_catalog.searchResults(meta_type=['BlogFolder', 'Blog'], path={'query':self.getObjectPath(startpoint),'level':0}) 
     173        #result = startpoint.portal_catalog.searchResults(meta_type=['BlogFolder', 'Blog'], path={'query':self.getObjectPath(startpoint),'level':0}) 
    171174         
    172175        # now fetch all the available categories 
    173         categories=[] 
    174         for o in result: 
    175             obj=o.getObject() 
    176             cats = obj.getCategories() 
    177             for c in cats: 
    178                 if not c in categories: 
    179                     categories.append(c) 
    180          
     176        #categories=[] 
     177        #for o in result: 
     178        #    obj=o.getObject() 
     179        #    cats = obj.getCategories() 
     180        #    for c in cats: 
     181        #        if not c in categories: 
     182        #            categories.append(c) 
     183        # 
    181184        # add the global categories 
    182         for c in self.getGlobalCategories(): 
    183             if not c in categories: 
    184                 categories.append(c) 
     185        #for c in self.getGlobalCategories(): 
     186        #    if not c in categories: 
     187        #        categories.append(c) 
    185188         
    186189        # now we have a list of unique categories available from startpoint and deeper in tree 
     
    189192        for c in categories: 
    190193            result = startpoint.portal_catalog.searchResults(review_state=self._getState(), meta_type='BlogEntry', EntryCategory=c,  path={'query':self.getObjectPath(startpoint),'level':0}) 
    191             rescats[c]=len(result) 
     194            num = len(result) 
     195            if num >0: 
     196                rescats[c]=len(result) 
    192197        return rescats 
     198        #return categories 
    193199     
    194200    security.declarePublic('getSortedKeys') 
     
    251257            query['EntryCategory']=category 
    252258 
    253         query['getAlwaysOnTop']=1 
     259        #query['getAlwaysOnTop']=1 
    254260         
    255261        if filterState: 
     
    257263 
    258264             
    259         resultsTop = startpoint.portal_catalog.searchResults(query, meta_type='BlogEntry', path={'query':self.getObjectPath(startpoint),'level':0}, sort_order='reverse', sort_on='effective') 
    260          
    261         query['getAlwaysOnTop']=0 
    262         resultsNoTop = startpoint.portal_catalog.searchResults(query, meta_type='BlogEntry', path={'query':self.getObjectPath(startpoint),'level':0}, sort_order='reverse', sort_on='effective') 
    263          
    264         results = resultsTop + resultsNoTop 
    265  
    266         if maxResults==0: 
     265        #resultsTop = startpoint.portal_catalog.searchResults(query, meta_type='BlogEntry', path={'query':self.getObjectPath(startpoint),'level':0}, sort_order='reverse', sort_on='effective') 
     266         
     267        #query['getAlwaysOnTop']=0 
     268        results = startpoint.portal_catalog.searchResults(query, meta_type='BlogEntry',  
     269                 path={'query':self.getObjectPath(startpoint),'level':0}, sort_order='reverse',  
     270                  sort_on='effective', sort_limit=maxResults) 
     271         
     272        if maxResults==0: 
    267273            return results 
    268274        elif maxResults==None: 
  • SimpleBlog/branches/optimizations/content/blog.py

    r822 r823  
    1616from Products.Archetypes.utils import  unique 
    1717 
    18 from Products.ATContentTypes.content.base import ATCTFolder 
     18from Products.ATContentTypes.content.base import ATCTBTreeFolder, ATCTFolder 
    1919 
    2020schema = ATCTFolder.schema.copy() +  Schema(( 
     
    247247    def synContentValues(self): 
    248248        # get brains for items that are published within the context of this blog. 
    249         entries = self.simpleblog_tool.searchForEntries(self, maxResults=0) 
    250  
     249        syn_tool = getToolByName(self, 'portal_syndication') 
     250        limit = int(syn_tool.getMaxItems(self)) 
     251        entries = self.getrEntries(self, maxResults=limit) 
     252          
    251253        # convert to objects 
    252254        objs = [e.getObject() for e in entries] 
     
    268270        return [f for f in self.getBRefs('AppearsIn') if self.portal_membership.checkPermission('View', f)] 
    269271 
    270     def getEntries(self, category=None, maxResults=None, b_start=0, filterState=1, join=0, skipOnTop=0, **kwargs): 
     272    def getEntries(self, category=None, maxResults=None, b_start=0, filterState=1, join=0, skipOnTop=0, mode="", **kwargs): 
    271273        """ Return all the contained published entries, real objects, not the brains """ 
    272274        # see simpleblog_tool.searchForEntries for API description 
     
    278280            query['review_state']=publishedState 
    279281        if maxResults: 
    280             query['sort_limit'] = maxResults 
     282            query['sort_limit'] = maxResults + 1 # need to if the last page riched 
    281283        query['path'] = {'query':self.simpleblog_tool.getObjectPath(self),'level':0} 
    282284        query['sort_order'] = 'reverse' 
     
    286288        if not skipOnTop and b_start==0: 
    287289            query['getAlwaysOnTop']=1 
    288             # first the items that need to be listed on top 
    289290            onTop = list(self.portal_catalog.searchResults(query)) 
    290             #onTop = [r.getObject() for r in localOnTop ] 
    291             # then the other items 
    292291            query['getAlwaysOnTop']=0 
    293292 
    294293        onBottom = list(self.portal_catalog.searchResults(query)) 
    295         #onBottom= [r.getObject() for r in localNoTop] 
    296          
    297294        ####  cut the b_start when it is tooo large 
    298          
     295 
     296        itemsPerPage = self.getDisplayItems() 
    299297        last = 0 
     298        if len(onBottom) < maxResults + 1: #last page 
     299            last = 1 
     300        elif len(onBottom) == maxResults + 1: #not last page yet 
     301            onBottom = onBottom[:-1] 
     302        if len(onBottom) < b_start:  # too large b_start given 
     303            b_start = (len(onBottom)/itemsPerPage)*itemsPerPage 
    300304        if join: 
    301305            results = onTop+onBottom 
    302306            if b_start > 0: 
    303                 if len(onBottom)==b_start: 
     307                if len(onBottom) == b_start: 
    304308                    b_start = b_start-(maxResults-b_start) 
    305309                    last = 1 
    306310                results = results[b_start:] 
    307             if maxResults==0: 
    308                 return (results,last) 
    309             elif maxResults==None: 
    310                 results =[r.getObject() for r in  results[:self.simpleblog_tool.getMaxItemsInPortlet()]] 
    311                 return results 
     311            #if maxResults==0: 
     312            #    return (results,last) 
     313            #elif maxResults==None: 
     314            #    #results =[r.getObject() for r in  results[:self.simpleblog_tool.getMaxItemsInPortlet()]] 
     315            #    return (results,0) 
     316            #else: 
     317            #    results = [r.getObject() for r in results] 
     318            #    return (results,last) 
     319            if mode == "full": 
     320                results = (results,last) 
    312321            else: 
    313                 results = [r.getObject() for r in results] 
    314                 return (results,last) 
     322                results = (results,last) 
     323            return results 
    315324        else: 
    316             return ([r.getObject() for r in onTop], [r.getObject() for r in onBottom]
     325            return (onTop, onBottom
    317326 
    318327    def getAdminEmail(self): 
  • SimpleBlog/branches/optimizations/content/blogfolder.py

    r822 r823  
    55from Products.CMFCore import CMFCorePermissions 
    66 
    7 from Products.ATContentTypes.content.base import ATCTFolder 
     7from Products.ATContentTypes.content.base import ATCTBTreeFolder, ATCTFolder 
    88 
    99import Products.SimpleBlog.Permissions 
  • SimpleBlog/branches/optimizations/skins/SimpleBlog/SimpleBlog_macros.pt

    r822 r823  
    2828        <span tal:define="item_type obj/portal_type; 
    2929                    item_type_class python:'contenttype-' + normalizeString(item_type);" 
    30               tal:attributes="class string:simpleBlogIcons ${item_type_class}" tal:content="obj/title"/></a> 
     30              tal:attributes="class string:simpleBlogIcons ${item_type_class}" tal:content="obj/Title"/></a> 
    3131    </h2> 
    3232    <h2 class="noMargin" tal:condition="not:showIcons"> 
     
    3535    </h2> 
    3636    <p class="simpleBlogDescription" 
    37        tal:content="structure python:obj.Description()
     37       tal:content="structure obj/Description
    3838       tal:condition="obj/Description">Description</p> 
    39     <div tal:replace="structure python:obj.getBody()" class="simpleBlogBody"/> 
     39    <div tal:replace="structure obj/getBody" class="simpleBlogBody"/> 
    4040    <tal:tags metal:use-macro="obj/simpleblog_byline/macros/technoratiTags"/> 
    4141    <tal:byline tal:condition="showByline"> 
     
    5757    </h2> 
    5858    <p class="simpleBlogDescription" 
    59        tal:content="structure python:obj.Description()
     59       tal:content="structure obj/Description
    6060       tal:condition="obj/Description">Description</p> 
    6161    <tal:tags metal:use-macro="obj/simpleblog_byline/macros/technoratiTags"/> 
  • SimpleBlog/branches/optimizations/skins/SimpleBlog/simpleblog_portlet_macros.pt

    r822 r823  
    2626<div metal:define-macro="portletRecent"><tal:block  
    2727           tal:define="maxResults here/simpleblog_tool/getMaxItemsInPortlet; 
    28                        recent python:startpoint.getEntries(maxResults=maxResults,skipOnTop=1, join=1)
     28                       recent python:startpoint.getEntries(maxResults=maxResults,skipOnTop=1, join=1)[0]
    2929                       global showIcons startpoint/getShowIcons;"><tal:toggle  
    3030           tal:define="global toggle python:1"/> 
     
    3838        <dd class="" 
    3939            tal:define="oddrow repeat/entry/odd; 
    40                         item_type entry/portal_type; 
     40                        obj entry; 
     41                        item_type obj/portal_type; 
    4142                        item_type_class python:'contenttype-' + normalizeString(item_type);"  
    4243            tal:attributes="class python:test(toggle, 'portletItem even','portletItem odd')"> 
    4344            <a href="#"  
    44                tal:attributes="href entry/absolute_url;"  
     45               tal:attributes="href obj/getURL;"  
    4546                               title="entry"> 
    46                <span tal:attributes="class python:showIcons and 'simpleBlogPortletIcons '+item_type_class or ''" tal:content="entry/Title"/> 
     47               <span tal:attributes="class python:showIcons and 'simpleBlogPortletIcons '+item_type_class or ''" tal:content="obj/Title"/> 
    4748            </a><tal:toggle tal:define="global toggle python:test(toggle==1,0,1)"/> 
    4849        </dd> 
  • SimpleBlog/branches/optimizations/skins/SimpleBlog/simpleblog_view.pt

    r822 r823  
    99                  displayMode displayMode | python:here.getDisplayMode(); 
    1010                  b_size python:displayItems; 
    11                   b_start python:0; 
    12                   b_start request/b_start | b_start; 
    13                   results python:here.getEntries(maxResults=int(b_start)+displayItems, sort=1, join=1, b_start=int(b_start)); 
    14                   last python:results[1]; 
    15                   b_start python:last and int(b_start)-displayItems or b_start; 
    16                   last python:len(results[0])<displayItems and 1 or last;"> 
     11                  b_start python:int(request.get('b_start', 0)) or 0; 
     12                  b_start  python:(b_start%displayItems)!=0 and (b_start/displayItems)*displayItems or b_start; 
     13                  results python:here.getEntries(maxResults=b_start+displayItems, sort=1, join=1, b_start=b_start,mode=displayMode); 
     14                  last python:results[1]"> 
    1715        <tal:block metal:use-macro="here/SimpleBlog_macros/macros/blogGlobals"/> 
    1816        <div metal:use-macro="here/document_actions/macros/document_actions"> 
     
    3937        <div tal:condition="results" tal:define="batch python:results[0];"> 
    4038            <tal:block tal:repeat="entry batch"><tal:entry  
    41                        tal:define="obj python:entry;"><div metal:use-macro="here/SimpleBlog_macros/macros/?displayMode"/> 
     39                       tal:define="obj entry/getObject"><div metal:use-macro="here/SimpleBlog_macros/macros/?displayMode"/> 
    4240                <br/> 
    4341                </tal:entry></tal:block>