fix: deliverytime timestamp error and riderlogs read timeouts
CreateOrder had no fallback for Deliverytime (unlike Orderdate), so it defaulted to "" and Postgres rejected it as an invalid timestamp on every order creation - reproduced and confirmed via a direct manual INSERT. Same fallback pattern as Orderdate now applies. Also carries the v2.7.58 fix that was live but never committed: GetRiderLogsv1 and UpdateRiderLogv1 scope a 15s timeout to their riderlogs full-list LRANGE (900K+ entries, routinely 5-6.5s), instead of the default 3s client timeout that was causing getriderlogs 500s. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -401,6 +401,12 @@ func CreateOrder(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
// ✅ Fallback if deliverytime is missing - it maps to a `timestamp` column,
|
||||
// so an empty string (the zero value) is rejected by Postgres outright.
|
||||
if strings.TrimSpace(data.Deliverytime) == "" {
|
||||
data.Deliverytime = time.Now().Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
// ✅ Fallback if orderdate is missing
|
||||
if strings.TrimSpace(data.Orderdate) == "" {
|
||||
data.Orderdate = time.Now().Format("2006-01-02 15:04:05")
|
||||
|
||||
@@ -1053,7 +1053,9 @@ func UpdateRiderLogv1(data models.Riderlogs) error {
|
||||
ctx := context.Background()
|
||||
key := "riderlogs"
|
||||
|
||||
logs, err := db.Rdb.LRange(ctx, key, 0, -1).Result()
|
||||
// See comment in GetRiderLogsv1: riderlogs is an unbounded list, full scans
|
||||
// need more than the client's default 3s ReadTimeout.
|
||||
logs, err := db.Rdb.WithTimeout(15 * time.Second).LRange(ctx, key, 0, -1).Result()
|
||||
if err != nil {
|
||||
return errors.New("failed to fetch logs from redis: " + err.Error())
|
||||
}
|
||||
@@ -1156,7 +1158,11 @@ func GetRiderLogsv1(fromdate, todate, keyword string, partnerid int) ([]models.R
|
||||
ctx := context.Background()
|
||||
results := []models.Riderlogsv1{}
|
||||
|
||||
redisList, err := db.Rdb.LRange(ctx, "riderlogs", 0, -1).Result()
|
||||
// riderlogs is an unbounded, ever-growing list (900K+ entries as of writing).
|
||||
// A full-list LRANGE routinely takes several seconds, well past the client's
|
||||
// default 3s ReadTimeout, so this call gets a longer timeout scoped to just
|
||||
// this request instead of loosening the timeout for every Redis call.
|
||||
redisList, err := db.Rdb.WithTimeout(15 * time.Second).LRange(ctx, "riderlogs", 0, -1).Result()
|
||||
if err != nil {
|
||||
return nil, errors.New("redis lrange error: " + err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user