@@ -19,7 +19,6 @@ package app
19
19
import (
20
20
"context"
21
21
"encoding/json"
22
- "errors"
23
22
"fmt"
24
23
"github.com/caarlos0/env"
25
24
client "github.com/devtron-labs/devtron/api/helm-app/service"
@@ -458,67 +457,13 @@ func convertUrlToHttpsIfSshType(url string) string {
458
457
return httpsURL
459
458
}
460
459
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
-
515
460
// getAppAndProjectForAppIdentifier, returns app db model for an app unique identifier or from display_name if both exists else it throws pg.ErrNoRows
516
461
func (impl AppCrudOperationServiceImpl ) getAppAndProjectForAppIdentifier (appIdentifier * helmBean.AppIdentifier ) (* appRepository.App , error ) {
517
462
app := & appRepository.App {}
518
463
var err error
519
464
appNameUniqueIdentifier := appIdentifier .GetUniqueAppNameIdentifier ()
520
465
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 {
522
467
impl .logger .Errorw ("error in fetching app meta data by unique app identifier" , "appNameUniqueIdentifier" , appNameUniqueIdentifier , "err" , err )
523
468
return app , err
524
469
}
@@ -530,14 +475,6 @@ func (impl AppCrudOperationServiceImpl) getAppAndProjectForAppIdentifier(appIden
530
475
return app , err
531
476
}
532
477
}
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
- }
541
478
return app , nil
542
479
}
543
480
@@ -595,17 +532,17 @@ func (impl AppCrudOperationServiceImpl) GetHelmAppMetaInfo(appId string) (*bean.
595
532
return nil , err
596
533
}
597
534
// 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 {
599
536
err = impl .updateAppNameToUniqueAppIdentifierInApp (app , appIdDecoded )
600
537
if err != nil {
601
538
impl .logger .Errorw ("GetHelmAppMetaInfo, error in migrating displayName and appName to unique identifier for external apps" , "appIdentifier" , appIdDecoded , "err" , err )
602
539
//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
603
540
}
604
541
}
605
- if app != nil && app .Id == 0 {
542
+ if app .Id == 0 {
606
543
app .AppName = appIdDecoded .ReleaseName
607
544
}
608
- if app != nil && util2 .IsExternalChartStoreApp (app .DisplayName ) {
545
+ if util2 .IsExternalChartStoreApp (app .DisplayName ) {
609
546
displayName = app .DisplayName
610
547
}
611
548
@@ -631,14 +568,9 @@ func (impl AppCrudOperationServiceImpl) GetHelmAppMetaInfo(appId string) (*bean.
631
568
displayName = InstalledApp .App .DisplayName
632
569
}
633
570
}
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
- }
639
571
640
572
user , err := impl .userRepository .GetByIdIncludeDeleted (app .CreatedBy )
641
- if err != nil && ! errors . Is ( err , pg .ErrNoRows ) {
573
+ if err != nil && err != pg .ErrNoRows {
642
574
impl .logger .Errorw ("error in fetching user for app meta info" , "error" , err )
643
575
return nil , err
644
576
}
0 commit comments