Beispiel #1
0
    def batch_load_fn(self, ids):
        query = DBSession().query(CommentModel).filter(
            CommentModel.article_id.in_(ids))
        article_comments = {}
        for comment in query.all():
            if comment.article_id in article_comments:
                article_comments[comment.article_id].append(comment)
            else:
                article_comments[comment.article_id] = [comment]

        return Promise.resolve(
            [article_comments.get(article_id, None) for article_id in ids])
Beispiel #2
0
 def batch_load_fn(self, ids):
     query = DBSession().query(ArticleModel).filter(
         ArticleModel.id.in_(ids))
     articles = dict([(article.id, article) for article in query.all()])
     return Promise.resolve([articles.get(id, None) for id in ids])