Commit 55cd9d15 authored by Maxim Ivanov's avatar Maxim Ivanov
Browse files

stash

parent c6d2aa56
Loading
Loading
Loading
Loading
+0 −55
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import (
	"net"
	"net/http"
	"net/http/pprof"
	"sort"
	"strings"
	"time"

@@ -229,60 +228,6 @@ func StartConsoleServer(logger *zap.Logger, startupLogger *zap.Logger, db *sql.D
			startupLogger.Fatal("Console server gateway listener failed", zap.Error(err))
		}
	}()

	// Run a background process to periodically refresh storage collection names.
	go func() {
		// Refresh function to update cache and return a delay until the next refresh should run.
		refreshFn := func() *time.Timer {
			startAt := time.Now()

			// Load all distinct collections from database.
			collections := make([]string, 0, 10)
			query := "SELECT DISTINCT collection FROM storage"
			rows, err := s.db.QueryContext(ctx, query)
			if err != nil {
				s.logger.Error("Error querying storage collections.", zap.Error(err))
				return time.NewTimer(time.Minute)
			}
			for rows.Next() {
				var dbCollection string
				if err := rows.Scan(&dbCollection); err != nil {
					_ = rows.Close()
					s.logger.Error("Error scanning storage collections.", zap.Error(err))
					return time.NewTimer(time.Minute)
				}
				collections = append(collections, dbCollection)
			}
			_ = rows.Close()

			sort.Strings(collections)
			collectionSetCache.Store(collections)

			elapsed := time.Now().Sub(startAt)
			elapsed *= 20
			if elapsed < time.Minute {
				elapsed = time.Minute
			}
			return time.NewTimer(elapsed)
		}

		// Run one refresh as soon as the server starts.
		timer := refreshFn()

		// Then refresh on the chosen timer.
		for {
			select {
			case <-ctx.Done():
				if timer != nil {
					timer.Stop()
				}
				return
			case <-timer.C:
				timer = refreshFn()
			}
		}
	}()

	return s
}

+1 −3
Original line number Diff line number Diff line
@@ -21,9 +21,6 @@ import (
	"encoding/base64"
	"encoding/gob"
	"encoding/json"
	"strconv"
	"sync/atomic"

	"github.com/gofrs/uuid"
	"github.com/heroiclabs/nakama-common/api"
	"github.com/heroiclabs/nakama/v3/console"
@@ -33,6 +30,7 @@ import (
	"google.golang.org/grpc/status"
	"google.golang.org/protobuf/types/known/emptypb"
	"google.golang.org/protobuf/types/known/timestamppb"
	"strconv"
)

type consoleStorageCursor struct {
+13 −0
Original line number Diff line number Diff line
package server

import "testing"

func createTestConsoleServer(t *testing.T) {
	consoleLogger := loggerForTest(t)
	config := NewConfig(consoleLogger)
	c := newConsoleS
	if err != nil {
		t.Fatalf("error creating test matchmaker: %v", err)
	}
	defer cleanup()
}