Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit f6a1308

Browse files
committed
index追加
1 parent 1e5d77c commit f6a1308

File tree

3 files changed

+2
-38
lines changed

3 files changed

+2
-38
lines changed

webapp/go/top_handler.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ func getStreamerThemeHandler(c echo.Context) error {
8080
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get user: "+err.Error())
8181
}
8282

83-
// themeModel := ThemeModel{}
84-
// if err := tx.GetContext(ctx, &themeModel, "SELECT * FROM themes WHERE user_id = ?", userModel.ID); err != nil {
85-
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to get user theme: "+err.Error())
86-
// }
87-
8883
if err := tx.Commit(); err != nil {
8984
return echo.NewHTTPError(http.StatusInternalServerError, "failed to commit: "+err.Error())
9085
}

webapp/go/user_handler.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,6 @@ func getIconHandler(c echo.Context) error {
143143
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get user icon: "+err.Error())
144144
}
145145

146-
// if err := tx.GetContext(ctx, &image, "SELECT image FROM icons WHERE user_id = ?", user.ID); err != nil {
147-
// if errors.Is(err, sql.ErrNoRows) {
148-
// return c.File(fallbackImage)
149-
// } else {
150-
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to get user icon: "+err.Error())
151-
// }
152-
// }
153-
154146
return c.Blob(http.StatusOK, "image/jpeg", image)
155147

156148
// c.Response().Header().Set("x-accel-redirect", fmt.Sprintf("/img/%s", filepath.Base(files[0])))
@@ -177,16 +169,6 @@ func postIconHandler(c echo.Context) error {
177169

178170
iconHash := sha256.Sum256(req.Image)
179171

180-
// files, err := filepath.Glob(fmt.Sprintf("../img/user-%d-*.jpg", userID))
181-
// if err != nil {
182-
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to glob: "+err.Error())
183-
// }
184-
// for _, f := range files {
185-
// if err := os.Remove(f); err != nil {
186-
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to remove file: "+err.Error())
187-
// }
188-
// }
189-
190172
os.WriteFile(fmt.Sprintf("../img/user-%d.jpg", userID), req.Image, 0644)
191173

192174
tx, err := dbConn.BeginTxx(ctx, nil)
@@ -195,25 +177,11 @@ func postIconHandler(c echo.Context) error {
195177
}
196178
defer tx.Rollback()
197179

198-
// if _, err := tx.ExecContext(ctx, "DELETE FROM icons WHERE user_id = ?", userID); err != nil {
199-
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete old user icon: "+err.Error())
200-
// }
201-
202-
// _, err = tx.ExecContext(ctx, "INSERT INTO icons (user_id, image) VALUES (?, ?)", userID, req.Image)
203-
// if err != nil {
204-
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to insert new user icon: "+err.Error())
205-
// }
206-
207180
_, err = tx.ExecContext(ctx, "UPDATE users SET icon_hash = ? WHERE id = ?", fmt.Sprintf("%x", iconHash), userID)
208181
if err != nil {
209182
return echo.NewHTTPError(http.StatusInternalServerError, "failed to insert new user icon: "+err.Error())
210183
}
211184

212-
// // iconID, err := rs.LastInsertId()
213-
// // if err != nil {
214-
// // return echo.NewHTTPError(http.StatusInternalServerError, "failed to get last inserted icon id: "+err.Error())
215-
// // }
216-
217185
if err := tx.Commit(); err != nil {
218186
return echo.NewHTTPError(http.StatusInternalServerError, "failed to commit: "+err.Error())
219187
}

webapp/sql/initdb.d/10_schema.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ CREATE TABLE `ng_words` (
110110
`user_id` BIGINT NOT NULL,
111111
`livestream_id` BIGINT NOT NULL,
112112
`word` VARCHAR(255) NOT NULL,
113-
`created_at` BIGINT NOT NULL
113+
`created_at` BIGINT NOT NULL,
114+
INDEX `idx_ng_words_livestream_id_user_id_created_at` (`livestream_id`, `user_id`, `created_at` DESC)
114115
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
115116
CREATE INDEX ng_words_word ON ng_words(`word`);
116117

0 commit comments

Comments
 (0)