From 3da5876e4c09f4a7330b55393e0ac570d64c3238 Mon Sep 17 00:00:00 2001 From: Suriya Date: Tue, 21 Jul 2026 11:24:48 +0530 Subject: [PATCH] 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 --- controllers/orderController.go | 6 ++++++ domain/partner.go | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/controllers/orderController.go b/controllers/orderController.go index dadc081..6bc6fa0 100644 --- a/controllers/orderController.go +++ b/controllers/orderController.go @@ -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") diff --git a/domain/partner.go b/domain/partner.go index 05a7783..c85772b 100644 --- a/domain/partner.go +++ b/domain/partner.go @@ -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()) }