Skip to content

Commit

Permalink
pref: optimize gen patch logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwlin committed Jan 23, 2025
1 parent 0e1ea9c commit 29cb473
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/logic/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ func (l *VersionLogic) GetResourcePath(param GetResourcePathParam) string {
}

func (l *VersionLogic) GetPatchPath(ctx context.Context, param GetVersionPatchParam) (string, error) {
changes, err := patcher.CalculateDiff(param.TargetVersionFileHashes, param.CurrentVersionFileHashes)
exists, err := l.storage.PatchExists(param.ResourceID, param.TargetVersionID, param.CurrentVersionID)
if err != nil {
l.logger.Error("Failed to calculate diff",
l.logger.Error("Failed to check patch file exists",
zap.String("resource ID", param.ResourceID),
zap.Int("target version ID", param.TargetVersionID),
zap.Int("current version ID", param.CurrentVersionID),
Expand All @@ -293,9 +293,14 @@ func (l *VersionLogic) GetPatchPath(ctx context.Context, param GetVersionPatchPa
return "", err
}

exists, err := l.storage.PatchExists(param.ResourceID, param.TargetVersionID, param.CurrentVersionID)
if exists {
patchPath := l.storage.PatchPath(param.ResourceID, param.TargetVersionID, param.CurrentVersionID)
return patchPath, nil
}

changes, err := patcher.CalculateDiff(param.TargetVersionFileHashes, param.CurrentVersionFileHashes)
if err != nil {
l.logger.Error("Failed to check patch file exists",
l.logger.Error("Failed to calculate diff",
zap.String("resource ID", param.ResourceID),
zap.Int("target version ID", param.TargetVersionID),
zap.Int("current version ID", param.CurrentVersionID),
Expand All @@ -304,11 +309,6 @@ func (l *VersionLogic) GetPatchPath(ctx context.Context, param GetVersionPatchPa
return "", err
}

if exists {
patchPath := l.storage.PatchPath(param.ResourceID, param.TargetVersionID, param.CurrentVersionID)
return patchPath, nil
}

patchDir := l.storage.PatchDir(param.ResourceID, param.TargetVersionID)
latestStorage, err := l.storageRepo.GetStorageByVersionID(ctx, param.TargetVersionID)
if err != nil {
Expand Down

0 comments on commit 29cb473

Please sign in to comment.