-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(topic): performance for read and creation
- Loading branch information
1 parent
dffd94c
commit de74863
Showing
5 changed files
with
58 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
internal/sdkprovider/service/kafkatopic/kafka_topic_exists.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package kafkatopic | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"sync" | ||
|
||
"github.com/aiven/aiven-go-client/v2" | ||
"golang.org/x/exp/slices" | ||
) | ||
|
||
var onceForService sync.Map | ||
|
||
// isTopicExists checks if topic exists | ||
func isTopicExists(ctx context.Context, client *aiven.Client, project, serviceName, topic string) bool { | ||
c := getTopicCache() | ||
|
||
var err error | ||
once, _ := onceForService.LoadOrStore(project+"/"+serviceName, new(sync.Once)) | ||
once.(*sync.Once).Do(func() { | ||
var list []*aiven.KafkaListTopic | ||
list, err = client.KafkaTopics.List(ctx, project, serviceName) | ||
if err != nil { | ||
return | ||
} | ||
|
||
c.SetV1List(project, serviceName, list) | ||
}) | ||
|
||
if err != nil { | ||
log.Printf("[ERROR] cannot check kafka topic existence: %s", err) | ||
return false | ||
} | ||
|
||
if slices.Contains(c.GetV1List(project, serviceName), topic) || slices.Contains(c.GetQueue(project, serviceName), topic) { | ||
return true | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters