Fix old pacakge versions hanging around

This commit is contained in:
ferreo 2024-07-30 19:17:33 +01:00
parent 6c31af0166
commit c2d3850a33
4 changed files with 31 additions and 0 deletions

View File

@ -129,6 +129,15 @@ func (r *Repository) SavePackages(pkgs *haxmap.Map[string, domain.SourcePackage]
return nil return nil
} }
func (r *Repository) DropPackages() error {
tx := r.db.Where("1 = 1").Delete(&domain.SourcePackageDTO{})
if tx.Error != nil {
return tx.Error
}
tx = r.db.Where("1 = 1").Delete(&domain.PackageInfo{})
return tx.Error
}
func (r *Repository) UpdateLastUpdateTime(time time.Time) error { func (r *Repository) UpdateLastUpdateTime(time time.Time) error {
val := &domain.TimeContainer{ val := &domain.TimeContainer{
Time: time, Time: time,

View File

@ -0,0 +1,17 @@
package handlers_packages
import (
"brunel/packages"
"github.com/gofiber/fiber/v2"
)
func Package(c *fiber.Ctx) error {
pkgName := c.Params("package")
packs := packages.GetPackages()
pack, ok := packs.Get(pkgName)
if !ok {
return c.Status(fiber.StatusNotFound).SendString("Package not found")
}
return c.Status(fiber.StatusOK).JSON(pack)
}

View File

@ -92,6 +92,10 @@ func ProcessPackages() error {
LastUpdateTime = time.Now() LastUpdateTime = time.Now()
helpers.ReloadCache() helpers.ReloadCache()
err = helpers.DBInst.DropPackages()
if err != nil {
return err
}
err = SaveToDb() err = SaveToDb()
if err != nil { if err != nil {
return err return err

View File

@ -92,6 +92,7 @@ func runServer(ctx context.Context) error {
server.Get("/api/counts", handlers_packages.Counts) server.Get("/api/counts", handlers_packages.Counts)
server.Get("/api/packages", handlers_packages.Packages) server.Get("/api/packages", handlers_packages.Packages)
server.Get("/api/package/:package", handlers_packages.Package)
server.Get("/api/queue", handlers_build.Queue) server.Get("/api/queue", handlers_build.Queue)
server.Get("/api/errored", handlers_build.Errored) server.Get("/api/errored", handlers_build.Errored)