Fixed indexing on m:n table, as well as added seeding function
This commit is contained in:
parent
66f9df86d8
commit
205adeb118
@ -48,6 +48,7 @@ services:
|
||||
DATABASE_URL: "postgresql://serverctl:serverctlsecret@db/serverctl"
|
||||
ports:
|
||||
- "8080:8080"
|
||||
- "6060:6060" # Profiler optional
|
||||
logging: *loki-logging
|
||||
depends_on:
|
||||
- db_migrator
|
||||
|
@ -0,0 +1,10 @@
|
||||
-- Write your migrate up statements here
|
||||
|
||||
create index member_id_project_member_idx on sctl_project_member (member_id);
|
||||
|
||||
---- create above / drop below ----
|
||||
|
||||
drop index member_id_project_member_idx;
|
||||
|
||||
-- Write your migrate down statements here. If this migration is irreversible
|
||||
-- Then delete the separator line above.
|
@ -0,0 +1,9 @@
|
||||
-- Write your migrate up statements here
|
||||
|
||||
create index project_id_project_member_idx on sctl_project_member (project_id);
|
||||
|
||||
---- create above / drop below ----
|
||||
|
||||
drop index project_id_project_member_idx;
|
||||
-- Write your migrate down statements here. If this migration is irreversible
|
||||
-- Then delete the separator line above.
|
@ -29,6 +29,7 @@ require (
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
|
||||
github.com/golang/protobuf v1.5.0 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
||||
github.com/jackc/pgconn v1.11.0 // indirect
|
||||
github.com/jackc/pgio v1.0.0 // indirect
|
||||
|
@ -437,6 +437,8 @@ github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/dgraph-io/ristretto"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
@ -10,10 +11,13 @@ import (
|
||||
"github.com/eko/gocache/store"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-co-op/gocron"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"serverctl/pkg/application/projects"
|
||||
@ -23,6 +27,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
import _ "net/http/pprof"
|
||||
|
||||
func setupLogger() *zap.Logger {
|
||||
highPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
|
||||
return lvl >= zapcore.ErrorLevel
|
||||
@ -269,5 +275,57 @@ func main() {
|
||||
projectsRepository := postgres.NewProjectsRepository(database)
|
||||
projectsService := projects.NewService(logger, projectsRepository, cacheM)
|
||||
|
||||
setupProfiler()
|
||||
addSeedData(database, usersRepository, projectsRepository)
|
||||
setupApi(logger, cacheM, usersService, projectsService)
|
||||
}
|
||||
|
||||
func setupProfiler() {
|
||||
go func() {
|
||||
log.Println(http.ListenAndServe(":6060", nil))
|
||||
}()
|
||||
}
|
||||
|
||||
func addSeedData(database *db.Client, ur users.Repository, pr projects.Repository) {
|
||||
conn := database.GetConn(context.Background())
|
||||
defer conn.Release()
|
||||
|
||||
var numRows int
|
||||
err := conn.QueryRow(context.Background(), "select count(id) from sctl_user").Scan(&numRows)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if numRows == 0 {
|
||||
addTestData(conn, ur, pr)
|
||||
}
|
||||
}
|
||||
|
||||
func addTestData(conn *pgxpool.Conn, ur users.Repository, pr projects.Repository) {
|
||||
ctx := context.Background()
|
||||
for jobs := 0; jobs < 100; jobs++ {
|
||||
go func() {
|
||||
for i := 0; i < 1_000; i++ {
|
||||
var (
|
||||
user *users.CreateUser
|
||||
err error
|
||||
userId int
|
||||
)
|
||||
user, err = users.NewCreateUser(fmt.Sprintf("%s@test.com", uuid.New().String()), "password", users.NewPlainTextPasswordHasher())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
userId, err = ur.Create(ctx, user)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = pr.Create(ctx, projects.NewCreateProject(uuid.New().String()[:20], userId))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user