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
评论列表
文章目录