コード例 #1
0
ファイル: slice.py プロジェクト: kalmas/LearningRegistry
    def format_data(self,keys_only,docs, keys, forceUnique, current_rt=None):
        sentIDs = []
        prefix = '{"documents":[\n'
        num_sent = 0
        doc_count = 0
        update_resumption_max_results = current_rt and "maxResults" in current_rt and current_rt["maxResults"] != None
        if docs is not None:
            for row in docs:
                doc_count += 1
                alreadySent = (row["id"] in sentIDs)
                if not alreadySent or not forceUnique:
                    sentIDs.append(row["id"])
                    if keys_only:
                        return_data = {"doc_ID":row["id"]}
                    else:
                        # Get the resource data and update with the node timestamp data
                        # That the view has in value['timestamp']
                        resourceData = {}
                        resourceData = row["doc"]
                        return_data = {"doc_ID":row["id"], "resource_data_description":resourceData}
                    yield prefix + json.dumps(return_data)
                    num_sent += 1
                    prefix = ",\n"
                else:
                    log.debug("{0} skipping: alreadySent {1} / forceUnique {2}".format(doc_count, repr(alreadySent), forceUnique))
                    if update_resumption_max_results:
                        current_rt["maxResults"] = current_rt["maxResults"] - 1
        
        if doc_count == 0:
            yield prefix
        
        maxResults = self._get_view_total(keys=keys,resumptionToken=current_rt)
        
        rt = " "
        if self.enable_flow_control:
            if current_rt != None and "offset" in current_rt and current_rt["offset"] is not None:
                offset = current_rt["offset"]
            else:
                offset = 0
                
            if offset+doc_count < maxResults:
                rt = ''' "resumption_token":"{0}", '''.format(resumption_token.get_offset_token(self.service_id, offset=offset+doc_count, keys=keys, maxResults=maxResults))

        
        db  = couchdb.Server(appConfig['couchdb.url'])[appConfig['couchdb.db.resourcedata']]
        yield '\n],'+rt+'"resultCount":'+str(maxResults) +',"viewUpToDate":'+h.isViewUpdated(db,'_design/learningregistry-slice')+'}'
コード例 #2
0
ファイル: slice.py プロジェクト: dbhurley/LearningRegistry
    def format_data(self, keys_only, docs, params, forceUnique, maxResults, current_rt=None):
        try:
            sentIDs = []
            prefix = '{"documents":[\n'
            num_sent = 0
            doc_count = 0
            startkey_docid = None
            startkey = params.get('startkey', None)
            update_resumption_max_results = current_rt and "maxResults" in current_rt and current_rt["maxResults"] != None
            if docs is not None:
                for row in docs:
                    doc_count += 1
                    alreadySent = (row["id"] in sentIDs)
                    if not alreadySent or not forceUnique:
                        sentIDs.append(row["id"])
                        startkey_docid = row["id"]
                        startkey = row['key']
                        if keys_only:
                            return_data = {"doc_ID": row["id"]}
                        else:
                            # Get the resource data and update with the node timestamp data
                            # That the view has in value['timestamp']
                            resourceData = {}
                            resourceData = row["doc"]
                            return_data = {"doc_ID": row["id"], "resource_data_description": resourceData}
                        yield prefix + json.dumps(return_data)
                        num_sent += 1
                        prefix = ",\n"
                    else:
                        log.debug("{0} skipping: alreadySent {1} / forceUnique {2}".format(doc_count, repr(alreadySent), forceUnique))
                        if update_resumption_max_results:
                            current_rt["maxResults"] = current_rt["maxResults"] - 1

            if doc_count == 0:
                yield prefix

            rt = " "
            if self.enable_flow_control:
                #only create resumption_token if we have sent docs, and we have a next doc to start with
                if num_sent < maxResults and startkey_docid is not None:
                    token = resumption_token.get_token_slice(self.service_id, maxResults=maxResults, startkey_docid=startkey_docid,
                                                             startkey=startkey, endkey=params.get('endkey', None),
                                                             any_tags=params.get(ANY_TAGS), identity=params.get(IDENTITY))
                    rt = ''' "resumption_token":"{0}", '''.format(token)
            db = couchdb.Server(appConfig['couchdb.url'])[appConfig['couchdb.db.resourcedata']]
            yield '\n],' + rt + '"resultCount":' + str(maxResults) + ',"viewUpToDate":' + h.isViewUpdated(db, SLICE_DOCUMENT) + '}'
        except Exception as ex:
            print(ex)
コード例 #3
0
    def format_data(self,
                    keys_only,
                    docs,
                    params,
                    forceUnique,
                    maxResults,
                    current_rt=None):
        try:
            sentIDs = []
            prefix = '{"documents":[\n'
            num_sent = 0
            doc_count = 0
            startkey_docid = None
            startkey = params.get('startkey', None)
            update_resumption_max_results = current_rt and "maxResults" in current_rt and current_rt[
                "maxResults"] != None
            if docs is not None:
                for row in docs:
                    doc_count += 1
                    alreadySent = (row["id"] in sentIDs)
                    if not alreadySent or not forceUnique:
                        sentIDs.append(row["id"])
                        startkey_docid = row["id"]
                        startkey = row['key']
                        if keys_only:
                            return_data = {"doc_ID": row["id"]}
                        else:
                            # Get the resource data and update with the node timestamp data
                            # That the view has in value['timestamp']
                            resourceData = {}
                            resourceData = row["doc"]
                            return_data = {
                                "doc_ID": row["id"],
                                "resource_data_description": resourceData
                            }
                        yield prefix + json.dumps(return_data)
                        num_sent += 1
                        prefix = ",\n"
                    else:
                        log.debug(
                            "{0} skipping: alreadySent {1} / forceUnique {2}".
                            format(doc_count, repr(alreadySent), forceUnique))
                        if update_resumption_max_results:
                            current_rt[
                                "maxResults"] = current_rt["maxResults"] - 1

            if doc_count == 0:
                yield prefix

            rt = " "
            if self.enable_flow_control:
                #only create resumption_token if we have sent docs, and we have a next doc to start with
                if num_sent < maxResults and startkey_docid is not None:
                    token = resumption_token.get_token_slice(
                        self.service_id,
                        maxResults=maxResults,
                        startkey_docid=startkey_docid,
                        startkey=startkey,
                        endkey=params.get('endkey', None),
                        any_tags=params.get(ANY_TAGS),
                        identity=params.get(IDENTITY))
                    rt = ''' "resumption_token":"{0}", '''.format(token)
            db = couchdb.Server(
                appConfig['couchdb.url'])[appConfig['couchdb.db.resourcedata']]
            yield '\n],' + rt + '"resultCount":' + str(
                maxResults) + ',"viewUpToDate":' + h.isViewUpdated(
                    db, SLICE_DOCUMENT) + '}'
        except Exception as ex:
            print(ex)