def after_insert(self, raw_post: Dict, values_lst: List[SQLValuesToWrite], records: List[DataRecord]): for record in records: statistic_add_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()
def after_insert(self, raw_post: Dict, values_lst: List[SQLValuesToWrite], records: List[DataRecord]): for record in records: statistic_add_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: self.do_mentions(record['user_id'], POST_TYPES.COMMENT, record['id'], { 'comment_info': { 'related_type': record['related_type'], 'related_id': record['related_id'], } })
async def after_insert(self, raw_post: Dict, values: SQLValuesToWrite, record: DataRecord): 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)[ record['related_id'].tobytes()] related = [POST_TYPES.COMMENT, record['id']] self.do_mentions(record['user_id'], loc_title, loc, related)
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'])
def work(): try: db.execute_sql('DROP TABLE statistic24h;') db.execute_sql('ALTER TABLE "user" ADD COLUMN "visible" INTEGER NULL DEFAULT NULL;') db.execute_sql('ALTER TABLE "user" ADD COLUMN "user_id" BYTEA NULL DEFAULT NULL;') db.execute_sql('ALTER TABLE "user" ADD COLUMN "reset_key" BYTEA NULL DEFAULT NULL;') db.execute_sql('ALTER TABLE "user" ADD COLUMN "avatar" TEXT NULL DEFAULT NULL;') db.execute_sql('ALTER TABLE "user" ADD COLUMN "type" INTEGER DEFAULT 0;') db.execute_sql('ALTER TABLE "user" ADD COLUMN "url" TEXT NULL DEFAULT NULL;') db.execute_sql('ALTER TABLE "user" ADD COLUMN "location" TEXT NULL DEFAULT NULL;') db.execute_sql('ALTER TABLE "user" ADD COLUMN "access_time" BIGINT NULL DEFAULT NULL;') db.execute_sql('ALTER TABLE "user" ADD COLUMN "last_check_in_time" BIGINT NULL DEFAULT NULL;') db.execute_sql('ALTER TABLE "user" ADD COLUMN "check_in_his" INT DEFAULT 0;') db.execute_sql('ALTER TABLE "user" ADD COLUMN "exp" INT DEFAULT 0;') db.execute_sql('ALTER TABLE "user" RENAME "reg_time" TO "time";') db.execute_sql('ALTER TABLE "board" RENAME "creator_id" TO "user_id";') db.execute_sql('ALTER TABLE "comment" ADD COLUMN "post_number" INTEGER NULL;') db.execute_sql('ALTER TABLE "statistic" ADD COLUMN "bookmark_count" INTEGER DEFAULT 0;') db.execute_sql('ALTER TABLE "statistic" ADD COLUMN "upvote_count" INTEGER DEFAULT 0;') db.execute_sql('ALTER TABLE "statistic" ADD COLUMN "downvote_count" INTEGER DEFAULT 0;') db.execute_sql('ALTER TABLE "statistic" ADD COLUMN "thank_count" INTEGER DEFAULT 0;') db.execute_sql('ALTER TABLE "statistic" ADD COLUMN "vote_weight" BIGINT DEFAULT 0;') db.execute_sql('ALTER TABLE "statistic" ADD COLUMN "bookmarked_users" BYTEA[] NULL;') db.execute_sql('ALTER TABLE "statistic" ADD COLUMN "upvoted_users" BYTEA[] NULL;') db.execute_sql('ALTER TABLE "statistic" ADD COLUMN "downvoted_users" BYTEA[] NULL;') db.execute_sql('ALTER TABLE "statistic" ADD COLUMN "thanked_users" BYTEA[] NULL;') except Exception as e: print(e) print('failed') db.rollback() for i in Comment.select(): post_number = Comment.select().where(Comment.related_id == i.related_id, Comment.id <= i.id).count() Comment.update(post_number=post_number).where(Comment.id == i.id).execute()