Update MinIO bucket configuration and enhance dashboard service caching
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
- Changed the default MinIO bucket name from "opplens-documents" to "opplens" across multiple configuration files. - Introduced caching for dashboard statistics in the service layer to improve performance and reduce redundant data fetching. - Implemented a mutex for thread-safe access to cached statistics, ensuring data integrity during concurrent requests. This update streamlines the configuration for the AI summarizer and optimizes the dashboard service, enhancing overall system efficiency.
This commit is contained in:
+39
-6
@@ -104,14 +104,47 @@ func (c *Counter) GetDailyCounts(ctx context.Context, startDay, endDay time.Time
|
||||
return map[string]int64{}, nil
|
||||
}
|
||||
|
||||
counts := make(map[string]int64)
|
||||
keys := make([]string, 0)
|
||||
dates := make([]string, 0)
|
||||
for day := startDay; !day.After(endDay); day = day.AddDate(0, 0, 1) {
|
||||
date := day.Format("2006-01-02")
|
||||
value, err := c.Get(ctx, AITranslationSuccessDailyCounterKey(day))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
dates = append(dates, day.Format("2006-01-02"))
|
||||
keys = append(keys, AITranslationSuccessDailyCounterKey(day))
|
||||
}
|
||||
|
||||
counts := make(map[string]int64, len(dates))
|
||||
for _, date := range dates {
|
||||
counts[date] = 0
|
||||
}
|
||||
|
||||
cursor, err := c.mongo.GetCollection(metricsCountersCollection).Find(ctx, bson.M{
|
||||
"_id": bson.M{"$in": keys},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("mongo counter get daily counts: %w", err)
|
||||
}
|
||||
defer cursor.Close(ctx)
|
||||
|
||||
keyToDate := make(map[string]string, len(keys))
|
||||
for i, key := range keys {
|
||||
keyToDate[key] = dates[i]
|
||||
}
|
||||
|
||||
for cursor.Next(ctx) {
|
||||
var doc struct {
|
||||
ID string `bson:"_id"`
|
||||
Count int64 `bson:"count"`
|
||||
}
|
||||
counts[date] = value
|
||||
if err := cursor.Decode(&doc); err != nil {
|
||||
return nil, fmt.Errorf("mongo counter decode daily count: %w", err)
|
||||
}
|
||||
date, ok := keyToDate[doc.ID]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
counts[date] = doc.Count
|
||||
}
|
||||
if err := cursor.Err(); err != nil {
|
||||
return nil, fmt.Errorf("mongo counter iterate daily counts: %w", err)
|
||||
}
|
||||
|
||||
return counts, nil
|
||||
|
||||
Reference in New Issue
Block a user