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

fix: latest chart version fix #22

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions internal/sql/AppStoreApplicationVersionRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type AppStoreApplicationVersionRepository interface {
FindVersionsByAppStoreId(appStoreId int) ([]*AppStoreApplicationVersion, error)
Save(versions *[]*AppStoreApplicationVersion) error
FindLatestCreated(appStoreId int) (*AppStoreApplicationVersion, error)
FindOneByAppStoreIdAndVersion(appStoreId int, version string) (*AppStoreApplicationVersion, error)
FindLatestCreatedByAppStoreId(appStoreId int) (*AppStoreApplicationVersion, error)
FindLatest(appStoreId int) (*AppStoreApplicationVersion, error)
Update(appVersions []*AppStoreApplicationVersion) error
}
Expand Down Expand Up @@ -73,11 +73,11 @@ func (impl AppStoreApplicationVersionRepositoryImpl) FindLatestCreated(appStoreI
return appStoreApplicationVersion, err
}

func (impl AppStoreApplicationVersionRepositoryImpl) FindOneByAppStoreIdAndVersion(appStoreId int, version string) (*AppStoreApplicationVersion, error) {
func (impl AppStoreApplicationVersionRepositoryImpl) FindLatestCreatedByAppStoreId(appStoreId int) (*AppStoreApplicationVersion, error) {
appStoreApplicationVersion := &AppStoreApplicationVersion{}
err := impl.dbConnection.Model(appStoreApplicationVersion).
Where("app_store_id =?", appStoreId).
Where("version =?", version).
OrderExpr("order by created desc ").
Limit(1).
Select()
return appStoreApplicationVersion, err
Expand Down
27 changes: 17 additions & 10 deletions pkg/SyncService.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,27 +493,34 @@ func (impl *SyncServiceImpl) updateOCIRegistryChartVersions(client *registry.Cli
}
// Update latest version for the chart
if chartVersionsCount > 0 {

var latestFlagAppVersions []*sql.AppStoreApplicationVersion
latestChartVersion := chartVersions[0]
latestCreated, err := impl.appStoreApplicationVersionRepository.FindOneByAppStoreIdAndVersion(appId, latestChartVersion)
if err != nil {
latestCreated, err := impl.appStoreApplicationVersionRepository.FindLatestCreatedByAppStoreId(appId)
if err != nil && err != pg.ErrNoRows {
impl.logger.Errorw("error in marking latest", "err", err)
return err
}

if latestCreated != nil && latestCreated.Id == 0 {
return nil
}

latestCreated.Latest = true
latestFlagAppVersions = append(latestFlagAppVersions, latestCreated)
application, err := impl.appStoreApplicationVersionRepository.FindLatest(appId)

currentLatest, err := impl.appStoreApplicationVersionRepository.FindLatest(appId)
if err != nil && err != pg.ErrNoRows {
impl.logger.Errorw("error in marking latest", "err", err)
impl.logger.Errorw("error in finding current latest chart", "appStoreId", appId, "err", err)
return err
}
if application.Id == latestCreated.Id {

if currentLatest != nil && currentLatest.Id == latestCreated.Id {
return nil
} else if currentLatest != nil && currentLatest.Id > 0 {
currentLatest.Latest = false
latestFlagAppVersions = append(latestFlagAppVersions, currentLatest)
}
if err == nil {
application.Latest = false
latestFlagAppVersions = append(latestFlagAppVersions, application)
}

err = impl.appStoreApplicationVersionRepository.Update(latestFlagAppVersions)
if err != nil {
impl.logger.Errorw("error in marking latest", "err", err)
Expand Down