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

Commit

Permalink
statsが重そうなやつ
Browse files Browse the repository at this point in the history
  • Loading branch information
acidlemon committed Nov 25, 2023
1 parent d1ab38f commit b968187
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 4 additions & 6 deletions webapp/go/stats_handler.go
Expand Up @@ -96,20 +96,18 @@ func getUserStatisticsHandler(c echo.Context) error {
for _, user := range users {
var reactions int64
query := `
SELECT COUNT(*) FROM users u
INNER JOIN livestreams l ON l.user_id = u.id
SELECT COUNT(*) FROM livestreams
INNER JOIN reactions r ON r.livestream_id = l.id
WHERE u.id = ?`
WHERE l.user_id = ?`
if err := tx.GetContext(ctx, &reactions, query, user.ID); err != nil && !errors.Is(err, sql.ErrNoRows) {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to count reactions: "+err.Error())
}

var tips int64
query = `
SELECT IFNULL(SUM(l2.tip), 0) FROM users u
INNER JOIN livestreams l ON l.user_id = u.id
SELECT IFNULL(SUM(l2.tip), 0) FROM livestreams
INNER JOIN livecomments l2 ON l2.livestream_id = l.id
WHERE u.id = ?`
WHERE l.user_id = ?`
if err := tx.GetContext(ctx, &tips, query, user.ID); err != nil && !errors.Is(err, sql.ErrNoRows) {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to count tips: "+err.Error())
}
Expand Down
6 changes: 4 additions & 2 deletions webapp/sql/initdb.d/10_schema.sql
Expand Up @@ -46,7 +46,8 @@ CREATE TABLE `livestreams` (
`playlist_url` VARCHAR(255) NOT NULL,
`thumbnail_url` VARCHAR(255) NOT NULL,
`start_at` BIGINT NOT NULL,
`end_at` BIGINT NOT NULL
`end_at` BIGINT NOT NULL,
INDEX `idx_livestreams_user_id` (`user_id`)
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;

-- ライブ配信予約枠
Expand Down Expand Up @@ -117,5 +118,6 @@ CREATE TABLE `reactions` (
`livestream_id` BIGINT NOT NULL,
-- :innocent:, :tada:, etc...
`emoji_name` VARCHAR(255) NOT NULL,
`created_at` BIGINT NOT NULL
`created_at` BIGINT NOT NULL,
INDEX `idx_reactions_livestream_id` (`livestream_id`)
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;

0 comments on commit b968187

Please sign in to comment.