Skip to content

Commit

Permalink
fix(gebura): update SyncAppInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Mar 12, 2024
1 parent e3012ee commit 4f87179
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/sephirah/internal/biz/bizangela/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func NewPullAppInfoTopic(
if !a.supv.CheckAppInfoSource(r.AppInfoID.Source) {
return nil
}
if r.AppInfoID.Internal {
return nil
}
if !r.IgnoreRateLimit {
if info, err := infoCache.GetWithFallBack(ctx, r.AppInfoID, nil); err == nil &&
info.LatestUpdateTime.Add(libtime.Day).After(time.Now()) {
Expand Down
12 changes: 11 additions & 1 deletion app/sephirah/internal/biz/bizgebura/app_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (g *Gebura) SyncAppInfos(
err = g.pullAppInfo.LocalCall(ctx, modelangela.PullAppInfo{
ID: ids[i],
AppInfoID: *infoID,
IgnoreRateLimit: true,
IgnoreRateLimit: false,
})
if err != nil {
return nil, pb.ErrorErrorReasonUnspecified("%s", err)
Expand All @@ -124,6 +124,16 @@ func (g *Gebura) SyncAppInfos(
AppInfoID: *infoID,
IgnoreRateLimit: false,
})
appInfo := new(modelgebura.AppInfo)
appInfo.ID = ids[i]
appInfo.Internal = infoID.Internal
appInfo.Source = infoID.Source
appInfo.SourceAppID = infoID.SourceAppID
appInfo, err = g.repo.CreateAppInfoOrGet(ctx, appInfo)
if err != nil {
continue
}
appInfos = append(appInfos, appInfo)
}
}
return appInfos, nil
Expand Down
1 change: 1 addition & 0 deletions app/sephirah/internal/biz/bizgebura/gebura.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type ReportAppPackageHandler interface {

type GeburaRepo interface {
CreateAppInfo(context.Context, *modelgebura.AppInfo) error
CreateAppInfoOrGet(context.Context, *modelgebura.AppInfo) (*modelgebura.AppInfo, error)
UpdateAppInfo(context.Context, *modelgebura.AppInfo) error
ListAppInfos(context.Context, model.Paging, []string, []modelgebura.AppType,
[]model.InternalID, bool) ([]*modelgebura.AppInfo, int64, error)
Expand Down
19 changes: 19 additions & 0 deletions app/sephirah/internal/data/gebura.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ func (g geburaRepo) CreateAppInfo(ctx context.Context, a *modelgebura.AppInfo) e
return q.Exec(ctx)
}

func (g geburaRepo) CreateAppInfoOrGet(ctx context.Context, a *modelgebura.AppInfo) (*modelgebura.AppInfo, error) {
err := g.CreateAppInfo(ctx, a)
if err == nil {
return a, nil
}
if ent.IsConstraintError(err) {
var ai *ent.AppInfo
ai, err = g.data.db.AppInfo.Query().Where(
appinfo.InternalEQ(a.Internal),
appinfo.SourceEQ(a.Source),
appinfo.SourceAppIDEQ(a.SourceAppID),
).Only(ctx)
if err == nil {
return converter.ToBizAppInfo(ai), nil
}
}
return nil, err
}

func (g geburaRepo) UpdateAppInfo(ctx context.Context, a *modelgebura.AppInfo) error {
q := g.data.db.AppInfo.Update().
Where(
Expand Down

0 comments on commit 4f87179

Please sign in to comment.