Ejemplo n.º 1
0
    def update_work(self, ctx, work, get=None, save=None):
        """Adds/Updates the given work in the database.
        """
        get = get or self.db.get
        save = save or self.db.save

        logging.info("works_db: updating work %s", work['key'])

        key = work['key']
        old_work = get(key, {})
        if old_work:
            if "_rev" in old_work:  # ugly side-effect of CachedDatabase.
                work['_rev'] = old_work['_rev']
            work['editions'] = old_work.get('editions', [])

            old_seeds = set(engine.get_seeds(old_work))
        else:
            work['editions'] = []
            old_seeds = set()

        work['_id'] = work['key']
        new_seeds = set(engine.get_seeds(work))

        # Add both old and new seeds to the queue
        ctx.add_seeds(old_seeds)
        ctx.add_seeds(new_seeds)

        def non_edition_seeds(seeds):
            return sorted(seed for seed in seeds
                          if not seed.startswith("/books"))

        # Add editions to the queue if any of the seeds are modified
        if non_edition_seeds(old_seeds) != non_edition_seeds(new_seeds):
            ctx.add_editions(work['editions'])

        save(work)
        return work
Ejemplo n.º 2
0
    def update_work(self, ctx, work, get=None, save=None):
        """Adds/Updates the given work in the database.
        """
        get = get or self.db.get
        save = save or self.db.save
        
        logger.info("works_db: updating work %s", work['key'])
        
        key = work['key']
        old_work = get(key, {})
        if old_work:
            if "_rev" in old_work:  # ugly side-effect of CachedDatabase.
                work['_rev'] = old_work['_rev']
            work['editions'] = old_work.get('editions', [])
            
            old_seeds = set(engine.get_seeds(old_work))
        else:
            work['editions'] = []
            old_seeds = set()

        work['_id'] = work['key']
        new_seeds = set(engine.get_seeds(work))
        
        # Add both old and new seeds to the queue
        ctx.add_seeds(old_seeds)
        ctx.add_seeds(new_seeds)
        
        def non_edition_seeds(seeds):
            return sorted(seed for seed in seeds if not seed.startswith("/books"))
        
        # Add editions to the queue if any of the seeds are modified
        if non_edition_seeds(old_seeds) != non_edition_seeds(new_seeds):
            ctx.add_editions(work['editions'])
            
        save(work)
        return work
Ejemplo n.º 3
0
 def get_seeds(work):
     """Return non edition seeds of a work."""
     return [seed for seed in engine.get_seeds(work) if not seed.startswith("/books/")]
Ejemplo n.º 4
0
 def get_seeds(work):
     # returns non edition seeds
     if work:
         return sorted(engine.get_seeds(work))
     else:
         return []
Ejemplo n.º 5
0
 def get_seeds(work):
     """Return non edition seeds of a work."""
     return [
         seed for seed in engine.get_seeds(work)
         if not seed.startswith("/books/")
     ]
Ejemplo n.º 6
0
 def get_seeds(work):
     # returns non edition seeds
     if work:
         return sorted(engine.get_seeds(work))
     else:
         return []