本文整理汇总了Python中flaskbb.forum.models.Topic.last_updated方法的典型用法代码示例。如果您正苦于以下问题:Python Topic.last_updated方法的具体用法?Python Topic.last_updated怎么用?Python Topic.last_updated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flaskbb.forum.models.Topic
的用法示例。
在下文中一共展示了Topic.last_updated方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insert_bulk_data
# 需要导入模块: from flaskbb.forum.models import Topic [as 别名]
# 或者: from flaskbb.forum.models.Topic import last_updated [as 别名]
def insert_bulk_data(topic_count=10, post_count=100):
"""Creates a specified number of topics in the first forum with
each topic containing a specified amount of posts.
Returns the number of created topics and posts.
:param topics: The amount of topics in the forum.
:param posts: The number of posts in each topic.
"""
user1 = User.query.filter_by(id=1).first()
user2 = User.query.filter_by(id=2).first()
forum = Forum.query.filter_by(id=1).first()
last_post = Post.query.order_by(Post.id.desc()).first()
last_post_id = 1 if last_post is None else last_post.id
created_posts = 0
created_topics = 0
posts = []
if not (user1 or user2 or forum):
return False
db.session.begin(subtransactions=True)
for i in range(1, topic_count + 1):
last_post_id += 1
# create a topic
topic = Topic(title="Test Title %s" % i)
post = Post(content="First Post")
topic.save(post=post, user=user1, forum=forum)
created_topics += 1
# create some posts in the topic
for j in range(1, post_count + 1):
last_post_id += 1
post = Post(content="Some other Post", user=user2, topic=topic.id)
topic.last_updated = post.date_created
topic.post_count += 1
# FIXME: Is there a way to ignore IntegrityErrors?
# At the moment, the first_post_id is also the last_post_id.
# This does no harm, except that in the forums view, you see
# the information for the first post instead of the last one.
# I run a little benchmark:
# 5.3643078804 seconds to create 100 topics and 10000 posts
# Using another method (where data integrity is ok) I benchmarked
# these stats:
# 49.7832770348 seconds to create 100 topics and 10000 posts
# Uncomment the line underneath and the other line to reduce
# performance but fixes the above mentioned problem.
#topic.last_post_id = last_post_id
created_posts += 1
posts.append(post)
# uncomment this and delete the one below, also uncomment the
# topic.last_post_id line above. This will greatly reduce the
# performance.
#db.session.bulk_save_objects(posts)
db.session.bulk_save_objects(posts)
# and finally, lets update some stats
forum.recalculate(last_post=True)
user1.recalculate()
user2.recalculate()
return created_topics, created_posts