@@ -19,7 +19,6 @@ package app
1919import (
2020 "context"
2121 "encoding/json"
22- "errors"
2322 "fmt"
2423 "github.com/caarlos0/env"
2524 client "github.com/devtron-labs/devtron/api/helm-app/service"
@@ -458,67 +457,13 @@ func convertUrlToHttpsIfSshType(url string) string {
458457 return httpsURL
459458}
460459
461- // handleDuplicateAppEntries identifies and resolves duplicate app entries based on creation time.
462- // It marks the most recent duplicate entry as inactive and updates the corresponding installed app.
463- func (impl AppCrudOperationServiceImpl ) handleDuplicateAppEntries (appNameUniqueIdentifier string ) (* appRepository.App , error ) {
464- // Fetch app IDs by name
465- appIds , err := impl .getAppIdsByName (appNameUniqueIdentifier )
466- if err != nil {
467- impl .logger .Errorw ("error in fetching app Ids by appIdentifier" , "appNameUniqueIdentifier" , appNameUniqueIdentifier , "err" , err )
468- return nil , err
469- }
470-
471- // Fetch apps by IDs from App table for duplicated entries
472- apps , err := impl .appRepository .FindByIds (appIds )
473- if err != nil || errors .Is (err , pg .ErrNoRows ) {
474- impl .logger .Errorw ("error in fetching app List by appIds" , "appIds" , appIds , "err" , err )
475- return nil , err
476- }
477-
478- // Identify the earliest and duplicated app entries
479- earliestApp , duplicatedApp := identifyDuplicateApps (apps )
480-
481- // Fetch the installed app associated with the duplicated app
482- installedApp , err := impl .installedAppRepository .GetInstalledAppsByAppId (duplicatedApp .Id )
483- if err != nil {
484- impl .logger .Errorw ("error in fetching installed app by appId" , "appId" , duplicatedApp .Id , "err" , err )
485- return nil , err
486- }
487- // Update duplicated app entries
488- err = impl .installedAppDbService .UpdateDuplicatedEntriesInAppAndInstalledApps (earliestApp , duplicatedApp , & installedApp )
489- if err != nil {
490- impl .logger .Errorw ("error in updating duplicated entries" , "earliestApp" , earliestApp , "duplicatedApp" , duplicatedApp , "err" , err )
491- return nil , err
492- }
493-
494- impl .logger .Debug ("Successfully resolved duplicate app entries" , "earliestApp" , earliestApp , "duplicatedApp" , duplicatedApp )
495- return earliestApp , nil
496-
497- }
498-
499- // getAppIdsByName fetches app IDs by the app name unique identifier [for duplicated active app]
500- func (impl AppCrudOperationServiceImpl ) getAppIdsByName (appNameUniqueIdentifier string ) ([]* int , error ) {
501- slice := []string {appNameUniqueIdentifier }
502- appIds , err := impl .appRepository .FindIdsByNames (slice )
503- if err != nil {
504- return nil , err
505- }
506-
507- // Convert each element to a pointer and store in a slice of pointers
508- ids := make ([]* int , len (appIds ))
509- for i := range appIds {
510- ids [i ] = & appIds [i ]
511- }
512- return ids , nil
513- }
514-
515460// getAppAndProjectForAppIdentifier, returns app db model for an app unique identifier or from display_name if both exists else it throws pg.ErrNoRows
516461func (impl AppCrudOperationServiceImpl ) getAppAndProjectForAppIdentifier (appIdentifier * helmBean.AppIdentifier ) (* appRepository.App , error ) {
517462 app := & appRepository.App {}
518463 var err error
519464 appNameUniqueIdentifier := appIdentifier .GetUniqueAppNameIdentifier ()
520465 app , err = impl .appRepository .FindAppAndProjectByAppName (appNameUniqueIdentifier )
521- if err != nil && ! errors . Is ( err , pg . ErrNoRows ) && ! errors . Is ( err , pg .ErrMultiRows ) {
466+ if err != nil && err != pg .ErrNoRows {
522467 impl .logger .Errorw ("error in fetching app meta data by unique app identifier" , "appNameUniqueIdentifier" , appNameUniqueIdentifier , "err" , err )
523468 return app , err
524469 }
@@ -530,14 +475,6 @@ func (impl AppCrudOperationServiceImpl) getAppAndProjectForAppIdentifier(appIden
530475 return app , err
531476 }
532477 }
533- if errors .Is (err , pg .ErrMultiRows ) {
534-
535- app , err = impl .handleDuplicateAppEntries (appNameUniqueIdentifier )
536- if err != nil {
537- impl .logger .Errorw ("error in handling Duplicate entries in the app" , "appNameUniqueIdentifier" , appNameUniqueIdentifier , "err" , err )
538- return app , err
539- }
540- }
541478 return app , nil
542479}
543480
@@ -595,17 +532,17 @@ func (impl AppCrudOperationServiceImpl) GetHelmAppMetaInfo(appId string) (*bean.
595532 return nil , err
596533 }
597534 // if app.DisplayName is empty then that app_name is not yet migrated to app name unique identifier
598- if app != nil && app .Id > 0 && len (app .DisplayName ) == 0 {
535+ if app .Id > 0 && len (app .DisplayName ) == 0 {
599536 err = impl .updateAppNameToUniqueAppIdentifierInApp (app , appIdDecoded )
600537 if err != nil {
601538 impl .logger .Errorw ("GetHelmAppMetaInfo, error in migrating displayName and appName to unique identifier for external apps" , "appIdentifier" , appIdDecoded , "err" , err )
602539 //not returning from here as we need to show helm app metadata even if migration of app_name fails, then migration can happen on project update
603540 }
604541 }
605- if app != nil && app .Id == 0 {
542+ if app .Id == 0 {
606543 app .AppName = appIdDecoded .ReleaseName
607544 }
608- if app != nil && util2 .IsExternalChartStoreApp (app .DisplayName ) {
545+ if util2 .IsExternalChartStoreApp (app .DisplayName ) {
609546 displayName = app .DisplayName
610547 }
611548
@@ -631,14 +568,9 @@ func (impl AppCrudOperationServiceImpl) GetHelmAppMetaInfo(appId string) (*bean.
631568 displayName = InstalledApp .App .DisplayName
632569 }
633570 }
634- // Safeguard against nil app cases
635- if app == nil {
636- impl .logger .Errorw ("no rows found for the requested app" , "appId" , appId , "error" , err )
637- return nil , fmt .Errorf ("no rows found for the requested app, %q" , pg .ErrNoRows )
638- }
639571
640572 user , err := impl .userRepository .GetByIdIncludeDeleted (app .CreatedBy )
641- if err != nil && ! errors . Is ( err , pg .ErrNoRows ) {
573+ if err != nil && err != pg .ErrNoRows {
642574 impl .logger .Errorw ("error in fetching user for app meta info" , "error" , err )
643575 return nil , err
644576 }
0 commit comments