def tx(key, incr): recipe = Recipe.get(db.Key(key)) if recipe: recipe.views += incr to_db = [recipe] idx = RecipeIdx.get(db.Key.from_path('RecipeIdx', 'idx', parent=recipe.key())) if idx: idx.views = recipe.views to_db.append(idx) fri = RecipeFriends.get(db.Key.from_path('RecipeFriends', 'fri', parent=recipe.key())) if fri: fri.views = recipe.views to_db.append(fri) db.put(to_db) return True
def update_friends(start_key=None): while (True): try: rec_friends = RecipeFriends.all() if start_key: rec_friends.filter('__key__ >', start_key) rec_friends.order('__key__') rec_friends = rec_friends.fetch(20) if not rec_friends: break else: start_key = None for rec_friend in rec_friends: rec_friend.friends = get_cached_friends(rec_friend.parent_key().parent().name()).keys() rec_friend.put() start_key = rec_friend.key() except (DeadlineExceededError, Timeout), e: deferred_lib.defer(update_friends, start_key) except (CapabilityDisabledError), e: break # End if there is no more time...