def do_business(self):
        super(DeleteOwnerToBlobArcs, self).do_business()

        if self.result:
            cache_keys = []
            if self._DeleteArcs__origin:
                cache_keys.append(IMG_CACHE_PREFIX + destinations_cache_key(self.arc_class, self._DeleteArcs__origin))
            else:
                for arc in self.result:
                    cache_keys.append(IMG_CACHE_PREFIX + destinations_cache_key(self.arc_class, arc.origin))

            if self._DeleteArcs__destination:
                cache_keys.append(IMG_CACHE_PREFIX + origins_cache_key(self.arc_class, self._DeleteArcs__destination))
            else:
                for arc in self.result:
                    cache_keys.append(IMG_CACHE_PREFIX + origins_cache_key(self.arc_class, arc.destination))
            memcache.delete_multi(cache_keys)
 def __init__(self, arc_class, origin=None, destination=None):
     super(DeleteArcs, self).__init__(arc_class, origin, destination, True)
     self._arc_delete_future = None
     self._cache_keys = []
     if origin:
         self._cache_keys.append(destinations_cache_key(arc_class, origin))
     if destination:
         self._cache_keys.append(origins_cache_key(arc_class, destination))
Beispiel #3
0
    def test_origins_search(self):
        destination = Node()
        origins = [Node() for i in xrange(3)]
        ndb.put_multi([destination] + origins)
        arcs = [Arc(origin=ori.key, destination=destination.key) for ori in origins]
        ndb.put_multi(arcs)
        search = ArcOriginsSearch(destination)
        search.execute()
        expected_keys = [n.key for n in origins]
        actual_keys = [n.key for n in search.result]
        self.assertItemsEqual(expected_keys, actual_keys)
        cache_keys = memcache.get(origins_cache_key(Arc, destination))
        self.assertItemsEqual(expected_keys, cache_keys)

        # Assert Arcs are removed from cache
        Arc(origin=origins[0].key, destination=destination.key).put()
        self.assertIsNone(memcache.get(origins_cache_key(Arc, destination)))
Beispiel #4
0
 def _pre_put_hook(self):
     if hasattr(self, 'key'):
         origins_key = origins_cache_key(self.__class__, self.destination)
         destinations_key = destinations_cache_key(self.__class__,
                                                   self.origin)
         keys = [
             origins_key, destinations_key, IMG_CACHE_PREFIX + origins_key,
             IMG_CACHE_PREFIX + destinations_key
         ]
         memcache.delete_multi(keys)
    def do_business(self):
        super(DeleteArcs, self).do_business()

        if self.result:
            futures = ndb.delete_multi_async([arc.key for arc in self.result])
            cache_keys = []
            if self.__origin:
                cache_keys.append(destinations_cache_key(self.arc_class, self.__origin))
            else:
                for arc in self.result:
                    cache_keys.append(destinations_cache_key(self.arc_class, arc.origin))

            if self.__destination:
                cache_keys.append(origins_cache_key(self.arc_class, self.__destination))
            else:
                for arc in self.result:
                    cache_keys.append(origins_cache_key(self.arc_class, arc.destination))
            memcache.delete_multi(cache_keys)
            [f.get_result() for f in futures]
 def __init__(self, arc_class, origin=None, destination=None):
     super(ArcNodeSearchBase, self).__init__(arc_class, origin, destination, False)
     if origin and destination:
         raise Exception('only one of origin or destination can be not None')
     elif origin:
         self._cache_key = destinations_cache_key(arc_class, origin)
         self._arc_property = 'destination'
     else:
         self._arc_property = 'origin'
         self._cache_key = origins_cache_key(arc_class, destination)
     self._node_cached_keys = None
 def __init__(self, origin=None, destination=None):
     super(ArcNodeSearchBase, self).__init__(origin, destination, False)
     if origin and destination:
         raise Exception(
             'only one of origin or destination can be not None')
     elif origin:
         self._cache_key = destinations_cache_key(self.arc_class,
                                                  self.origin)
         self._arc_property = 'destination'
     else:
         self._arc_property = 'origin'
         self._cache_key = origins_cache_key(self.arc_class, destination)
     self._node_cached_keys = None
    def do_business(self):
        super(DeleteArcs, self).do_business()

        if self.result:
            futures = ndb.delete_multi_async([arc.key for arc in self.result])
            cache_keys = []
            if self.__origin:
                cache_keys.append(
                    destinations_cache_key(self.arc_class, self.__origin))
            else:
                for arc in self.result:
                    cache_keys.append(
                        destinations_cache_key(self.arc_class, arc.origin))

            if self.__destination:
                cache_keys.append(
                    origins_cache_key(self.arc_class, self.__destination))
            else:
                for arc in self.result:
                    cache_keys.append(
                        origins_cache_key(self.arc_class, arc.destination))
            memcache.delete_multi(cache_keys)
            [f.get_result() for f in futures]
Beispiel #9
0
    def do_business(self):
        super(DeleteOwnerToBlobArcs, self).do_business()

        if self.result:
            cache_keys = []
            if self._DeleteArcs__origin:
                cache_keys.append(IMG_CACHE_PREFIX + destinations_cache_key(
                    self.arc_class, self._DeleteArcs__origin))
            else:
                for arc in self.result:
                    cache_keys.append(
                        IMG_CACHE_PREFIX +
                        destinations_cache_key(self.arc_class, arc.origin))

            if self._DeleteArcs__destination:
                cache_keys.append(IMG_CACHE_PREFIX + origins_cache_key(
                    self.arc_class, self._DeleteArcs__destination))
            else:
                for arc in self.result:
                    cache_keys.append(
                        IMG_CACHE_PREFIX +
                        origins_cache_key(self.arc_class, arc.destination))
            memcache.delete_multi(cache_keys)
Beispiel #10
0
 def _pre_put_hook(self):
     if hasattr(self, 'key'):
         origins_key = origins_cache_key(self.__class__, self.destination)
         destinations_key = destinations_cache_key(self.__class__, self.origin)
         keys = [origins_key, destinations_key, IMG_CACHE_PREFIX + origins_key, IMG_CACHE_PREFIX + destinations_key]
         memcache.delete_multi(keys)