diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/guff/models/post.cr | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/src/guff/models/post.cr b/src/guff/models/post.cr index 560b36d..9a740bc 100644 --- a/src/guff/models/post.cr +++ b/src/guff/models/post.cr @@ -395,7 +395,6 @@ module Guff site_id: site_id, post_id: post_id, tags: tags, - use_transaction: false, ) end end @@ -422,23 +421,6 @@ module Guff site_id = nil : Int?, post_id = nil : Int?, tags = [] of String : Array(String)?, - use_transaction = true : Bool - ) - if use_transaction - transaction do - raw_set_tags(site_id, post_id, tags) - end - else - raw_set_tags(site_id, post_id, tags) - end - - nil - end - - private def raw_set_tags( - site_id = nil : Int?, - post_id = nil : Int?, - tags = [] of String : Array(String)?, ) return unless post_id && tags @@ -448,19 +430,23 @@ module Guff "post_id": post_id.to_s, } - # delete existing post tags - query(:set_tags_delete, args, nil) + transaction do + # delete existing post tags + query(:set_tags_delete, args, nil) - if tags.size > 0 - @models.tag.add_tags(tags) + if tags.size > 0 + @models.tag.add_tags(tags) - # add new post tags - query(:set_tags_insert, args, { - "tags": tags.map { |tag| - "'" + @db.quote(tag) + "'" - }.join(','), - }) + # add new post tags + query(:set_tags_insert, args, { + "tags": tags.map { |tag| + "'" + @db.quote(tag) + "'" + }.join(','), + }) + end end + + nil end end end |