async def after_update(self, values: SQLValuesToWrite, old_records: List[DataRecord], new_records: List[DataRecord]): for old_record, record in zip(old_records, new_records): manage_try_add = lambda column, op: ManageLog.add_by_post_changed( self, column, op, POST_TYPES.WIKI, values, old_record, record) manage_try_add_with_diff = lambda column, op: ManageLog.add_by_post_changed( self, column, op, POST_TYPES.WIKI, values, old_record, record, diff_func=diff) title_changed = manage_try_add('title', MOP.POST_TITLE_CHANGE) # 管理日志:标题编辑 content_changed = manage_try_add_with_diff( 'content', MOP.POST_CONTENT_CHANGE) # 管理日志:正文编辑 if title_changed or content_changed: post_stats_do_edit(record['id'], record['user_id']) manage_try_add('ref', MOP.WIKI_REF_CHANGE) # 管理日志:链接编辑 manage_try_add('state', MOP.POST_STATE_CHANGE) # 管理日志:改变状态 manage_try_add('visible', MOP.POST_VISIBLE_CHANGE) # 管理日志:改变可见度 if config.SEARCH_ENABLE: run_in_thread(esdb.es_update_wiki, record['id'])
async def after_update(self, values: SQLValuesToWrite, old_records: List[DataRecord], new_records: List[DataRecord]): for old_record, record in zip(old_records, new_records): manage_try_add = lambda column, op: ManageLog.add_by_post_changed( self, column, op, POST_TYPES.TOPIC, values, old_record, record ) manage_try_add_with_diff = lambda column, op: ManageLog.add_by_post_changed( self, column, op, POST_TYPES.TOPIC, values, old_record, record, diff_func=diff ) title_changed = manage_try_add('title', MOP.POST_TITLE_CHANGE) # 管理日志:标题编辑 content_changed = manage_try_add_with_diff('content', MOP.POST_CONTENT_CHANGE) # 管理日志:正文编辑 if title_changed or content_changed: post_stats_do_edit(record['id'], record['user_id']) Topic.update(edit_count=Topic.edit_count + 1).where(Topic.id == record['id']).execute() manage_try_add('state', MOP.POST_STATE_CHANGE) # 管理日志:状态修改 manage_try_add('visible', MOP.POST_VISIBLE_CHANGE) # 管理日志:改变可见度 manage_try_add('awesome', MOP.TOPIC_AWESOME_CHANGE) # 管理日志:设置精华 manage_try_add('sticky_weight', MOP.TOPIC_STICKY_WEIGHT_CHANGE) # 管理日志:置顶权重 manage_try_add('weight', MOP.TOPIC_WEIGHT_CHANGE) # 管理日志:修改权重 # 管理日志:移动板块 if manage_try_add('board_id', MOP.TOPIC_BOARD_MOVE): post_stats_topic_move(old_record['board_id'], record['board_id'], record['id']) if config.SEARCH_ENABLE: run_in_thread(esdb.es_update_topic, record['id'])
async def on_complete(id_lst: IDList): # 创建完成后添加入日志 for id_ in id_lst: # TODO: 管理日志:新建板块 # ManageLogModel.post_new(self, POST_TYPES.BOARD, record) if config.SEARCH_ENABLE: run_in_thread(esdb.es_update_topic, id_)
async def after_insert(self, values_lst: List[SQLValuesToWrite], records: List[DataRecord]): for record in records: # 添加统计记录 post_stats_new(POST_TYPES.WIKI, record['id']) # 添加创建记录 ManageLog.post_new(self, POST_TYPES.WIKI, record) if config.SEARCH_ENABLE: run_in_thread(esdb.es_update_wiki, record['id'])
async def after_update(self, values: SQLValuesToWrite, old_records: List[DataRecord], new_records: List[DataRecord]): for old_record, record in zip(old_records, new_records): # 管理日志:修改评论状态 ManageLog.add_by_post_changed(self, 'state', MOP.POST_STATE_CHANGE, POST_TYPES.COMMENT, values, old_record, record) if config.SEARCH_ENABLE: run_in_thread(esdb.es_update_comment, record['id'])
async def after_insert(self, values_lst: List[SQLValuesToWrite], records: List[DataRecord]): for record in records: # if self.do_mentions: # self.do_mentions(record['user_id'], POST_TYPES.TOPIC, record['id'], { # 'title': record['title'], # }) # 添加统计记录 post_stats_topic_new(record['board_id'], record['id']) if config.SEARCH_ENABLE: run_in_thread(esdb.es_update_topic, record['id'])
async def after_insert(self, values_lst: List[SQLValuesToWrite], records: List[DataRecord]): for record in records: post_stats_do_comment(record['related_type'], record['related_id'], record['id']) post_number = Comment.select().where( Comment.related_id == record['related_id'], Comment.id <= record['id']).count() Comment.update(post_number=post_number).where( Comment.id == record['id']).execute() if self.do_mentions: # 创建提醒 loc = [record['related_type'], record['related_id']] # record['related_id']: memoryview loc_title = POST_TYPES.get_post_title_by_list(loc)[ get_bytes_from_blob(record['related_id'])] related = [POST_TYPES.COMMENT, record['id']] self.do_mentions(record['user_id'], loc_title, loc, related) if config.SEARCH_ENABLE: run_in_thread(esdb.es_update_comment, record['id'])