fix: race condition on sync mode

This commit is contained in:
Cristian Vidmar 2023-10-02 17:50:10 +02:00
parent 524dd9d61b
commit 9b9fdad2cd
8 changed files with 11 additions and 9 deletions

View File

@ -615,6 +615,7 @@ func (cc *ContentfulClient) UpdateCache(ctx context.Context, contentTypes []stri
ctxAtWork, cancel := context.WithTimeout(ctx, time.Second*time.Duration(cc.cacheUpdateTimeout))
defer cancel()
localOffline := cc.offline
isSync := cc.sync
cc.cacheMutex.sharedDataGcLock.RUnlock()
if localOffline {
@ -632,7 +633,7 @@ func (cc *ContentfulClient) UpdateCache(ctx context.Context, contentTypes []stri
}
}
}
if cc.sync {
if isSync {
return cc.syncCache(ctxAtWork, contentTypes)
}
cc.cacheWorkerOnce.Do(func() {

View File

@ -14,7 +14,7 @@ import (
"github.com/foomo/gocontentful/erm"
)
var VERSION = "v1.0.23"
var VERSION = "v1.0.25"
type contentfulRc struct {
ManagementToken string `json:"managementToken"`

View File

@ -1,4 +1,4 @@
// Code generated by https://github.com/foomo/gocontentful v1.0.23 - DO NOT EDIT.
// Code generated by https://github.com/foomo/gocontentful v1.0.24 - DO NOT EDIT.
package testapi
import (

View File

@ -1,4 +1,4 @@
// Code generated by https://github.com/foomo/gocontentful v1.0.23 - DO NOT EDIT.
// Code generated by https://github.com/foomo/gocontentful v1.0.24 - DO NOT EDIT.
package testapi
import "github.com/foomo/contentful"

View File

@ -1,4 +1,4 @@
// Code generated by https://github.com/foomo/gocontentful v1.0.23 - DO NOT EDIT.
// Code generated by https://github.com/foomo/gocontentful v1.0.24 - DO NOT EDIT.
package testapi
import (
@ -649,6 +649,7 @@ func (cc *ContentfulClient) UpdateCache(ctx context.Context, contentTypes []stri
ctxAtWork, cancel := context.WithTimeout(ctx, time.Second*time.Duration(cc.cacheUpdateTimeout))
defer cancel()
localOffline := cc.offline
isSync := cc.sync
cc.cacheMutex.sharedDataGcLock.RUnlock()
if localOffline {
@ -666,7 +667,7 @@ func (cc *ContentfulClient) UpdateCache(ctx context.Context, contentTypes []stri
}
}
}
if cc.sync {
if isSync {
return cc.syncCache(ctxAtWork, contentTypes)
}
cc.cacheWorkerOnce.Do(func() {

View File

@ -1,4 +1,4 @@
// Code generated by https://github.com/foomo/gocontentful v1.0.23 - DO NOT EDIT.
// Code generated by https://github.com/foomo/gocontentful v1.0.24 - DO NOT EDIT.
package testapi
import (

View File

@ -1,4 +1,4 @@
// Code generated by https://github.com/foomo/gocontentful v1.0.23 - DO NOT EDIT.
// Code generated by https://github.com/foomo/gocontentful v1.0.24 - DO NOT EDIT.
package testapi
import (

View File

@ -1,4 +1,4 @@
// Code generated by https://github.com/foomo/gocontentful v1.0.23 - DO NOT EDIT.
// Code generated by https://github.com/foomo/gocontentful v1.0.24 - DO NOT EDIT.
package testapi
import (