Exemplo n.º 1
0
    def getReadData(self, feedUrl):
        readDataAttr = 'readData__' + self.ud.app_username + \
            '__' + str(feedUrl).translate(None, '.')
        readData = ReadData.get_by_id(readDataAttr)
        if readData is None:
            readData = ReadData(app_username=self.ud.app_username, feedUrl=feedUrl, readData='', readCount=0, id=readDataAttr)
            readData.put()

        return readData
Exemplo n.º 2
0
 def getReadData(self, feedUrl, ud):
     readDataAttr = 'readData__' + ud.app_username + \
         '__' + str(feedUrl).translate(None, '.')
     readData = ReadData.get_by_id(readDataAttr)
     if readData is not None:
         return readData.readData, readData.readCount
     else:
         return '', 0
Exemplo n.º 3
0
    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)))