示例#1
0
文件: thing.py 项目: JBTech/reddit
    def _cursor(self):
        # TODO why was this even here?
        # get_cols = bool(self._sort_param)
        get_cols = False
        params = (self._kind._type_id, get_cols, self._sort, self._limit, self._offset, self._rules)
        if self._use_data:
            c = tdb.find_data(*params)
        else:
            c = tdb.find_things(*params)

        # TODO simplfy this! get_cols is always false?
        # called on a bunch of rows to fetch their properties in batch
        def row_fn(rows):
            # if have a sort, add the sorted column to the results
            if get_cols:
                extra_props = {}
                for r in rows:
                    for sc in (s.col for s in self._sort):
                        # dict of ids to the extra sort params
                        props = extra_props.setdefault(r.thing_id, {})
                        props[sc] = getattr(r, sc)
                _ids = extra_props.keys()
            else:
                _ids = rows
                extra_props = {}
            return self._kind._byID(_ids, self._data, False, extra_props)

        return Results(c, row_fn, True)
示例#2
0
文件: thing.py 项目: xxl007/reddit
    def _cursor(self):
        #TODO why was this even here?
        #get_cols = bool(self._sort_param)
        get_cols = False
        params = (self._kind._type_id, get_cols, self._sort, self._limit,
                  self._offset, self._rules)
        if self._use_data:
            c = tdb.find_data(*params)
        else:
            c = tdb.find_things(*params)

        #TODO simplfy this! get_cols is always false?
        #called on a bunch of rows to fetch their properties in batch
        def row_fn(rows):
            #if have a sort, add the sorted column to the results
            if get_cols:
                extra_props = {}
                for r in rows:
                    for sc in (s.col for s in self._sort):
                        #dict of ids to the extra sort params
                        props = extra_props.setdefault(r.thing_id, {})
                        props[sc] = getattr(r, sc)
                _ids = extra_props.keys()
            else:
                _ids = rows
                extra_props = {}
            return self._kind._byID(_ids,
                                    data=self._data,
                                    return_dict=False,
                                    stale=self._stale,
                                    extra_props=extra_props)

        return Results(c, row_fn, True)