Skip to content

Commit 6ab0495

Browse files
committed
refactor: delete the unused functions
1 parent 0123eaa commit 6ab0495

File tree

4 files changed

+2
-123
lines changed

4 files changed

+2
-123
lines changed

core/llm_token_ratelimit/init.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,6 @@ import (
1818
"fmt"
1919
)
2020

21-
func initRules() error {
22-
cfg := globalConfig.GetConfig()
23-
if cfg == nil {
24-
return fmt.Errorf("config is nil")
25-
}
26-
27-
if len(cfg.Rules) == 0 {
28-
return nil
29-
}
30-
31-
if _, err := LoadRules(cfg.Rules); err != nil {
32-
return err
33-
}
34-
35-
return nil
36-
}
37-
3821
func Init(cfg *Config) error {
3922
if globalConfig == nil {
4023
return fmt.Errorf("global config is nil")
@@ -55,7 +38,7 @@ func Init(cfg *Config) error {
5538
if err := globalRedisClient.Init(cfg.Redis); err != nil {
5639
return err
5740
}
58-
if err := initRules(); err != nil {
41+
if _, err := LoadRules(cfg.Rules); err != nil {
5942
return err
6043
}
6144
return nil

core/llm_token_ratelimit/init_test.go

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -254,79 +254,6 @@ func TestInit_ConcurrentSafety(t *testing.T) {
254254
}
255255
}
256256

257-
func TestInitRules_ConcurrentSafety(t *testing.T) {
258-
// Save original state
259-
originalConfig := globalConfig.GetConfig()
260-
defer func() {
261-
if originalConfig != nil {
262-
globalConfig.SetConfig(originalConfig)
263-
}
264-
}()
265-
266-
// Set a test config
267-
testConfig := &Config{
268-
Rules: []*Rule{
269-
{
270-
ID: "test-rule-1",
271-
Resource: "/api/test",
272-
Strategy: FixedWindow,
273-
SpecificItems: []*SpecificItem{
274-
{
275-
Identifier: Identifier{Type: Header, Value: "*"},
276-
KeyItems: []*KeyItem{
277-
{
278-
Key: "*",
279-
Token: Token{Number: 1000, CountStrategy: TotalTokens},
280-
Time: Time{Unit: Second, Value: 60},
281-
},
282-
},
283-
},
284-
},
285-
},
286-
},
287-
}
288-
289-
err := globalConfig.SetConfig(testConfig)
290-
require.NoError(t, err)
291-
292-
const numGoroutines = 30
293-
var wg sync.WaitGroup
294-
errors := make(chan error, numGoroutines)
295-
296-
// Concurrent initRules calls
297-
for i := 0; i < numGoroutines; i++ {
298-
wg.Add(1)
299-
go func(id int) {
300-
defer wg.Done()
301-
if err := initRules(); err != nil {
302-
errors <- fmt.Errorf("initRules failed in goroutine %d: %v", id, err)
303-
}
304-
}(i)
305-
}
306-
307-
// Wait for completion
308-
done := make(chan struct{})
309-
go func() {
310-
wg.Wait()
311-
close(done)
312-
}()
313-
314-
select {
315-
case <-done:
316-
// Success
317-
case err := <-errors:
318-
t.Fatal(err)
319-
case <-time.After(15 * time.Second):
320-
t.Fatal("Test timed out")
321-
}
322-
323-
// Check for any remaining errors
324-
close(errors)
325-
for err := range errors {
326-
t.Errorf("Concurrent error: %v", err)
327-
}
328-
}
329-
330257
// Test that concurrent access doesn't cause data corruption
331258
func TestSafeConfig_DataIntegrity(t *testing.T) {
332259
config := &SafeConfig{}
@@ -534,9 +461,6 @@ func TestGlobalConfig_ConcurrentAccess(t *testing.T) {
534461
if cfg != nil {
535462
_ = cfg.ErrorCode // Basic access
536463
}
537-
case 2:
538-
// Call initRules (which uses globalConfig.GetConfig internally)
539-
_ = initRules() // Ignore errors as rules might not be valid without proper setup
540464
}
541465
}
542466
}(i)

core/llm_token_ratelimit/redis_client.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -152,34 +152,6 @@ func (c *SafeRedisClient) Eval(script string, keys []string, args ...interface{}
152152
return c.client.Eval(context.TODO(), script, keys, args...).Result()
153153
}
154154

155-
func (c *SafeRedisClient) Set(key string, value interface{}, expiration time.Duration) error {
156-
if c == nil {
157-
return fmt.Errorf("safe redis client is nil")
158-
}
159-
c.mu.RLock()
160-
defer c.mu.RUnlock()
161-
162-
if c.client == nil {
163-
return fmt.Errorf("redis client is not initialized")
164-
}
165-
166-
return c.client.Set(context.TODO(), key, value, expiration).Err()
167-
}
168-
169-
func (c *SafeRedisClient) Get(key string) (*redis.StringCmd, error) {
170-
if c == nil {
171-
return nil, fmt.Errorf("safe redis client is nil")
172-
}
173-
c.mu.RLock()
174-
defer c.mu.RUnlock()
175-
176-
if c.client == nil {
177-
return nil, fmt.Errorf("redis client is not initialized")
178-
}
179-
180-
return c.client.Get(context.TODO(), key), nil
181-
}
182-
183155
func (c *SafeRedisClient) Close() error {
184156
if c == nil {
185157
return fmt.Errorf("safe redis client is nil")

core/llm_token_ratelimit/rule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (r *Rule) ResourceName() string {
3232
return r.Resource
3333
}
3434

35-
// TODO: update rule string and tests
35+
// TODO: update rule string and tests when rule changed
3636
func (r *Rule) String() string {
3737
if r == nil {
3838
return "Rule{nil}"

0 commit comments

Comments
 (0)