def addFeedToDataStore(self, feedUrl): fds = FeedDataSettings.get_by_id(feedUrl) if fds is None: fds = FeedDataSettings(url=feedUrl, id=feedUrl, article_count=0, feedDataCount=0, private_data='', new_etag='', new_modified='', refCount=1) else: fds.refCount = fds.refCount + 1 logging.debug( 'adding feed to data store %s, refCount: %s', feedUrl, fds.refCount) fds.put()
def deleteFeed(self, feedUrl): logging.debug('deleting feed: %s', feedUrl) fds = FeedDataSettings.get_by_id(feedUrl) if fds is not None: fds.refCount = fds.refCount - 1 logging.debug( 'deleting feed %s, refCount: %s', feedUrl, fds.refCount) if fds.refCount > 0: fds.put() else: fds.key.delete()
def addNewFeed(self, feedUrl): logging.debug('adding feed: %s', feedUrl) fds = FeedDataSettings.get_by_id(feedUrl) if fds is None: fds = FeedDataSettings(url=feedUrl, id=feedUrl, article_count=0, feedDataCount=0, private_data='', new_etag='', new_modified='', refCount=1) fds.put(use_cache=False, use_memcache=False) # ! logging.debug('adding feed, fds is None: %s', feedUrl) GetAndParse(feedUrl, False, fds) else: fds.refCount = fds.refCount + 1 fds.put()
def get(self): self.response.headers['Content-Type'] = 'application/json' self.response.headers['Cache-Control'] = "private, max-age=0" user = users.get_current_user() if user: ud = GetAppUserByEmail(user.email()) if ud is not None: # rebuild indexs # allFeedDataSettings = FeedDataSettings.query() # for feed in allFeedDataSettings: # feed.url = feed.url # feed.put() allUserRead = ReadData.query( ReadData.app_username == ud.app_username).fetch() #data = [{'url': read.feedUrl, 'readCount': read.readCount} for read in allUserRead] # data = [{read.feedUrl: {read: read.readCount} for read in # allUserRead] data = {} for read in allUserRead: data[read.feedUrl] = { 'readCount': read.readCount } #futures = [FeedDataSettings.query(FeedDataSettings.url == read.feedUrl).fetch_async(1) for read in allUserRead] futures = [FeedDataSettings.get_by_id_async( read.feedUrl) for read in allUserRead] # todo: # get read keys # read mylti async # fdss = [ndb.get_multi_async(for read in allUserRead] # @ndb.tasklet # def get_cart_plus_offers(acct): # cart, offers = yield get_cart_async(acct), get_offers_async(acct) # raise ndb.Return((cart, offers)) # https://developers.google.com/appengine/docs/python/ndb/async#using # todo test keys only and then multy async # (70) 2014-05-26 14:15:05.645 "GET /GetUserReadData" 200 real=4603ms api=0ms overhead=201ms (139 RPCs, cost=28420, billed_ops=[DATASTORE_READ:406]) # (71) 2014-05-26 14:15:01.630 "GET /GetUserReadData" 200 real=3819ms api=0ms overhead=201ms (139 RPCs, cost=28420, billed_ops=[DATASTORE_READ:406]) # (72) 2014-05-26 14:14:57.326 "GET /GetUserReadData" 200 real=4030ms api=0ms overhead=196ms (139 RPCs, cost=28420, billed_ops=[DATASTORE_READ:406]) # (73) 2014-05-26 14:14:52.344 "GET /GetUserReadData" 200 real=4707ms api=0ms overhead=134ms (139 RPCs, cost=28420, billed_ops=[DATASTORE_READ:406]) # (1) 2014-05-26 14:50:43.065 "GET /GetUserReadData" 200 real=737ms api=0ms overhead=2ms (3 RPCs, cost=9520, billed_ops=[DATASTORE_READ:136]) # (2) 2014-05-26 14:50:41.645 "GET /GetUserReadData" 200 real=781ms api=0ms overhead=4ms (3 RPCs, cost=9520, billed_ops=[DATASTORE_READ:136]) # (3) 2014-05-26 14:50:39.951 "GET /GetUserReadData" 200 real=859ms api=0ms overhead=4ms (3 RPCs, cost=9520, billed_ops=[DATASTORE_READ:136]) # (4) 2014-05-26 14:50:38.157 "GET /GetUserReadData" 200 real=856ms api=0ms overhead=5ms (3 RPCs, cost=9520, billed_ops=[DATASTORE_READ:136]) for future in futures: fds = future.get_result() if fds is not None: data[fds.url]['totalCount'] = fds.article_count else: logging.debug('empty future %s', future) self.response.out.write(str(json.dumps(data)))