Skip to content

Commit

Permalink
Upgrade to pgx v5.4.3
Browse files Browse the repository at this point in the history
Bug fixes.
Improve performance of notification persist.
  • Loading branch information
sesposito committed Aug 9, 2023
1 parent 63f57d6 commit dd908aa
Show file tree
Hide file tree
Showing 19 changed files with 748 additions and 201 deletions.
542 changes: 542 additions & 0 deletions data/modules/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/heroiclabs/sql-migrate v0.0.0-20230615133120-fb3ad977aaaf
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59
github.com/jackc/pgx/v5 v5.4.2
github.com/jackc/pgx/v5 v5.4.3
github.com/prometheus/client_golang v1.16.0
github.com/stretchr/testify v1.8.4
github.com/twmb/murmur3 v1.1.8
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08
github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM=
github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186 h1:ZQM8qLT/E/CGD6XX0E6q9FAwxJYmWpJufzmLMaFuzgQ=
github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc=
github.com/jackc/pgx/v5 v5.4.2 h1:u1gmGDwbdRUZiwisBm/Ky2M14uQyUP65bG8+20nnyrg=
github.com/jackc/pgx/v5 v5.4.2/go.mod h1:q6iHT8uDNXWiFNOlRqJzBTaSH3+2xCXkokxHZC5qWFY=
github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY=
github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func main() {
}); err != nil {
logger.Fatal("Failed to acquire pgx conn for migration check", zap.Error(err))
}
conn.Close()

// Access to social provider integrations.
socialClient := social.NewClient(logger, 5*time.Second, config.GetGoogleAuth().OAuthConfig)
Expand Down
3 changes: 1 addition & 2 deletions server/console_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/heroiclabs/nakama-common/api"
"github.com/heroiclabs/nakama-common/runtime"
"github.com/heroiclabs/nakama/v3/console"
"github.com/jackc/pgx/v5/pgtype"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -55,7 +54,7 @@ func (s *ConsoleServer) DeleteChannelMessages(ctx context.Context, in *console.D

var res sql.Result
var err error
if res, err = s.db.ExecContext(ctx, query, &pgtype.Timestamptz{Time: deleteBefore, Valid: true}); err != nil {
if res, err = s.db.ExecContext(ctx, query, deleteBefore); err != nil {
s.logger.Error("Could not delete messages.", zap.Error(err))
return nil, status.Error(codes.Internal, "An error occurred while trying to delete messages.")
}
Expand Down
22 changes: 13 additions & 9 deletions server/core_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ type accountUpdate struct {
}

func GetAccount(ctx context.Context, logger *zap.Logger, db *sql.DB, statusRegistry *StatusRegistry, userID uuid.UUID) (*api.Account, error) {
var displayName sql.NullString
var username sql.NullString
var displayName sql.NullString
var avatarURL sql.NullString
var langTag sql.NullString
var location sql.NullString
Expand All @@ -73,7 +73,9 @@ func GetAccount(ctx context.Context, logger *zap.Logger, db *sql.DB, statusRegis
var updateTime pgtype.Timestamptz
var verifyTime pgtype.Timestamptz
var disableTime pgtype.Timestamptz
var deviceIDs pgtype.Array[string]
var deviceIDs pgtype.FlatArray[string]

m := pgtype.NewMap()

query := `
SELECT u.username, u.display_name, u.avatar_url, u.lang_tag, u.location, u.timezone, u.metadata, u.wallet,
Expand All @@ -82,16 +84,16 @@ SELECT u.username, u.display_name, u.avatar_url, u.lang_tag, u.location, u.timez
FROM users u
WHERE u.id = $1`

if err := db.QueryRowContext(ctx, query, userID).Scan(&username, &displayName, &avatarURL, &langTag, &location, &timezone, &metadata, &wallet, &email, &apple, &facebook, &facebookInstantGame, &google, &gamecenter, &steam, &customID, &edgeCount, &createTime, &updateTime, &verifyTime, &disableTime, &deviceIDs); err != nil {
if err := db.QueryRowContext(ctx, query, userID).Scan(&username, &displayName, &avatarURL, &langTag, &location, &timezone, &metadata, &wallet, &email, &apple, &facebook, &facebookInstantGame, &google, &gamecenter, &steam, &customID, &edgeCount, &createTime, &updateTime, &verifyTime, &disableTime, m.SQLScanner(&deviceIDs)); err != nil {
if err == sql.ErrNoRows {
return nil, ErrAccountNotFound
}
logger.Error("Error retrieving user account.", zap.Error(err))
return nil, err
}

devices := make([]*api.AccountDevice, 0, len(deviceIDs.Elements))
for _, deviceID := range deviceIDs.Elements {
devices := make([]*api.AccountDevice, 0, len(deviceIDs))
for _, deviceID := range deviceIDs {
devices = append(devices, &api.AccountDevice{Id: deviceID})
}

Expand Down Expand Up @@ -183,17 +185,19 @@ WHERE u.id IN (` + strings.Join(statements, ",") + `)`
var updateTime pgtype.Timestamptz
var verifyTime pgtype.Timestamptz
var disableTime pgtype.Timestamptz
var deviceIDs pgtype.Array[string]
var deviceIDs pgtype.FlatArray[string]

m := pgtype.NewMap()

err = rows.Scan(&userID, &username, &displayName, &avatarURL, &langTag, &location, &timezone, &metadata, &wallet, &email, &apple, &facebook, &facebookInstantGame, &google, &gamecenter, &steam, &customID, &edgeCount, &createTime, &updateTime, &verifyTime, &disableTime, &deviceIDs)
err = rows.Scan(&userID, &username, &displayName, &avatarURL, &langTag, &location, &timezone, &metadata, &wallet, &email, &apple, &facebook, &facebookInstantGame, &google, &gamecenter, &steam, &customID, &edgeCount, &createTime, &updateTime, &verifyTime, &disableTime, m.SQLScanner(&deviceIDs))
if err != nil {
_ = rows.Close()
logger.Error("Error retrieving user accounts.", zap.Error(err))
return nil, err
}

devices := make([]*api.AccountDevice, 0, len(deviceIDs.Elements))
for _, deviceID := range deviceIDs.Elements {
devices := make([]*api.AccountDevice, 0, len(deviceIDs))
for _, deviceID := range deviceIDs {
devices = append(devices, &api.AccountDevice{Id: deviceID})
}

Expand Down
12 changes: 12 additions & 0 deletions vendor/github.com/jackc/pgx/v5/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/github.com/jackc/pgx/v5/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/github.com/jackc/pgx/v5/conn.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vendor/github.com/jackc/pgx/v5/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/jackc/pgx/v5/pgconn/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions vendor/github.com/jackc/pgx/v5/pgconn/pgconn.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dd908aa

Please sign in to comment.