Skip to content

Commit

Permalink
Commented out debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean committed Aug 23, 2023
1 parent ee31909 commit 7117996
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions config/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.5'
services:
api1: &api
image: ghcr.io/jeancrodrigues/rinha-backend:latest
image: ghcr.io/jeancrodrigues/rinha-backend-23-golang:main
# hostname: api1
depends_on:
- db
Expand Down Expand Up @@ -60,7 +60,7 @@ services:
command: redis-server --save "" --loglevel warning

db: # Banco de dados
image: ghcr.io/jeancrodrigues/rinha-backend-postgres:latest
image: ghcr.io/jeancrodrigues/rinha-backend-23-golang-db:main
# volumes:
# - ./postgres.conf:/etc/postgresql/postgresql.conf
# - ./db-init-entrypoint.sh:/docker-entrypoint-initdb.d/init-user-db.sh
Expand Down
2 changes: 1 addition & 1 deletion db/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
func GetConnection() PgxIface {

if Conn != nil {
log.Println("getting existent connection")
//log.Println("getting existent connection")
return Conn
} else {
log.Println("opening connections")
Expand Down
20 changes: 10 additions & 10 deletions db/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func FindPessoas(conn PgxIface, search string) ([]string, error) {
result, err := conn.Query(context.Background(), sql, search)

if err != nil {
log.Println(err)
//log.Println(err)
return nil, err
}

Expand Down Expand Up @@ -105,13 +105,13 @@ func SavePessoaSearch(conn PgxIface, pessoa Pessoa, pessoaJson []byte) error {

search := strings.ToLower(strings.Join(pessoa.Stack, " ") + " " + pessoa.Nome + " " + pessoa.Apelido)

exec, err := conn.
_, err := conn.
Exec(context.Background(), sql, search, pessoaJson)

log.Println(fmt.Sprintf("executed insert with result %+v", exec))
//log.Println(fmt.Sprintf("executed insert with result %+v", exec))

if err != nil {
log.Println(fmt.Sprintf("error executing insert %v", err))
//log.Println(fmt.Sprintf("error executing insert %v", err))
return err
}

Expand All @@ -132,10 +132,10 @@ func SavePessoaSearchBatch(conn PgxIface, pessoaBatch []Pessoa, pessoaJson [][]b
paramSql = append(paramSql, fmt.Sprintf("($%d, $%d)", i+1, i+2))
}

exec, err := conn.
_, err := conn.
Exec(context.Background(), fmt.Sprintf(sql, strings.Join(paramSql, ",")), params...)

log.Println(fmt.Sprintf("executed insert with result %+v", exec))
//log.Println(fmt.Sprintf("executed insert with result %+v", exec))

if err != nil {
log.Println(fmt.Sprintf("error executing insert %v", err))
Expand All @@ -158,10 +158,10 @@ func SavePessoaBatch(conn PgxIface, pessoaBatch []Pessoa) error {
paramSql = append(paramSql, fmt.Sprintf("($%d, $%d, $%d, $%d, $%d::varchar[])", i+1, i+2, i+3, i+4, i+5))
}

exec, err := conn.
_, err := conn.
Exec(context.Background(), fmt.Sprintf(sql, strings.Join(paramSql, ",")), params...)

log.Println(fmt.Sprintf("executed insert with result %+v", exec))
//log.Println(fmt.Sprintf("executed insert with result %+v", exec))

if err != nil {
log.Println(fmt.Sprintf("error executing insert %v", err))
Expand All @@ -175,10 +175,10 @@ func SavePessoa(conn PgxIface, id uuid.UUID, pessoa Pessoa) error {

sql := `insert into pessoa values ( $1, $2, $3, $4, $5::varchar[]);`

exec, err := conn.
_, err := conn.
Exec(context.Background(), sql, id, pessoa.Apelido, pessoa.Nome, pessoa.Nascimento, pessoa.Stack)

log.Println(fmt.Sprintf("executed insert with result %+v", exec))
//log.Println(fmt.Sprintf("executed insert with result %+v", exec))

if err != nil {
log.Println(fmt.Sprintf("error executing insert %v", err))
Expand Down
34 changes: 17 additions & 17 deletions http/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ func GetPessoa(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

if err != nil {
http.NotFound(w, r)
log.Println(fmt.Sprintf("get Pessoa with invalid uuid %s %s", param, err))
//log.Println(fmt.Sprintf("get Pessoa with invalid uuid %s %s", param, err))
return
}

log.Println(fmt.Sprintf("get Pessoa by id %s", id))
//log.Println(fmt.Sprintf("get Pessoa by id %s", id))

result, err := redisConnection.Get(ctx, "id::"+id.String()).Result()

if err == nil {
log.Printf("found in cache %+v\n", result)
//log.Printf("found in cache %+v\n", result)
_, err := w.Write([]byte(fmt.Sprintf("%s", result)))
if err != nil {
log.Println(err)
//log.Println(err)
return
}
return
} else {
log.Println(err)
//log.Println(err)
}

pessoa, err := db.GetPessoaById(GetConnection(), id)
Expand All @@ -79,7 +79,7 @@ func GetPessoa(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
_, err = w.Write(pessoaJson)

if err != nil {
log.Println(err)
//log.Println(err)
return
}
}
Expand All @@ -99,12 +99,12 @@ func GetPessoas(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
return
}

log.Println(fmt.Sprintf("get pessoas by term %s", searchTerm))
//log.Println(fmt.Sprintf("get pessoas by term %s", searchTerm))

_, err = w.Write([]byte(fmt.Sprintf("[%s]", strings.Join(pessoas, ","))))

if err != nil {
log.Println(err)
//log.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
Expand All @@ -115,7 +115,7 @@ func CreatePessoa(batchChannelPessoa chan Job, batchChannelPessoaSearch chan Job
bytes, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
log.Printf("error reading body %s\n", err)
//log.Printf("error reading body %s\n", err)
return
}

Expand All @@ -138,7 +138,7 @@ func handleCreatePessoa(batchChannelPessoa chan Job,
parseResult := <-parsePessoaChannel
if parseResult.Error != nil {
w.WriteHeader(http.StatusBadRequest)
log.Printf("error parsing input %s\n", parseResult.Error)
//log.Printf("error parsing input %s\n", parseResult.Error)
return
}

Expand All @@ -159,12 +159,12 @@ func persistPessoa(batchChannelPessoa chan Job,
redisConnection.Set(ctx, "apelido::"+pessoa.Apelido, true, 0)

go func() {
fmt.Printf("added: %s %s\n", pessoa.Id)
//fmt.Printf("added: %s %s\n", pessoa.Id)
batchChannelPessoa <- Job{name: pessoa.Id.String(), Pessoa: pessoa}
batchChannelPessoaSearch <- Job{pessoa.Id.String(), pessoa, pessoaJson}
}()

log.Println(fmt.Sprintf("created Pessoa with id %s : body %+v", pessoa.Id, pessoa))
//log.Println(fmt.Sprintf("created Pessoa with id %s : body %+v", pessoa.Id, pessoa))
}

func GetPessoaCount(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
Expand All @@ -178,7 +178,7 @@ func GetPessoaCount(w http.ResponseWriter, r *http.Request, ps httprouter.Params
_, err = w.Write([]byte(strconv.Itoa(int(count))))

if err != nil {
log.Println(err)
//log.Println(err)
return
}
}
Expand Down Expand Up @@ -229,7 +229,7 @@ func parsePessoa(bytes []byte, result chan ParsePessoaResult) {
result <- resultParsePessoaError("field nascimento invalid")
}

log.Printf(fmt.Sprintf("parsed Pessoa %+v", pessoa))
//log.Printf(fmt.Sprintf("parsed Pessoa %+v", pessoa))

result <- resultParsePessoaSuccess(&pessoa)
}
Expand All @@ -249,7 +249,7 @@ func resultParsePessoaSuccess(pessoa *db.Pessoa) ParsePessoaResult {
}

func SavePessoaSearchBatch(batch []Job) {
log.Println(fmt.Printf("batch started %s\n", batch[0].name))
//log.Println(fmt.Printf("batch started %s\n", batch[0].name))

var pessoaBatch []db.Pessoa
var pessoaJson [][]byte
Expand All @@ -265,7 +265,7 @@ func SavePessoaSearchBatch(batch []Job) {
}

func SavePessoaBatch(batch []Job) {
log.Println(fmt.Printf("batch started %s\n", batch[0].name))
//log.Println(fmt.Printf("batch started %s\n", batch[0].name))

var pessoaBatch []db.Pessoa

Expand All @@ -275,5 +275,5 @@ func SavePessoaBatch(batch []Job) {

db.SavePessoaBatch(GetConnection(), pessoaBatch)

log.Println(fmt.Printf("batch completed %s count %d!\n", batch[0].name, len(batch)))
//log.Println(fmt.Printf("batch completed %s count %d!\n", batch[0].name, len(batch)))
}

0 comments on commit 7117996

Please sign in to comment.