This commit is contained in:
ferreo 2024-07-29 22:49:20 +01:00
parent 62dc61c68d
commit 373b99343d
6 changed files with 7 additions and 54 deletions

View File

@ -1,30 +0,0 @@
package handlers_build
import (
"brunel/buildqueue"
"brunel/domain"
"brunel/helpers"
"brunel/packages"
"time"
"github.com/gofiber/fiber/v2"
)
type BuildQueueCountResponse struct {
LastUpdateTime time.Time `json:"lastUpdateTime"`
Counts domain.BuildQueueCount `json:"counts"`
}
func Counts(c *fiber.Ctx) error {
if cachedResponse, ok := helpers.Cache.Get("buildcounts"); ok {
return c.Status(fiber.StatusOK).JSON(cachedResponse)
}
response := BuildQueueCountResponse{
LastUpdateTime: packages.LastUpdateTime,
Counts: buildqueue.GetCounts(),
}
helpers.Cache.Set("buildcounts", response)
return c.Status(fiber.StatusOK).JSON(response)
}

View File

@ -4,8 +4,6 @@ import (
"brunel/buildqueue"
"brunel/domain"
"brunel/fastmap"
"brunel/helpers"
"fmt"
"strings"
"github.com/gofiber/fiber/v2"
@ -22,11 +20,6 @@ func Queue(c *fiber.Ctx) error {
search := strings.ToLower(c.Query("search"))
filter := c.Query("filter")
cacheKey := fmt.Sprintf("buildqueue:%d:%d:%s:%s", pageNum, pageSize, search, filter)
if cachedResponse, ok := helpers.Cache.Get(cacheKey); ok {
return c.Status(fiber.StatusOK).JSON(cachedResponse)
}
// Adjust pageNum to be 0-based for GetPage
adjustedPageNum := pageNum - 1
if adjustedPageNum < 0 {
@ -60,6 +53,5 @@ func Queue(c *fiber.Ctx) error {
Packages: result,
}
helpers.Cache.Set(cacheKey, response)
return c.Status(fiber.StatusOK).JSON(response)
}

View File

@ -1,8 +1,8 @@
package handlers_packages
import (
"brunel/buildqueue"
"brunel/domain"
"brunel/helpers"
"brunel/packages"
"time"
@ -15,15 +15,14 @@ type CountsResponse struct {
}
func Counts(c *fiber.Ctx) error {
if cachedResponse, ok := helpers.Cache.Get("counts"); ok {
return c.Status(fiber.StatusOK).JSON(cachedResponse)
}
cts := packages.GetPackagesCount()
bcts := buildqueue.GetCounts()
cts.Building = bcts.Building
cts.Queued = bcts.Queued
response := CountsResponse{
LastUpdateTime: packages.LastUpdateTime,
Counts: packages.GetPackagesCount(),
Counts: cts,
}
helpers.Cache.Set("counts", response)
return c.Status(fiber.StatusOK).JSON(response)
}

View File

@ -3,9 +3,7 @@ package handlers_packages
import (
"brunel/domain"
"brunel/fastmap"
"brunel/helpers"
"brunel/packages"
"fmt"
"strings"
"github.com/gofiber/fiber/v2"
@ -22,11 +20,6 @@ func Packages(c *fiber.Ctx) error {
search := strings.ToLower(c.Query("search"))
filter := c.Query("filter")
cacheKey := fmt.Sprintf("packages:%d:%d:%s:%s", pageNum, pageSize, search, filter)
if cachedResponse, ok := helpers.Cache.Get(cacheKey); ok {
return c.Status(fiber.StatusOK).JSON(cachedResponse)
}
// Adjust pageNum to be 0-based for GetPage
adjustedPageNum := pageNum - 1
if adjustedPageNum < 0 {
@ -64,6 +57,5 @@ func Packages(c *fiber.Ctx) error {
Packages: result,
}
helpers.Cache.Set(cacheKey, response)
return c.Status(fiber.StatusOK).JSON(response)
}

View File

@ -431,5 +431,6 @@ func GetPackagesCount() domain.PackagesCount {
})
return true
})
return count
}

View File

@ -92,7 +92,6 @@ func runServer(ctx context.Context) error {
server.Get("/api/counts", handlers_packages.Counts)
server.Get("/api/packages", handlers_packages.Packages)
server.Get("/api/buildqueue", handlers_build.Queue)
server.Get("/api/buildcounts", handlers_build.Counts)
server.Post("/api/login", handlers_auth.Login)
adminRoutes.Post("/register", handlers_auth.Register)