Skip to content

Commit

Permalink
Fix demo queries
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmacdonald committed Nov 12, 2023
1 parent 749f9c6 commit b06ebdb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FROM alpine:latest

LABEL maintainer="Leigh MacDonald <[email protected]>"
LABEL org.opencontainers.image.source="https://github.com/leighmacdonald/gbans"
LABEL org.opencontainers.image.version="v0.5.0"
LABEL org.opencontainers.image.version="v0.5.1"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.description="Centralized community backend for Team Fortress 2"

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: all test clean build install frontend sourcemod
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
TAGGED_IMAGE = ghcr.io/leighmacdonald/gbans:$(BRANCH)
VERSION=v0.5.0
VERSION=v0.5.1
GO_CMD=go
GO_BUILD=$(GO_CMD) build
GO_FLAGS = -trimpath -ldflags="-s -w -X github.com/leighmacdonald/gbans/internal/app.BuildVersion=$(VERSION)"
Expand Down
2 changes: 1 addition & 1 deletion docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sudo docker run -d --restart unless-stopped \
--dns=1.1.1.1 \
-v /home/ubuntu/gbans/gbans.yml:/app/gbans.yml:ro \
--name gbans \
ghcr.io/leighmacdonald/gbans:v0.5.0
ghcr.io/leighmacdonald/gbans:v0.5.1
```

Substitute `master` for a specific tag if desired, and `/home/ubuntu/gbans/gbans.yml` with the location of your config.
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gbans",
"version": "0.5.0",
"version": "0.5.1",
"description": "gbans",
"main": "src/index.tsx",
"repository": "github.com/leighmacdonald/gbans",
Expand Down
23 changes: 22 additions & 1 deletion internal/store/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package store

import (
"context"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -128,6 +129,18 @@ func (db *Store) GetDemos(ctx context.Context, opts DemoFilter) ([]DemoFile, int
constraints = append(constraints, sq.Expr("stats ?? ?", sid64.String()))
}

orderBy := "demo_id"
if opts.OrderBy != "" {
orderBy = opts.OrderBy
}

order := "ASC"
if opts.Desc {
order = "DESC"
}

builder = builder.OrderBy(fmt.Sprintf("d.%s %s", orderBy, order))

if len(opts.ServerIds) > 0 && opts.ServerIds[0] != 0 {
anyServer := false

Expand All @@ -144,7 +157,15 @@ func (db *Store) GetDemos(ctx context.Context, opts DemoFilter) ([]DemoFile, int
}
}

query, args, errQueryArgs := builder.Where(constraints).ToSql()
var limit uint64

if opts.Limit <= 0 || opts.Limit > 100 {
limit = 50
} else {
limit = opts.Limit
}

query, args, errQueryArgs := builder.Limit(limit).Offset(opts.Offset).Where(constraints).ToSql()
if errQueryArgs != nil {
return nil, 0, Err(errQueryArgs)
}
Expand Down

0 comments on commit b06ebdb

Please sign in to comment.