Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

Changeset 575

Show
Ignore:
Timestamp:
11/05/07 22:29:41
Author:
fumanchu
Message:

Crazycache: Order support for indices.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/crazycache/dejavu/storage/caching.py

    r574 r575  
    9494        # Try to retrieve units using a cached index. 
    9595        if cls.identifiers and cls in self.cache.classes: 
    96             units = self.cache.scan(self.nextstore, cls, expr, order
     96            units = self.cache.scan(self.nextstore, cls, expr
    9797            if units is not None: 
    98                 for unit in units: 
     98                units = [(unit,) for unit in units] 
     99                for unit in self._paginate(units, order, limit, offset, single=True): 
    99100                    yield unit 
    100101                return 
  • branches/crazycache/dejavu/storage/storememcached.py

    r574 r575  
    496496        return {} 
    497497     
    498     def scan(self, mainstore, cls, expr, order): 
    499         """Return an ordered list of units from a cached index (or None). 
     498    def scan(self, mainstore, cls, expr): 
     499        """Return a list of units from a cached index (or None). 
    500500         
    501501        The class and expression will be used to find a cached index; 
     
    513513        keyattrs = self.primary_keys[cls] 
    514514         
    515         # Get a cached list of identifier-tuples, ordered if requested. 
    516         # TODO: add order to the idkey. 
     515        # Get a cached list of identifier-tuples. 
    517516        for index in indexset: 
    518517            if set(filters.keys()) >= set(index): 
     
    526525        if ids is None: 
    527526            # Not in the cache. Grab the list of id-tuples from nextstore. 
    528             ids = mainstore.view((cls, keyattrs, filters), order=order) 
    529             # Then cache the list result for next time. 
     527            ids = mainstore.view((cls, keyattrs, filters)) 
     528            # Then cache the list result for next time. Note that index 
     529            # contents are unordered. 
    530530            indexset.put(indexcriteria, ids, time=self.index_time) 
    531531             
     
    580580                    pass 
    581581         
    582         # Preserve order 
    583         return [units[k] for k in ids] 
     582        return units.values() 
    584583 
    585584 
     
    723722        index, although it may and often should contain additional entries. 
    724723        """ 
    725         partial_index = set(filters.keys()) > set(index) 
    726724        indexcriteria = dict([(k, filters[k]) for k in index]) 
    727725        ids = self.get(indexcriteria) 
     
    730728             
    731729            removals = False 
    732             # Preserve order by iterating over the retrieved ids 
    733             # instead of the retrieved units. 
    734             for id in ids: 
    735                 unit = units.get(id, None) 
    736                 if unit is not None: 
    737                     for k, v in filters.iteritems(): 
    738                         if getattr(unit, k) != v: 
    739                             if k in index: 
    740                                 removals = True 
    741                                 del units[id] 
    742                                 ids.remove(id) 
    743                             break 
    744                     else: 
    745                         unit.cleanse() 
    746                         yield unit 
     730            for id, unit in units.items(): 
     731                for k, v in filters.iteritems(): 
     732                    if getattr(unit, k) != v: 
     733                        if k in index: 
     734                            removals = True 
     735                            del units[id] 
     736                            ids.remove(id) 
     737                        break 
     738                else: 
     739                    unit.cleanse() 
     740                    yield unit 
    747741             
    748742            if removals: