Skip to content

Commit

Permalink
feat: add opts to composeAppsWithStoreInfo (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH committed May 17, 2024
1 parent 0420cd2 commit 3239189
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 16 additions & 6 deletions route/v2/compose_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
var ErrComposeAppIDNotProvided = errors.New("compose AppID (compose project name) is not provided")

func (a *AppManagement) MyComposeAppList(ctx echo.Context) error {
composeAppsWithStoreInfo, err := composeAppsWithStoreInfo(ctx.Request().Context())
composeAppsWithStoreInfo, err := composeAppsWithStoreInfo(ctx.Request().Context(), composeAppsWithStoreInfoOpts{
checkIsUpdateAvailable: true,
})
if err != nil {
message := err.Error()
logger.Error("failed to list compose apps with store info", zap.Error(err))
Expand Down Expand Up @@ -621,7 +623,14 @@ func YAMLfromRequest(ctx echo.Context) ([]byte, error) {
return buf, nil
}

func composeAppsWithStoreInfo(ctx context.Context) (map[string]codegen.ComposeAppWithStoreInfo, error) {
type composeAppsWithStoreInfoOpts struct {
checkIsUpdateAvailable bool
// The /web/appgrid endpoint does not require information about whether the application can be updated, so we added an option.
// This endpoint is called as soon as CasaOS is opened, and we don't have time to cache it in advance.
// We must ensure that this endpoint responds as quickly as possible.
}

func composeAppsWithStoreInfo(ctx context.Context, opts composeAppsWithStoreInfoOpts) (map[string]codegen.ComposeAppWithStoreInfo, error) {
composeApps, err := service.MyService.Compose().List(ctx)
if err != nil {
return nil, err
Expand All @@ -648,10 +657,11 @@ func composeAppsWithStoreInfo(ctx context.Context) (map[string]codegen.ComposeAp

composeAppWithStoreInfo.StoreInfo = storeInfo

// check if updateAvailable
updateAvailable := service.MyService.AppStoreManagement().IsUpdateAvailable(composeApp)

composeAppWithStoreInfo.UpdateAvailable = &updateAvailable
if opts.checkIsUpdateAvailable {
// check if updateAvailable
updateAvailable := service.MyService.AppStoreManagement().IsUpdateAvailable(composeApp)
composeAppWithStoreInfo.UpdateAvailable = &updateAvailable
}

// status
if storeInfo.Main == nil {
Expand Down
4 changes: 3 additions & 1 deletion route/v2/internal_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (

func (a *AppManagement) GetAppGrid(ctx echo.Context) error {
// v2 Apps
composeAppsWithStoreInfo, err := composeAppsWithStoreInfo(ctx.Request().Context())
composeAppsWithStoreInfo, err := composeAppsWithStoreInfo(ctx.Request().Context(), composeAppsWithStoreInfoOpts{
checkIsUpdateAvailable: false,
})
if err != nil {
message := err.Error()
logger.Error("failed to list compose apps with store info", zap.Error(err))
Expand Down

0 comments on commit 3239189

Please sign in to comment.