chore: simplify, modernize (Go 1.26), update deps#220
Conversation
- memorykv: guard nil-variadic with len==0 in Has/MGet/Set/TTL/Delete - memorykv: range-over-value in all key/item loops - memorykv: fix MExpire ttm<=0 panic (NewTicker(0)/Reset(0)); mirror Set guard - memorykv: remove redundant blocking stopCh send in Delete (LoadAndDelete handles it) - memoryjobs: use sync.NewCond constructor in FromConfig and FromPipeline - memoryjobs: reuse captured start time in log calls instead of re-evaluating time.Now() - memoryjobs: fix encoding/json import grouping in item.go
|
Warning Review limit reached
More reviews will be available in 29 minutes and 23 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR modernizes and simplifies the in-memory KV and jobs drivers, while addressing a TTL edge case that can panic when an already-expired TTL is supplied.
Changes:
- Update KV driver variadic argument guards (
len(...) == 0) and simplify loops (for _, v := range ...). - Add an expired/invalid TTL guard in
MExpireto avoidtime.NewTicker(0)/Reset(0)panics. - Simplify jobs driver initialization/logging (
sync.NewCond(...), reuse captured start timestamps) and reorder stdlib imports.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
memorykv/driver.go |
Refactors variadic guards/loops, adjusts TTL handling (including MExpire) and simplifies delete logic. |
memoryjobs/driver.go |
Uses sync.NewCond constructor and reuses captured start times in lifecycle logs. |
memoryjobs/item.go |
Moves encoding/json into the stdlib import group. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… MExpire When MExpire received an expired TTL (ttm <= 0) it called heap.Set directly, leaving any existing callback goroutine alive. That goroutine could later fire removeEntry and silently delete the newly saved item. Call heap.Delete first to signal the old callback's stopCh before writing the new non-TTL entry.
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Applied fixes
R — Bug fixes (2)
memorykv/driver.go—MExpire: addttm <= 0guard mirroringSet; preventstime.NewTicker(0)andta.Reset(0)panics when a past/expired TTL is suppliedM — Modern Go (4)
memorykv/driver.go— replace== nilvariadic guards withlen(keys/items) == 0inHas,MGet,Set,TTL,Deletememorykv/driver.go— range-over-value (for _, k := range keys/for _, it := range items) in all loopsmemoryjobs/driver.go—goroutines.Add(^uint64(0))already modern; no change neededmemoryjobs/item.go— moveencoding/jsoninto the stdlib import groupS — Simplify (3)
memoryjobs/driver.go— usesync.NewCond(&sync.Mutex{})constructor inFromConfigandFromPipelinememoryjobs/driver.go— reuse capturedstart/tvariable in log calls instead of re-callingtime.Now().UTC()memorykv/driver.go— remove redundant blockingstopChsend inDelete;LoadAndDeletealready signals the callback via a non-blocking select