Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

perf: use + instead of strings.Builder #131

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 4 additions & 29 deletions cmd/interaction/dal/cache/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cache

import (
"fmt"
"strings"

"github.com/ozline/tiktok/pkg/constants"
)
Expand All @@ -18,41 +17,17 @@ func GetUserLikeKey(userID int64) string {
}

func GetCommentNXKey(videoID string) string {
var builder strings.Builder
builder.Grow(len(constants.CommentNXKey) + 1 + len(videoID))
builder.WriteString(constants.CommentNXKey)
builder.WriteString(":")
builder.WriteString(videoID)
// return fmt.Sprintf("%s:%s", constants.CommentNXKey, videoID)
return builder.String()
return constants.CommentNXKey + ":" + videoID
}

func GetCountKey(videoID string) string {
var builder strings.Builder
builder.Grow(len(constants.CountKey) + 1 + len(videoID))
builder.WriteString(constants.CountKey)
builder.WriteString(":")
builder.WriteString(videoID)
// return fmt.Sprintf("%s:%s", constants.CountKey, videoID)
return builder.String()
return constants.CountKey + ":" + videoID
}

func GetCommentKey(videoID string) string {
var builder strings.Builder
builder.Grow(len(constants.CommentKey) + 1 + len(videoID))
builder.WriteString(constants.CommentKey)
builder.WriteString(":")
builder.WriteString(videoID)
// return fmt.Sprintf("%s:%s", constants.CommentKey, videoID)
return builder.String()
return constants.CommentKey + ":" + videoID
}

func GetCountNXKey(videoID string) string {
var builder strings.Builder
builder.Grow(len(constants.CountNXKey) + 1 + len(videoID))
builder.WriteString(constants.CountNXKey)
builder.WriteString(":")
builder.WriteString(videoID)
// return fmt.Sprintf("%s:%s", constants.CountNXKey, videoID)
return builder.String()
return constants.CountNXKey + ":" + videoID
}