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

Commit

Permalink
index追加
Browse files Browse the repository at this point in the history
  • Loading branch information
acidlemon committed Nov 25, 2023
1 parent 1e5d77c commit f6a1308
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 38 deletions.
5 changes: 0 additions & 5 deletions webapp/go/top_handler.go
Expand Up @@ -80,11 +80,6 @@ func getStreamerThemeHandler(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get user: "+err.Error())
}

// themeModel := ThemeModel{}
// if err := tx.GetContext(ctx, &themeModel, "SELECT * FROM themes WHERE user_id = ?", userModel.ID); err != nil {
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to get user theme: "+err.Error())
// }

if err := tx.Commit(); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to commit: "+err.Error())
}
Expand Down
32 changes: 0 additions & 32 deletions webapp/go/user_handler.go
Expand Up @@ -143,14 +143,6 @@ func getIconHandler(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get user icon: "+err.Error())
}

// if err := tx.GetContext(ctx, &image, "SELECT image FROM icons WHERE user_id = ?", user.ID); err != nil {
// if errors.Is(err, sql.ErrNoRows) {
// return c.File(fallbackImage)
// } else {
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to get user icon: "+err.Error())
// }
// }

return c.Blob(http.StatusOK, "image/jpeg", image)

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

iconHash := sha256.Sum256(req.Image)

// files, err := filepath.Glob(fmt.Sprintf("../img/user-%d-*.jpg", userID))
// if err != nil {
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to glob: "+err.Error())
// }
// for _, f := range files {
// if err := os.Remove(f); err != nil {
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to remove file: "+err.Error())
// }
// }

os.WriteFile(fmt.Sprintf("../img/user-%d.jpg", userID), req.Image, 0644)

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

// if _, err := tx.ExecContext(ctx, "DELETE FROM icons WHERE user_id = ?", userID); err != nil {
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete old user icon: "+err.Error())
// }

// _, err = tx.ExecContext(ctx, "INSERT INTO icons (user_id, image) VALUES (?, ?)", userID, req.Image)
// if err != nil {
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to insert new user icon: "+err.Error())
// }

_, err = tx.ExecContext(ctx, "UPDATE users SET icon_hash = ? WHERE id = ?", fmt.Sprintf("%x", iconHash), userID)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to insert new user icon: "+err.Error())
}

// // iconID, err := rs.LastInsertId()
// // if err != nil {
// // return echo.NewHTTPError(http.StatusInternalServerError, "failed to get last inserted icon id: "+err.Error())
// // }

if err := tx.Commit(); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to commit: "+err.Error())
}
Expand Down
3 changes: 2 additions & 1 deletion webapp/sql/initdb.d/10_schema.sql
Expand Up @@ -110,7 +110,8 @@ CREATE TABLE `ng_words` (
`user_id` BIGINT NOT NULL,
`livestream_id` BIGINT NOT NULL,
`word` VARCHAR(255) NOT NULL,
`created_at` BIGINT NOT NULL
`created_at` BIGINT NOT NULL,
INDEX `idx_ng_words_livestream_id_user_id_created_at` (`livestream_id`, `user_id`, `created_at` DESC)
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
CREATE INDEX ng_words_word ON ng_words(`word`);

Expand Down

0 comments on commit f6a1308

Please sign in to comment.