From 735cd399b6148af6065ea88ee9abd72bc9e0e7fd Mon Sep 17 00:00:00 2001 From: Asa <26807394+a01sa01to@users.noreply.github.com> Date: Sat, 25 Nov 2023 13:53:01 +0900 Subject: [PATCH] =?UTF-8?q?go=20=E3=81=A7=20index=20=E3=81=AF=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/main.go | 9 +++++++++ sql/init.sql | 2 -- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/go/main.go b/go/main.go index 174e580..3eb6751 100644 --- a/go/main.go +++ b/go/main.go @@ -118,6 +118,15 @@ func initializeHandler(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, "failed to initialize: "+err.Error()) } + indexes := []string{ + "CREATE INDEX `livestreams_user_id` ON `livestreams` (`user_id`)", + } + for _, index := range indexes { + if _, err := dbConn.Exec(index); err != nil { + c.Logger().Warnf("failed to create index: %s", err) + } + } + c.Request().Header.Add("Content-Type", "application/json;charset=utf-8") return c.JSON(http.StatusOK, InitializeResponse{ Language: "golang", diff --git a/sql/init.sql b/sql/init.sql index a02fa27..399dea1 100644 --- a/sql/init.sql +++ b/sql/init.sql @@ -23,5 +23,3 @@ ALTER TABLE `tags` auto_increment = 1; ALTER TABLE `livecomments` auto_increment = 1; ALTER TABLE `livestreams` auto_increment = 1; ALTER TABLE `users` auto_increment = 1; - -CREATE INDEX `livestream_tags_tag_id` ON `livestream_tags` (`livestream_id`);