|
@@ -280,37 +280,38 @@ def create_test_data(users=5, categories=2, forums=2, topics=1, posts=1):
|
|
|
user2 = User.query.filter_by(id=2).first()
|
|
|
|
|
|
|
|
|
- for i in range(1, categories + 1):
|
|
|
- category_title = "Test Category %s" % i
|
|
|
- category = Category(title=category_title,
|
|
|
- description="Test Description")
|
|
|
- category.save()
|
|
|
- data_created['categories'] += 1
|
|
|
-
|
|
|
-
|
|
|
- for j in range(1, forums + 1):
|
|
|
- if i == 2:
|
|
|
- j += 2
|
|
|
-
|
|
|
- forum_title = "Test Forum %s %s" % (j, i)
|
|
|
- forum = Forum(title=forum_title, description="Test Description",
|
|
|
- category_id=i)
|
|
|
- forum.save()
|
|
|
- data_created['forums'] += 1
|
|
|
-
|
|
|
- for _ in range(1, topics + 1):
|
|
|
-
|
|
|
- topic = Topic(title="Test Title %s" % j)
|
|
|
- post = Post(content="Test Content")
|
|
|
-
|
|
|
- topic.save(post=post, user=user1, forum=forum)
|
|
|
- data_created['topics'] += 1
|
|
|
-
|
|
|
- for _ in range(1, posts + 1):
|
|
|
-
|
|
|
- post = Post(content="Test Post")
|
|
|
- post.save(user=user2, topic=topic)
|
|
|
- data_created['posts'] += 1
|
|
|
+ with db.session.no_autoflush:
|
|
|
+ for i in range(1, categories + 1):
|
|
|
+ category_title = "Test Category %s" % i
|
|
|
+ category = Category(title=category_title,
|
|
|
+ description="Test Description")
|
|
|
+ category.save()
|
|
|
+ data_created['categories'] += 1
|
|
|
+
|
|
|
+
|
|
|
+ for j in range(1, forums + 1):
|
|
|
+ if i == 2:
|
|
|
+ j += 2
|
|
|
+
|
|
|
+ forum_title = "Test Forum %s %s" % (j, i)
|
|
|
+ forum = Forum(title=forum_title, description="Test Description",
|
|
|
+ category_id=i)
|
|
|
+ forum.save()
|
|
|
+ data_created['forums'] += 1
|
|
|
+
|
|
|
+ for _ in range(1, topics + 1):
|
|
|
+
|
|
|
+ topic = Topic(title="Test Title %s" % j)
|
|
|
+ post = Post(content="Test Content")
|
|
|
+ topic.save(post=post, user=user1, forum=forum)
|
|
|
+ data_created['topics'] += 1
|
|
|
+
|
|
|
+ for _ in range(1, posts + 1):
|
|
|
+
|
|
|
+ post = Post(content="Test Post")
|
|
|
+
|
|
|
+ post.save(user=user2, topic=topic)
|
|
|
+ data_created['posts'] += 1
|
|
|
|
|
|
return data_created
|
|
|
|
|
@@ -337,46 +338,27 @@ def insert_bulk_data(topic_count=10, post_count=100):
|
|
|
if not (user1 or user2 or forum):
|
|
|
return False
|
|
|
|
|
|
- db.session.begin(subtransactions=True)
|
|
|
+ with db.session.no_autoflush:
|
|
|
+ for i in range(1, topic_count + 1):
|
|
|
+ last_post_id += 1
|
|
|
|
|
|
- for i in range(1, topic_count + 1):
|
|
|
- last_post_id += 1
|
|
|
+
|
|
|
+ topic = Topic(title="Test Title %s" % i)
|
|
|
+ post = Post(content="First Post")
|
|
|
+ topic.save(post=post, user=user1, forum=forum)
|
|
|
+ created_topics += 1
|
|
|
|
|
|
-
|
|
|
- topic = Topic(title="Test Title %s" % i)
|
|
|
- post = Post(content="First Post")
|
|
|
- topic.save(post=post, user=user1, forum=forum)
|
|
|
- created_topics += 1
|
|
|
+
|
|
|
+ for _ 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
|
|
|
|
|
|
-
|
|
|
- for _ 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
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- created_posts += 1
|
|
|
- posts.append(post)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- db.session.bulk_save_objects(posts)
|
|
|
+ created_posts += 1
|
|
|
+ posts.append(post)
|
|
|
+
|
|
|
+ db.session.bulk_save_objects(posts)
|
|
|
|
|
|
|
|
|
forum.recalculate(last_post=True)
|