change ids
All checks were successful
Build and Publish / Metadata (push) Successful in 3s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 50s
Build and Publish / BuildAndDeployArm64 (push) Successful in 4m25s

This commit is contained in:
matst80
2025-10-10 21:50:18 +00:00
parent b0e6c8eca8
commit e48a2590bd
13 changed files with 312 additions and 510 deletions

22
main.go
View File

@@ -72,7 +72,7 @@ func (a *App) Save() error {
if grain == nil {
continue
}
if grain.GetLastChange() > a.storage.LastSaves[id] {
if grain.GetLastChange() > a.storage.LastSaves[uint64(id)] {
hasChanges = true
err := a.storage.Store(id, grain)
if err != nil {
@@ -160,12 +160,12 @@ func GetDiscovery() Discovery {
func main() {
storage, err := NewDiskStorage(fmt.Sprintf("data/%s_state.gob", name))
storage, err := NewDiskStorage(fmt.Sprintf("data/s_%s.gob", name))
if err != nil {
log.Printf("Error loading state: %v\n", err)
}
app := &App{
pool: NewGrainLocalPool(65535, 2*time.Hour, spawn),
pool: NewGrainLocalPool(65535, 15*time.Minute, spawn),
storage: storage,
}
@@ -253,7 +253,13 @@ func main() {
w.Write([]byte("no cart id to checkout is empty"))
return
}
cartId := ToCartId(cookie.Value)
parsed, ok := ParseCartId(cookie.Value)
if !ok {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("invalid cart id format"))
return
}
cartId := parsed
order, err = syncedServer.CreateOrUpdateCheckout(r.Host, cartId)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
@@ -393,9 +399,13 @@ func triggerOrderCompleted(err error, syncedServer *PoolServer, order *CheckoutO
OrderId: order.ID,
Status: order.Status,
}
_, applyErr := syncedServer.pool.Apply(ToCartId(order.MerchantReference1), mutation)
cid, ok := ParseCartId(order.MerchantReference1)
if !ok {
return fmt.Errorf("invalid cart id in order reference: %s", order.MerchantReference1)
}
_, applyErr := syncedServer.pool.Apply(cid, mutation)
if applyErr == nil {
_ = AppendCartEvent(ToCartId(order.MerchantReference1), mutation)
_ = AppendCartEvent(cid, mutation)
}
return applyErr
}