This commit is contained in:
@@ -113,8 +113,7 @@ func (c *CartGrain) AddItem(sku string, qty int) ([]byte, error) {
|
||||
func (c *CartGrain) GetStorageMessage(since int64) []StorableMessage {
|
||||
|
||||
ret := make([]StorableMessage, 0)
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
for _, message := range c.storageMessages {
|
||||
if *message.TimeStamp > since {
|
||||
ret = append(ret, message)
|
||||
|
||||
5
main.go
5
main.go
@@ -58,6 +58,8 @@ type App struct {
|
||||
|
||||
func (a *App) Save() error {
|
||||
hasChanges := false
|
||||
a.pool.mu.RLock()
|
||||
defer a.pool.mu.RUnlock()
|
||||
for id, grain := range a.pool.GetGrains() {
|
||||
if grain == nil {
|
||||
continue
|
||||
@@ -70,6 +72,7 @@ func (a *App) Save() error {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !hasChanges {
|
||||
return nil
|
||||
}
|
||||
@@ -128,7 +131,7 @@ func main() {
|
||||
}
|
||||
|
||||
go func() {
|
||||
for range time.Tick(time.Minute) {
|
||||
for range time.Tick(time.Minute * 10) {
|
||||
|
||||
err := app.Save()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user