aboutsummaryrefslogtreecommitdiff
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
parentda8e370c2f9e8fa11c3c52cff9de44a0d201bf98 (diff)
downloadold-guff-4ee569a4707e3d40c44125f3b933b9220d507c1d.tar.bz2
old-guff-4ee569a4707e3d40c44125f3b933b9220d507c1d.zip
refactor set_tags
-rw-r--r--TODO.md1
-rw-r--r--src/guff/models/post.cr42
2 files changed, 15 insertions, 28 deletions
diff --git a/TODO.md b/TODO.md
index 158d072..f8543db 100644
--- a/TODO.md
+++ b/TODO.md
@@ -6,3 +6,4 @@ TODO
* readonly-db connection (using `PRAGMA query_only`)
* per-site public/ directories
* history (in `PostModel#update_post`)
+* triggers for removing unused `post_tag` and `tag` entries
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