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 #403

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MaineK00n
Copy link
Collaborator

If this Pull Request is work in progress, Add a prefix of “[WIP]” in the title.

What did you implement:

With #402, Redis PKG keys no longer have Arch at the end, even if they are Amazon, Oracle, or Fedora.
1da5dfb#diff-47497c0e5aee216ce040118072f4e2199cc00ec8f2c55059b2c4729ec026e101L324-L335

This part is for backward compatibility, and it is no longer necessary when most users are fetched with new goval-dictionary.

case c.Amazon, c.Oracle, c.Fedora:
isOld, err := func() (bool, error) {
bs, err := r.conn.Get(ctx, fmt.Sprintf(depKeyFormat, family, osVer)).Bytes()
if err != nil {
return false, xerrors.Errorf("Failed to Get %s. err: %w", fmt.Sprintf(depKeyFormat, family, osVer), err)
}
var dep map[string]map[string]map[string]struct{}
if err := json.Unmarshal(bs, &dep); err != nil {
return false, xerrors.Errorf("Failed to Unmarshal JSON. err: %w", err)
}
for _, def := range dep {
for k := range def["packages"] {
return strings.Contains(k, "#"), nil // old pattern: <package name>#<archtecture>
}
}
return false, xerrors.Errorf("%s:*:packages is empty", fmt.Sprintf(depKeyFormat, family, osVer))
}()
if err != nil {
return nil, xerrors.Errorf("Failed to check old goval-dictionary redis architecture. err: %w", err)
}
if isOld {
if arch != "" {
defIDs, err := r.conn.SMembers(ctx, fmt.Sprintf(pkgKeyFormat, family, osVer, fmt.Sprintf("%s#%s", packName, arch))).Result()
if err != nil {
return nil, xerrors.Errorf("Failed to SMembers. err: %w", err)
}
return defIDs, nil
}
dbsize, err := r.conn.DBSize(ctx).Result()
if err != nil {
return nil, xerrors.Errorf("Failed to DBSize. err: %w", err)
}
var pkgKeys []string
var cursor uint64
for {
var keys []string
var err error
keys, cursor, err = r.conn.Scan(ctx, cursor, fmt.Sprintf(pkgKeyFormat, family, osVer, fmt.Sprintf("%s#%s", packName, "*")), dbsize/5).Result()
if err != nil {
return nil, xerrors.Errorf("Failed to Scan. err: %w", err)
}
pkgKeys = append(pkgKeys, keys...)
if cursor == 0 {
break
}
}
pipe := r.conn.Pipeline()
for _, pkey := range pkgKeys {
_ = pipe.SMembers(ctx, pkey)
}
cmders, err := pipe.Exec(ctx)
if err != nil {
return nil, xerrors.Errorf("Failed to exec pipeline. err: %w", err)
}
var defIDs []string
for _, cmder := range cmders {
result, err := cmder.(*redis.StringSliceCmd).Result()
if err != nil {
return nil, xerrors.Errorf("Failed to SMembers. err: %w", err)
}
defIDs = append(defIDs, result...)
}
return defIDs, nil
}
defIDs, err := r.conn.SMembers(ctx, fmt.Sprintf(pkgKeyFormat, family, osVer, packName)).Result()
if err != nil {
return nil, xerrors.Errorf("Failed to SMembers. err: %w", err)
}
return defIDs, nil

For the hygiene of the code, I will erase it after a certain period of time.

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

Checklist:

You don't have to satisfy all of the following.

  • Write tests
  • Write documentation
  • Check that there aren't other open pull requests for the same issue/feature
  • Format your source code by make fmt
  • Pass the test by make test
  • Provide verification config / commands
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES

Reference

@MaineK00n MaineK00n self-assigned this Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant