Skip to content

Commit

Permalink
♻️ rename package
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaNecron committed Oct 10, 2023
1 parent 89e4f3b commit 82f6521
Show file tree
Hide file tree
Showing 71 changed files with 288 additions and 275 deletions.
6 changes: 3 additions & 3 deletions blizzard.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package blizzard

import (
"blizzard/cron"
"blizzard/judge"
"context"
"github.com/ArcticOJ/blizzard/v0/cron"
"github.com/ArcticOJ/blizzard/v0/judge"
)

func Init(ctx context.Context) {
judge.ResponseWorker = judge.NewObserver(ctx)
judge.ResponseWorker = judge.NewWorker(ctx)
cron.Start(ctx)
go judge.ResponseWorker.Work()
}
Expand Down
2 changes: 1 addition & 1 deletion cache/dbg_hook.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cache

import (
"blizzard/logger"
"context"
"github.com/ArcticOJ/blizzard/v0/logger"
"github.com/redis/go-redis/v9"
"net"
)
Expand Down
5 changes: 3 additions & 2 deletions cache/store.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package cache

import (
"blizzard/config"
"blizzard/logger"
"context"
"fmt"
"github.com/ArcticOJ/blizzard/v0/config"
"github.com/ArcticOJ/blizzard/v0/logger"
"github.com/redis/go-redis/v9"
"net"
"time"
Expand All @@ -20,6 +20,7 @@ const (
Bucket
Submission
Judge
Problem
)

func CreateClient(db DB, name string) (c redis.UniversalClient) {
Expand Down
6 changes: 3 additions & 3 deletions cache/stores/buckets.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package stores

import (
"blizzard/cache"
"blizzard/config"
"blizzard/logger"
"context"
"fmt"
"github.com/ArcticOJ/blizzard/v0/cache"
"github.com/ArcticOJ/blizzard/v0/config"
"github.com/ArcticOJ/blizzard/v0/logger"
"github.com/redis/go-redis/v9"
"math"
)
Expand Down
2 changes: 1 addition & 1 deletion cache/stores/judge.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package stores

import (
"blizzard/cache"
"context"
"github.com/ArcticOJ/blizzard/v0/cache"
"github.com/redis/go-redis/v9"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion cache/stores/pending.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package stores

import (
"blizzard/cache"
"context"
"fmt"
"github.com/ArcticOJ/blizzard/v0/cache"
"github.com/redis/go-redis/v9"
"sync"
"time"
Expand Down
24 changes: 24 additions & 0 deletions cache/stores/problems.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package stores

import (
"github.com/ArcticOJ/blizzard/v0/cache"
"github.com/ArcticOJ/blizzard/v0/rejson"
)

var Problems *ProblemStore

type ProblemStore struct {
j *rejson.ReJSON
}

const (
defaultProblemKey = "blizzard::problem[%s]"
)

func init() {
Problems = &ProblemStore{j: &rejson.ReJSON{Client: cache.CreateClient(cache.Problem, "problems")}}
}

func (*ProblemStore) Get() {

}
62 changes: 30 additions & 32 deletions cache/stores/users.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package stores

import (
"blizzard/cache"
"blizzard/db"
"blizzard/db/models/user"
"blizzard/logger"
"blizzard/rejson"
"context"
"crypto/md5"
"fmt"
"github.com/ArcticOJ/blizzard/v0/cache"
"github.com/ArcticOJ/blizzard/v0/db"
"github.com/ArcticOJ/blizzard/v0/db/models/user"
"github.com/ArcticOJ/blizzard/v0/rejson"
"github.com/google/uuid"
"github.com/redis/go-redis/v9"
"github.com/tmthrgd/go-hex"
Expand All @@ -24,30 +23,29 @@ type UserStore struct {
}

const (
defaultUserListKey = "blizzard::user_list"
defaultUserKey = "blizzard::user[%s]"
defaultHandleToIdResolver = "blizzard::user_id[%s]"
)

func init() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
defer cancel()
//ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
//defer cancel()
Users = &UserStore{j: &rejson.ReJSON{Client: cache.CreateClient(cache.User, "users")}}
var ids []string
logger.Panic(db.Database.NewSelect().Model((*user.User)(nil)).Column("id").Scan(ctx, &ids), "failed to to query for users")
var m []redis.Z
for _, id := range ids {
m = append(m, redis.Z{
Score: 0,
Member: id,
})
}
_, e := Users.j.TxPipelined(ctx, func(p redis.Pipeliner) error {
p.Del(ctx, defaultUserListKey)
p.ZAdd(ctx, defaultUserListKey, m...)
return nil
})
logger.Panic(e, "failed to populate user cache")
//var ids []string
//logger.Panic(db.Database.NewSelect().Model((*user.User)(nil)).Column("id").Scan(ctx, &ids), "failed to to query for users")
//var m []redis.Z
//for _, id := range ids {
// m = append(m, redis.Z{
// Score: 0,
// Member: id,
// })
//}
//_, e := Users.j.TxPipelined(ctx, func(p redis.Pipeliner) error {
// p.Del(ctx, defaultUserListKey)
// p.ZAdd(ctx, defaultUserListKey, m...)
// return nil
//})
//logger.Panic(e, "failed to populate user cache")
}

func (s *UserStore) load(id uuid.UUID, handle string) (u *user.User) {
Expand All @@ -74,9 +72,9 @@ func (s *UserStore) load(id uuid.UUID, handle string) (u *user.User) {
return
}

func (s *UserStore) Exists(ctx context.Context, id uuid.UUID) bool {
return s.j.ZScore(ctx, defaultUserListKey, id.String()).Err() == nil
}
//func (s *UserStore) Exists(ctx context.Context, id uuid.UUID) bool {
// return s.j.ZScore(ctx, defaultUserListKey, id.String()).Err() == nil
//}

func (s *UserStore) fallback(ctx context.Context, id uuid.UUID, handle string) *user.User {
u := s.load(id, handle)
Expand Down Expand Up @@ -111,9 +109,9 @@ func (s *UserStore) Get(ctx context.Context, id uuid.UUID, handle string) *user.
}
return s.fallback(ctx, uuid.Nil, handle)
}
if !s.Exists(ctx, id) {
return nil
}
//if !s.Exists(ctx, id) {
// return nil
//}
r := s.j.JSONGet(ctx, fmt.Sprintf(defaultUserKey, id), "$")
if _u := rejson.Unmarshal[user.User](r); _u == nil {
return s.fallback(ctx, id, "")
Expand Down Expand Up @@ -146,9 +144,9 @@ func (s *UserStore) GetMinimal(ctx context.Context, id uuid.UUID) *user.MinimalU
if id == uuid.Nil {
return nil
}
if !s.Exists(ctx, id) {
return nil
}
//if !s.Exists(ctx, id) {
// return nil
//}
r := s.j.JSONGet(ctx, fmt.Sprintf(defaultUserKey, id), "$['id','displayName','handle','organization','avatar','roles','rating']")
res := rejson.Unmarshal[interface{}](r)
if res == nil || len(res) != 7 {
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package config

import (
"blizzard/logger"
"github.com/ArcticOJ/blizzard/v0/logger"
"github.com/rs/zerolog"
"gopkg.in/yaml.v3"
"os"
Expand Down
2 changes: 1 addition & 1 deletion cron/cron.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cron

import (
"blizzard/cron/jobs"
"context"
"github.com/ArcticOJ/blizzard/v0/cron/jobs"
"github.com/go-co-op/gocron"
"sync"
"time"
Expand Down
8 changes: 4 additions & 4 deletions cron/jobs/purge_submissions.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package jobs

import (
"blizzard/cache/stores"
"blizzard/db"
"blizzard/db/models/contest"
"blizzard/logger"
"context"
"github.com/ArcticOJ/blizzard/v0/cache/stores"
"github.com/ArcticOJ/blizzard/v0/db"
"github.com/ArcticOJ/blizzard/v0/db/models/contest"
"github.com/ArcticOJ/blizzard/v0/logger"
)

func PurgeSubmissions(ctx context.Context) {
Expand Down
4 changes: 2 additions & 2 deletions cron/jobs/update_judge_status.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package jobs

import (
"blizzard/cache/stores"
"blizzard/config"
"context"
"encoding/json"
"fmt"
"github.com/ArcticOJ/blizzard/v0/cache/stores"
"github.com/ArcticOJ/blizzard/v0/config"
"net/http"
"net/url"
"time"
Expand Down
4 changes: 2 additions & 2 deletions db/db.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package db

import (
"blizzard/config"
"blizzard/db/seed"
"database/sql"
"fmt"
"github.com/ArcticOJ/blizzard/v0/config"
"github.com/ArcticOJ/blizzard/v0/db/seed"
"github.com/uptrace/bun"
"github.com/uptrace/bun/dialect/pgdialect"
"github.com/uptrace/bun/driver/pgdriver"
Expand Down
2 changes: 1 addition & 1 deletion db/debug_hook.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package db

import (
"blizzard/logger"
"context"
"errors"
"github.com/ArcticOJ/blizzard/v0/logger"
"github.com/uptrace/bun"
"reflect"
"time"
Expand Down
2 changes: 1 addition & 1 deletion db/models/contest/contest.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package contest

import (
"blizzard/db/models/user"
"github.com/ArcticOJ/blizzard/v0/db/models/user"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion db/models/contest/problem.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package contest

import (
"blizzard/db/models/user"
"github.com/ArcticOJ/blizzard/v0/db/models/user"
"github.com/google/uuid"
)

Expand Down
2 changes: 1 addition & 1 deletion db/models/contest/submission.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package contest

import (
"blizzard/db/models/user"
"github.com/ArcticOJ/blizzard/v0/db/models/user"
"github.com/google/uuid"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion db/models/post/comment.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package post

import (
"blizzard/db/models/user"
"github.com/ArcticOJ/blizzard/v0/db/models/user"
"github.com/google/uuid"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion db/models/post/post.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package post

import (
"blizzard/db/models/user"
"github.com/ArcticOJ/blizzard/v0/db/models/user"
"github.com/google/uuid"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion db/models/user/oauth.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package user

import (
"blizzard/db/utils"
"context"
"github.com/ArcticOJ/blizzard/v0/db/utils"
"github.com/google/uuid"
"github.com/uptrace/bun"
)
Expand Down
2 changes: 1 addition & 1 deletion db/models/user/role.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package user

import (
"blizzard/permission"
"github.com/ArcticOJ/blizzard/v0/permission"
)

type Role struct {
Expand Down
8 changes: 4 additions & 4 deletions db/seed/seed.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package seed

import (
"blizzard/db/models/contest"
"blizzard/db/models/post"
"blizzard/db/models/user"
"context"
"github.com/ArcticOJ/blizzard/v0/db/models/contest"
"github.com/ArcticOJ/blizzard/v0/db/models/post"
"github.com/ArcticOJ/blizzard/v0/db/models/user"
"github.com/uptrace/bun"
)

Expand Down Expand Up @@ -35,7 +35,7 @@ func RegisterModels(db *bun.DB) {
func DropAll(db *bun.DB, ctx context.Context) error {
m := append(models, intermediaryModels...)
for i := range m {
if _, e := db.NewDropTable().Model(m[i]).IfExists().Exec(ctx); e != nil {
if _, e := db.NewDropTable().Model(m[i]).Cascade().IfExists().Exec(ctx); e != nil {
return e
}
}
Expand Down
Loading

0 comments on commit 82f6521

Please sign in to comment.