-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rank design and implement, in progress. #99
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #99 +/- ##
==========================================
+ Coverage 27.97% 31.47% +3.50%
==========================================
Files 35 42 +7
Lines 1076 1223 +147
==========================================
+ Hits 301 385 +84
- Misses 729 780 +51
- Partials 46 58 +12 ☔ View full report in Codecov by Sentry. |
cmd/clean/main.go
Outdated
@@ -53,6 +63,8 @@ func clearDB() { | |||
&problem_model.ProblemTag{}, | |||
&judge_model.Judge{}, | |||
&judge_model.JudgeResult{}, | |||
&judge_model.ScoreCache{}, | |||
"problem_tags", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated with &problem_model.ProblemTag{}
models/judge/judge_score_cache.go
Outdated
ProblemSlug string `json:"problemSlug" gorm:"primaryKey"` | ||
Problem problem_model.Problem `json:"problem"` | ||
SubmissionCount int64 `json:"submissionCount" gorm:"default:1"` // judge create time < solvetime will be count | ||
IsCorrect bool `json:"isCorrect" gorm:"default:false"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfer IsAccepted
here
services/judge/judge_score_cache.go
Outdated
gorm_agent "github.com/oj-lab/oj-lab-platform/modules/agent/gorm" | ||
) | ||
|
||
func UpdateScoreCache(ctx context.Context, uid uuid.UUID, verdict judge_model.JudgeVerdict) (*judge_model.ScoreCache, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfer UpsertScoreCache
here
services/judge/judge_score_cache.go
Outdated
scoreCache.IsCorrect = true | ||
scoreCache.SolveTime = judge.CreateAt | ||
} | ||
newScoreCache, err := judge_model.CreateJudgeScoreCache(db, scoreCache) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CreateJudgeScoreCache
may failed here because of concurrency conflict.
If failed, get data again and continue the update logic.
models/judge/judge_score_cache.go
Outdated
) | ||
|
||
// user contest problem summary score info | ||
type ScoreCache struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfer JudgeScoreCache
here, naming should not differed in service
or db
modules.
I update the rankcache in the time scoreCache update. I found the logic may be too complicated in a single function. This impl maybe fast, which update only when needed. |
More test and final rank query api and service in progress. |
@@ -13,7 +14,10 @@ import ( | |||
|
|||
func CreateUser(ctx context.Context, user user_model.User) (*user_model.User, error) { | |||
db := gorm_agent.GetDefaultDB() | |||
|
|||
_, err := judge_model.CreateJudgeRankCache(db, judge_model.NewJudgeRankCache(user.Account)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If RankCache is necessary for every user, using relationship in GORM will be better, so that we won't need to create RankCache explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also welcome the design of lazy creation for RankCache, this depends on whether we think RankCache is needed for user who don't submit any judges.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it's lazy creation I think.
- simplify upsert logic - judge_rank api service model db - some test
Some design explain
I just test one user, one problem, one judger case. The scoreCache result is right as I think.
scoreCache is almost finished.
rankCache will be implemented in the nearest future.
Some advice will be appreciated.