-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa5c52d
commit 72b94b4
Showing
56 changed files
with
1,184 additions
and
1,173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package cache | ||
|
||
import ( | ||
"blizzard/blizzard/config" | ||
"blizzard/blizzard/logger" | ||
"context" | ||
"fmt" | ||
"github.com/allegro/bigcache/v3" | ||
"github.com/eko/gocache/lib/v4/cache" | ||
"github.com/eko/gocache/lib/v4/marshaler" | ||
cachestore "github.com/eko/gocache/lib/v4/store" | ||
bcstore "github.com/eko/gocache/store/bigcache/v4" | ||
"strings" | ||
"time" | ||
) | ||
|
||
type Store struct { | ||
ctx context.Context | ||
*marshaler.Marshaler | ||
} | ||
|
||
var store *Store | ||
|
||
func Init() { | ||
ctx := context.Background() | ||
bc, _ := bigcache.NewBigCache(bigcache.DefaultConfig(5 * time.Minute)) | ||
bcStore := bcstore.NewBigcache(bc) | ||
cacheManager := cache.New[interface{}](bcStore) | ||
store = &Store{Marshaler: marshaler.New(cacheManager), ctx: ctx} | ||
} | ||
|
||
func Get[T any](category, key string, loader func() (T, error)) *T { | ||
if config.Config.Debug { | ||
v, e := loader() | ||
if e != nil { | ||
return nil | ||
} | ||
return &v | ||
} | ||
if strings.TrimSpace(key) == "" { | ||
return nil | ||
} | ||
val, e := store.Get(store.ctx, key, new(T)) | ||
if e != nil { | ||
v, e := loader() | ||
if e != nil { | ||
return nil | ||
} | ||
e = store.Set(store.ctx, key, v, cachestore.WithExpiration(time.Hour*24)) | ||
return &v | ||
} | ||
if v, ok := val.(*T); ok { | ||
logger.Logger.Debug().Str("key", category+"_"+key).Interface("data", v).Msg("cache hit") | ||
return v | ||
} else { | ||
fmt.Println("fail") | ||
} | ||
return nil | ||
} | ||
|
||
func Invalidate(category, key string) bool { | ||
return store.Delete(store.ctx, category+"_"+key) == nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,44 @@ | ||
package contest | ||
|
||
import "blizzard/blizzard/db/models/user" | ||
|
||
type Problem struct { | ||
ID string `bun:",pk" json:"id"` | ||
Tags []string `bun:",array,notnull" json:"tags"` | ||
AuthorID string | ||
Author user.User `bun:"rel:has-one,join:author_id=id"` | ||
Content string `json:"content"` | ||
} | ||
import ( | ||
"blizzard/blizzard/db/models/user" | ||
"github.com/google/uuid" | ||
) | ||
|
||
type ( | ||
Problem struct { | ||
ID string `bun:",pk" json:"id"` | ||
Tags []string `bun:",array,notnull" json:"tags"` | ||
Source string `json:"source"` | ||
AuthorID uuid.UUID `bun:",type:uuid" json:"authorID,omitempty"` | ||
Author *user.User `bun:"rel:has-one,join:author_id=id" json:"-"` | ||
*ProblemContent `bun:"embed:"` | ||
Constraints *Constraints `bun:"embed:" json:"constraints,omitempty"` | ||
TestCount uint16 `bun:",notnull" json:"testCount,omitempty"` | ||
PointPerTest uint16 `bun:",default:1" json:"pointPerTest,omitempty"` | ||
} | ||
|
||
ProblemContent struct { | ||
Title string `bun:",notnull" json:"title,omitempty"` | ||
Statement string `bun:",notnull" json:"statement,omitempty"` | ||
Input string `bun:",notnull" json:"input,omitempty"` | ||
Output string `bun:",notnull" json:"output,omitempty"` | ||
Scoring []string `bun:",array" json:"scoring,omitempty"` | ||
SampleTestCases []*SampleTestCases `json:"sampleTestCases,omitempty"` | ||
} | ||
|
||
SampleTestCases struct { | ||
Input string `json:"input"` | ||
Output string `json:"output"` | ||
Note string `json:"note"` | ||
} | ||
|
||
Constraints struct { | ||
IsInteractive bool `bun:",default:false" json:"isInteractive"` | ||
TimeLimit float32 `bun:",default:1" json:"timeLimit"` | ||
MemoryLimit uint32 `bun:",default:128" json:"memoryLimit"` | ||
OutputLimit uint32 `bun:",default:64" json:"outputLimit"` | ||
AllowPartial bool `bun:",default:false" json:"allowPartial"` | ||
ShortCircuit bool `bun:",default:false" json:"shortCircuit"` | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,37 @@ | ||
package contest | ||
|
||
import "blizzard/blizzard/db/models/user" | ||
|
||
type Submission struct { | ||
// save the source code in a folder and load it by id | ||
ID uint64 `bun:",pk,autoincrement" json:"id"` | ||
AuthorID string | ||
Author *user.User | ||
} | ||
import ( | ||
"blizzard/blizzard/db/models/user" | ||
"github.com/google/uuid" | ||
"time" | ||
) | ||
|
||
type ( | ||
Submission struct { | ||
// save the source code in a folder and load it by id | ||
ID uint32 `bun:",pk,autoincrement" json:"id"` | ||
AuthorID uuid.UUID `bun:",type:uuid"` | ||
ProblemID string | ||
Language string | ||
SubmittedAt *time.Time `bun:",nullzero,type:timestamptz,notnull,default:'now()'::timestamptz"` | ||
Verdict Verdict `bun:",nullzero" json:"verdict"` | ||
Author *user.User | ||
} | ||
|
||
Verdict = uint8 | ||
) | ||
|
||
const ( | ||
Queued Verdict = iota | ||
Accepted | ||
InternalError | ||
Rejected | ||
Cancelled | ||
RuntimeError | ||
TimeLimitExceeded | ||
MemoryLimitExceeded | ||
OutputLimitExceeded | ||
StackLimitExceeded | ||
InvalidReturn | ||
CompilerError | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package post | ||
|
||
import ( | ||
"blizzard/blizzard/db/models/user" | ||
"github.com/google/uuid" | ||
"time" | ||
) | ||
|
||
type Comment struct { | ||
ID uint32 `bun:",pk,autoincrement" json:"id"` | ||
CommentedAt *time.Time `bun:",nullzero,type:timestamptz,notnull,default:'now()'::timestamptz" json:"commentedAt,omitempty"` | ||
AuthorID uuid.UUID `bun:",type:uuid" json:"-"` | ||
Author *user.User `bun:"rel:has-one,join:author_id=id" json:"author,omitempty"` | ||
PostID uint32 | ||
Post *Post `bun:"rel:belongs-to,join:post_id=id"` | ||
Content string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package post | ||
|
||
import ( | ||
"blizzard/blizzard/db/models/user" | ||
"github.com/google/uuid" | ||
"time" | ||
) | ||
|
||
type Post struct { | ||
ID uint32 `bun:",pk,autoincrement" json:"id"` | ||
Title string `bun:",notnull" json:"title"` | ||
PostedAt *time.Time `bun:",nullzero,type:timestamptz,notnull,default:'now()'::timestamptz" json:"postedAt,omitempty"` | ||
AuthorID uuid.UUID `bun:",type:uuid" json:"authorID,omitempty"` | ||
Author *user.User `bun:"rel:has-one,join:author_id=id" json:"-"` | ||
Comments []*Comment `bun:"rel:has-many,join:id=author_id" json:"comments,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.