Skip to content

Commit

Permalink
fix issue during 1st start
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Turrado <jorge.turrado@scrm.lidl>
  • Loading branch information
JorTurFer committed Aug 17, 2023
1 parent 2f8619c commit 99e0b80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 additions & 7 deletions server/application/application.go
Expand Up @@ -1418,13 +1418,20 @@ func (s *Server) RevisionMetadata(ctx context.Context, q *application.RevisionMe

var source *v1alpha1.ApplicationSource
if a.Spec.HasMultipleSources() {
// the source count can change during the time, we cannot just trust in .status.sync
// because if a source has been added/removed, the revisions there won't match
// as this is only used for the UI and not internally, we can use the historical data
// using the specific revisionId
for _, h := range a.Status.History {
if h.ID == int64(*q.VersionId) {
source = &h.Sources[*q.SourceIndex]
// If the historical data is empty (because the app hasn't been sysnced yet)
// we can use the source, if not (the app has been synced at least once)
// we have to use the history because sources can be added/removed
if len(a.Status.History) == 0 {
source = &a.Spec.Sources[*q.SourceIndex]
} else {
// the source count can change during the time, we cannot just trust in .status.sync
// because if a source has been added/removed, the revisions there won't match
// as this is only used for the UI and not internally, we can use the historical data
// using the specific revisionId
for _, h := range a.Status.History {
if h.ID == int64(*q.VersionId) {
source = &h.Sources[*q.SourceIndex]
}
}
}
if source == nil {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/applications/components/utils.tsx
Expand Up @@ -1045,7 +1045,7 @@ export function getAppDefaultSyncRevision(app?: appModels.Application) {
// getAppCurrentVersion gets the first app revisions from `status.sync.revisions` or, if that list is missing or empty, the `revision`
// field.
export function getAppCurrentVersion(app?: appModels.Application) {
if (!app || !app.status || !app.status.sync) {
if (!app || !app.status || !app.status.history) {
return 0;
}
return app.status.history[app.status.history.length - 1].id;
Expand Down

0 comments on commit 99e0b80

Please sign in to comment.