Skip to content
Snippets Groups Projects
Commit 61fd57ef authored by Marcin's avatar Marcin Committed by Marcin
Browse files

during post edition delete only already added tags id

parent 8abdd6e6
No related branches found
No related tags found
2 merge requests!827Merge develop changes to master,!681during post edition delete only already added and going to remove tags id
...@@ -255,18 +255,24 @@ BEGIN ...@@ -255,18 +255,24 @@ BEGIN
block_num = _block_num block_num = _block_num
RETURNING (xmax = 0) as is_new_post, hp.id, hp.author_id, hp.permlink_id, _parent_permlink as post_category, hp.parent_id, hp.community_id, hp.is_valid, hp.is_muted, hp.depth RETURNING (xmax = 0) as is_new_post, hp.id, hp.author_id, hp.permlink_id, _parent_permlink as post_category, hp.parent_id, hp.community_id, hp.is_valid, hp.is_muted, hp.depth
) -- WITH inserted_post ) -- WITH inserted_post
, tagsid_and_posts AS MATERIALIZED (
SELECT prepare_tags FROM hivemind_app.prepare_tags( ARRAY_APPEND(_metadata_tags, _parent_permlink ) )
) -- WITH tagsid_and_posts
, deleted_post_tags AS MATERIALIZED ( , deleted_post_tags AS MATERIALIZED (
DELETE FROM hivemind_app.hive_post_tags hpt DELETE FROM hivemind_app.hive_post_tags hp
USING inserted_post as ip USING hivemind_app.hive_post_tags as hpt
WHERE NOT ip.is_new_post AND hpt.post_id = ip.id JOIN inserted_post as ip ON hpt.post_id = ip.id AND NOT ip.is_new_post
RETURNING * LEFT JOIN tagsid_and_posts as tap ON tap.prepare_tags = hpt.tag_id
WHERE hpt.post_id = hp.post_id AND tap.prepare_tags IS NULL
RETURNING hpt.post_id
) -- WITH deleted_post_tags ) -- WITH deleted_post_tags
, inserts_to_posts_and_tags AS MATERIALIZED ( , inserts_to_posts_and_tags AS MATERIALIZED (
INSERT INTO hivemind_app.hive_post_tags(post_id, tag_id) INSERT INTO hivemind_app.hive_post_tags(post_id, tag_id)
SELECT ip.id, tags.prepare_tags SELECT ip.id, tags.prepare_tags
FROM inserted_post as ip FROM inserted_post as ip
LEFT JOIN deleted_post_tags as dpt ON dpt.post_id = 0 -- there is no post 0, this is only to force execute the deleted_post_tags CTE LEFT JOIN deleted_post_tags as dpt ON dpt.post_id = 0 -- there is no post 0, this is only to force execute the deleted_post_tags CTE
JOIN ( SELECT prepare_tags FROM hivemind_app.prepare_tags( ARRAY_APPEND(_metadata_tags, _parent_permlink ) ) ) as tags ON TRUE JOIN tagsid_and_posts as tags ON TRUE
ON CONFLICT DO NOTHING
) )
SELECT SELECT
ip.is_new_post, ip.is_new_post,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment