db.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:yo 作者: steemit 项目源码 文件源码
def create_notifications(self, notifications):
        results = []

        # create non-existant users before creating notifications
        usernames = []
        for notification in notifications:
            usernames.append(notification['to_username'])
            usernames.append(notification.get('from_username'))
        usernames = set(u for u in usernames if u)

        results.append(await self.create_users(usernames))

        # group notifications by keys to allow multi-row inserts
        # grouped_notifications = toolz.groupby(lambda x: tuple(x.keys()),
        #                                      notifications)
        # logger.debug('create_notifications',
        #             notification_count=len(notifications),
        #             group_count=len(grouped_notifications.keys()))
        #futures = []

        wwwpoll_columns = set(c.name for c in wwwpoll_table.c._all_columns)
        async with self.async_engine.acquire() as conn:
            for n in notifications:
                results.append(await
                               conn.execute(notifications_table.insert().values(**n)))
                n2 = toolz.keyfilter(lambda k: k in wwwpoll_columns, n)
                results.append(await conn.execute(wwwpoll_table.insert().values(**n2)))
        return all(results)

    # notification retrieval methods

    # pylint: disable=too-many-arguments,too-many-locals
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号