Skip to content

Commit ba3ecbc

Browse files
author
シン・ウー馬場ーイー222
committed
NGワード追加時のチェックをgoで実施するよう変更 8460
1 parent 6cab4de commit ba3ecbc

5 files changed

Lines changed: 388 additions & 385 deletions

File tree

home/isucon/bin/prepare.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ sudo truncate -s 0 "${nginx_access_log}"
3535
# sudo systemctl reload nginx
3636

3737
# cleanup
38-
rm -f "${result_dir}"/*.*
38+
#rm -f "${result_dir}"/*.*
3939

4040
echo "OK"

home/isucon/webapp/go/livecomment_handler.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"net/http"
1010
"strconv"
11+
"strings"
1112
"time"
1213

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

397398
for _, livecomment := range livecomments {
398-
query := `
399-
DELETE FROM livecomments
400-
WHERE
401-
id = ? AND
402-
livestream_id = ? AND
403-
(SELECT COUNT(*)
404-
FROM
405-
(SELECT ? AS text) AS texts
406-
INNER JOIN
407-
(SELECT CONCAT('%', ?, '%') AS pattern) AS patterns
408-
ON texts.text LIKE patterns.pattern) >= 1;
409-
`
410-
if _, err := tx.ExecContext(ctx, query, livecomment.ID, livestreamID, livecomment.Comment, ngword.Word); err != nil {
411-
return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete old livecomments that hit spams: "+err.Error())
399+
if strings.Contains(livecomment.Comment, ngword.Word) {
400+
query := `DELETE FROM livecomments WHERE id = ? AND livestream_id = ?`
401+
if _, err := tx.ExecContext(ctx, query, livecomment.ID, livestreamID); err != nil {
402+
return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete old livecomments that hit spams: "+err.Error())
403+
}
412404
}
413405
}
414406
}

0 commit comments

Comments
 (0)