Skip to content

Commit

Permalink
NGワード追加時のチェックをgoで実施するよう変更 8460
Browse files Browse the repository at this point in the history
  • Loading branch information
シン・ウー馬場ーイー222 committed Nov 25, 2023
1 parent 6cab4de commit ba3ecbc
Show file tree
Hide file tree
Showing 5 changed files with 388 additions and 385 deletions.
2 changes: 1 addition & 1 deletion home/isucon/bin/prepare.sh
Expand Up @@ -35,6 +35,6 @@ sudo truncate -s 0 "${nginx_access_log}"
# sudo systemctl reload nginx

# cleanup
rm -f "${result_dir}"/*.*
#rm -f "${result_dir}"/*.*

echo "OK"
20 changes: 6 additions & 14 deletions home/isucon/webapp/go/livecomment_handler.go
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
"strconv"
"strings"
"time"

"github.com/jmoiron/sqlx"
Expand Down Expand Up @@ -395,20 +396,11 @@ func moderateHandler(c echo.Context) error {
}

for _, livecomment := range livecomments {
query := `
DELETE FROM livecomments
WHERE
id = ? AND
livestream_id = ? AND
(SELECT COUNT(*)
FROM
(SELECT ? AS text) AS texts
INNER JOIN
(SELECT CONCAT('%', ?, '%') AS pattern) AS patterns
ON texts.text LIKE patterns.pattern) >= 1;
`
if _, err := tx.ExecContext(ctx, query, livecomment.ID, livestreamID, livecomment.Comment, ngword.Word); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete old livecomments that hit spams: "+err.Error())
if strings.Contains(livecomment.Comment, ngword.Word) {
query := `DELETE FROM livecomments WHERE id = ? AND livestream_id = ?`
if _, err := tx.ExecContext(ctx, query, livecomment.ID, livestreamID); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete old livecomments that hit spams: "+err.Error())
}
}
}
}
Expand Down

0 comments on commit ba3ecbc

Please sign in to comment.