aboutsummaryrefslogtreecommitdiff
path: root/server/szurubooru/api/post_api.py
diff options
context:
space:
mode:
authorrr-2016-08-26 14:59:14 +0200
committerrr-2016-08-26 15:09:08 +0200
commitffb87f1650885a6227471634825dc28ed3d6737a (patch)
tree38b5d3bc0410f053f35b23dd9a872203180f635f /server/szurubooru/api/post_api.py
parentbb369efa995f6ca2f07415f9d0890582f6e17627 (diff)
server/posts: defer flush; save content lazily
Rather than flushing the post right away only to find out that there were validation errors, try to postpone flushing for as long as possible. The previous behavior has led to too eager spending of post IDs - each flush calls nextval(post_id_seq), and postgres sequences are not affected by transaction rollbacks, so each erroneous post creation discarded a post ID, which has led to gaps in post IDs.
Diffstat (limited to 'server/szurubooru/api/post_api.py')
-rw-r--r--server/szurubooru/api/post_api.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/server/szurubooru/api/post_api.py b/server/szurubooru/api/post_api.py
index 34e007c..e4d4975 100644
--- a/server/szurubooru/api/post_api.py
+++ b/server/szurubooru/api/post_api.py
@@ -44,9 +44,6 @@ def create_post(ctx, _params=None):
content, tag_names, None if anonymous else ctx.user)
if len(new_tags):
auth.verify_privilege(ctx.user, 'tags:create')
- db.session.flush()
- for tag in new_tags:
- snapshots.create(tag, None if anonymous else ctx.user)
posts.update_post_safety(post, safety)
posts.update_post_source(post, source)
posts.update_post_relations(post, relations)
@@ -55,7 +52,10 @@ def create_post(ctx, _params=None):
if ctx.has_file('thumbnail'):
posts.update_post_thumbnail(post, ctx.get_file('thumbnail'))
ctx.session.add(post)
+ ctx.session.flush()
snapshots.create(post, None if anonymous else ctx.user)
+ for tag in new_tags:
+ snapshots.create(tag, None if anonymous else ctx.user)
ctx.session.commit()
tags.export_to_json()
return _serialize_post(ctx, post)

© 2015 - 2026 Jakob L. Kreuze