aboutsummaryrefslogtreecommitdiff
path: root/src/guff/models/post.cr
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-03-09 10:05:30 -0500
committerPaul Duncan <pabs@pablotron.org>2016-03-09 10:05:30 -0500
commit4ee569a4707e3d40c44125f3b933b9220d507c1d (patch)
tree17ff63cd25d9456c2ccc3e08d071bcd818a4ac3e /src/guff/models/post.cr
parentda8e370c2f9e8fa11c3c52cff9de44a0d201bf98 (diff)
downloadold-guff-4ee569a4707e3d40c44125f3b933b9220d507c1d.tar.bz2
old-guff-4ee569a4707e3d40c44125f3b933b9220d507c1d.zip
refactor set_tags
Diffstat (limited to 'src/guff/models/post.cr')
-rw-r--r--src/guff/models/post.cr42
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