[PATCH links] Fixes a bug when a user submits all invalid tags we don't try to do an empty insert. Caused by spammers but a bug none the less.
Export this patch
Changelog-fixed: Edge case where all submitted tags are invalid
resulting in an sql error (empty insert).
---
models/org_link.go | 3 +++
models/tag_link_shorts.go | 3 +++
models/tag_links.go | 3 +++
models/tag_listing.go | 3 +++
4 files changed, 12 insertions(+)
diff --git a/models/org_link.go b/models/org_link.go
index 330894c..9e4829e 100644
--- a/models/org_link.go
+++ b/models/org_link.go
@@ -272,6 +272,9 @@ func GetOrgLinksAnalytics(ctx context.Context, opts *database.FilterOptions) ([]
}
func OrgLinkStoreBatch(ctx context.Context, links []*OrgLink) error {
+ if len(links) == 0 {
+ return nil
+ }
err := database.WithTx(ctx, nil, func(tx *sql.Tx) error {
batch := sq.
Insert("org_links").
diff --git a/models/tag_link_shorts.go b/models/tag_link_shorts.go
index 4e0bc6b..6530864 100644
--- a/models/tag_link_shorts.go
+++ b/models/tag_link_shorts.go
@@ -61,6 +61,9 @@ func GetTagLinkShort(ctx context.Context, id int) (*TagLinkShort, error) {
}
func CreateBatchTagLinkShorts(ctx context.Context, linkShortID int, tagIDs []int) error {
+ if len(tagIDs) == 0 {
+ return nil
+ }
err := database.WithTx(ctx, nil, func(tx *sql.Tx) error {
var err error
q := sq.
diff --git a/models/tag_links.go b/models/tag_links.go
index beaf159..9c6a634 100644
--- a/models/tag_links.go
+++ b/models/tag_links.go
@@ -61,6 +61,9 @@ func GetTagLink(ctx context.Context, id int) (*TagLink, error) {
}
func CreateBatchTagLinks(ctx context.Context, linkID int, tagIDs []int) error {
+ if len(tagIDs) == 0 {
+ return nil
+ }
err := database.WithTx(ctx, nil, func(tx *sql.Tx) error {
var err error
q := sq.
diff --git a/models/tag_listing.go b/models/tag_listing.go
index a11a110..a0f05b3 100644
--- a/models/tag_listing.go
+++ b/models/tag_listing.go
@@ -61,6 +61,9 @@ func GetTagListing(ctx context.Context, id int) (*TagListing, error) {
}
func CreateBatchTagListings(ctx context.Context, linkShortID int, tagIDs []int) error {
+ if len(tagIDs) == 0 {
+ return nil
+ }
err := database.WithTx(ctx, nil, func(tx *sql.Tx) error {
var err error
q := sq.
--
2.49.1
Applied.
To git@git.code.netlandish.com:~netlandish/links
001c767..89e69a6 master -> master