Skip to content

Commit babcacf

Browse files
refactor: Refactor the cron function in http sync (#1600)
<!-- Please use this template for your pull request. --> <!-- Please use the sections that you need and delete other sections --> ## This PR Refactor the cron function in the `Sync` function for the HTTP sync. This might improve the performance as well because it reduces the number of HTTP requests. Signed-off-by: Zhiwei Liang <zhiwei.liang27@pm.me> Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
1 parent 8c5ac2f commit babcacf

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

core/pkg/sync/http/http_sync.go

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,20 @@ func (hs *Sync) Sync(ctx context.Context, dataSync chan<- sync.DataSync) error {
8282

8383
if body == "" {
8484
hs.Logger.Debug("configuration deleted")
85-
} else {
86-
if hs.LastBodySHA == "" {
87-
hs.Logger.Debug("new configuration created")
88-
msg, err := hs.Fetch(ctx)
89-
if err != nil {
90-
hs.Logger.Error(fmt.Sprintf("error fetching: %s", err.Error()))
91-
} else {
92-
dataSync <- sync.DataSync{FlagData: msg, Source: hs.URI, Type: sync.ALL}
93-
}
94-
} else {
95-
currentSHA := hs.generateSha([]byte(body))
96-
if hs.LastBodySHA != currentSHA {
97-
hs.Logger.Debug("configuration modified")
98-
msg, err := hs.Fetch(ctx)
99-
if err != nil {
100-
hs.Logger.Error(fmt.Sprintf("error fetching: %s", err.Error()))
101-
} else {
102-
dataSync <- sync.DataSync{FlagData: msg, Source: hs.URI, Type: sync.ALL}
103-
}
104-
}
105-
106-
hs.LastBodySHA = currentSHA
107-
}
85+
return
10886
}
87+
88+
currentSHA := hs.generateSha([]byte(body))
89+
90+
if hs.LastBodySHA == "" {
91+
hs.Logger.Debug("new configuration created")
92+
dataSync <- sync.DataSync{FlagData: body, Source: hs.URI, Type: sync.ALL}
93+
} else if hs.LastBodySHA != currentSHA {
94+
hs.Logger.Debug("configuration modified")
95+
dataSync <- sync.DataSync{FlagData: body, Source: hs.URI, Type: sync.ALL}
96+
}
97+
98+
hs.LastBodySHA = currentSHA
10999
})
110100

111101
hs.Cron.Start()

0 commit comments

Comments
 (0)