Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(db/redis)!: remove backward compatibility code #194

Open
wants to merge 1 commit into
base: master
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
37 changes: 5 additions & 32 deletions db/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const (
vpSeparator = "##"
deprecatedCPEsKey = "CPE#DeprecatedCPEs"
titleListKey = "CPE#Titles"
titleListCacheKey = "CPE#Cache#Titles"
titleKeyFormat = "CPE#Title#%s"
depKey = "CPE#DEP"
fetchMetaKey = "CPE#FETCHMETA"
Expand Down Expand Up @@ -255,38 +254,13 @@ func (r *RedisDriver) GetSimilarCpesByTitle(query string, n int, algorithm edlib
}

ctx := context.Background()
t, err := r.conn.Type(ctx, titleListKey).Result()
var ts []string
bs, err := r.conn.Get(ctx, titleListKey).Bytes()
if err != nil {
return nil, xerrors.Errorf("Failed to TYPE CPE#Titles. err: %w", err)
return nil, xerrors.Errorf("Failed to Get Titles. err: %w", err)
}

var ts []string
switch t {
case "string":
bs, err := r.conn.Get(ctx, titleListKey).Bytes()
if err != nil {
return nil, xerrors.Errorf("Failed to Get Titles. err: %w", err)
}
if err := json.Unmarshal(bs, &ts); err != nil {
return nil, xerrors.Errorf("Failed to Unmarshal JSON. err: %w", err)
}
case "set": // backward compatibility: https://github.com/vulsio/go-cpe-dictionary/pull/186
bs, err := r.conn.Get(ctx, titleListCacheKey).Bytes()
if err == nil {
if err := json.Unmarshal(bs, &ts); err != nil {
return nil, xerrors.Errorf("Failed to Unmarshal JSON. err: %w", err)
}
} else {
if !xerrors.Is(err, redis.Nil) {
return nil, xerrors.Errorf("Failed to Get Titles. err: %w", err)
}
ts, err = r.conn.SMembers(ctx, titleListKey).Result()
if err != nil {
return nil, xerrors.Errorf("Failed to SMembers Titles. err: %w", err)
}
}
default:
return nil, xerrors.Errorf("unexpected CPE#Titles type. expected: %q, actual: %q", []string{"string", "set"}, t)
if err := json.Unmarshal(bs, &ts); err != nil {
return nil, xerrors.Errorf("Failed to Unmarshal JSON. err: %w", err)
}

if len(ts) < n {
Expand Down Expand Up @@ -468,7 +442,6 @@ func (r *RedisDriver) InsertCpes(fetchType models.FetchType, cpes models.Fetched
for cpeURI := range oldDeps["DeprecatedCPEs"] {
_ = pipe.SRem(ctx, deprecatedCPEsKey, cpeURI)
}
_ = pipe.Del(ctx, titleListCacheKey)
for title, cpeURIs := range oldDeps["Title"] {
for cpeURI := range cpeURIs {
_ = pipe.SRem(ctx, fmt.Sprintf(titleKeyFormat, title), cpeURI)
Expand Down
Loading