d4x1 commented on code in PR #6628:
URL:
https://github.com/apache/incubator-devlake/pull/6628#discussion_r1426697473
##########
backend/helpers/srvhelper/scope_service_helper.go:
##########
@@ -93,6 +93,44 @@ func (scopeSrv *ScopeSrvHelper[C, S, SC])
GetScopeDetail(includeBlueprints bool,
return scopeDetail, nil
}
+func (scopeSrv *ScopeSrvHelper[C, S, SC]) GetScopeLatestSyncState(pkv
...interface{}) ([]*models.LatestSyncState, errors.Error) {
+ scope, err := scopeSrv.ModelSrvHelper.FindByPk(pkv...)
+ if err != nil {
+ return nil, err
+ }
+ s := *scope
+ params := plugin.MarshalScopeParams(s.ScopeParams())
+ scopeSrv.log.Debug("scope: %#+v, params: %+v", s, params)
+ rows, err := scopeSrv.db.Cursor(
+ dal.Select("raw_data_table, MAX(latest_success_start) as
latest_success_start"),
+ dal.From("_devlake_collector_latest_state"),
+ dal.Where("raw_data_params = ?", params),
+ dal.Groupby("raw_data_table"),
+ )
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ scopeSyncStates := []*models.LatestSyncState{}
Review Comment:
> Seems like we are returning the whole list anyway, I suggest that we use
the `All` method instead of using `Cursor` to make it simpler and readable
Got it. I'll fix it later.
##########
backend/helpers/srvhelper/scope_service_helper.go:
##########
@@ -93,6 +93,44 @@ func (scopeSrv *ScopeSrvHelper[C, S, SC])
GetScopeDetail(includeBlueprints bool,
return scopeDetail, nil
}
+func (scopeSrv *ScopeSrvHelper[C, S, SC]) GetScopeLatestSyncState(pkv
...interface{}) ([]*models.LatestSyncState, errors.Error) {
+ scope, err := scopeSrv.ModelSrvHelper.FindByPk(pkv...)
+ if err != nil {
+ return nil, err
+ }
+ s := *scope
+ params := plugin.MarshalScopeParams(s.ScopeParams())
+ scopeSrv.log.Debug("scope: %#+v, params: %+v", s, params)
+ rows, err := scopeSrv.db.Cursor(
+ dal.Select("raw_data_table, MAX(latest_success_start) as
latest_success_start"),
Review Comment:
> I don't think group by `raw_data_table` and take the max of
`latest_success_start` is needed because `raw_data_table`s are unique when
`raw_data_params` is specified. I think simply select the needed field would be
sufficient.
Got it. I'll fix it later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]