mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 11:47:36 +08:00
Merge pull request #995 from GLYASAI/sort-events
Bug Fix: sort by ID desc
This commit is contained in:
commit
741263b958
@ -131,7 +131,7 @@ func (c *EventDaoImpl) GetEventsByTarget(target, targetID string, offset, limit
|
|||||||
if err := db.Model(&model.ServiceEvent{}).Count(&total).Error; err != nil {
|
if err := db.Model(&model.ServiceEvent{}).Count(&total).Error; err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
if err := db.Offset(offset).Limit(limit).Order("create_time DESC").Find(&result).Error; err != nil {
|
if err := db.Offset(offset).Limit(limit).Order("create_time DESC, ID DESC").Find(&result).Error; err != nil {
|
||||||
if err == gorm.ErrRecordNotFound {
|
if err == gorm.ErrRecordNotFound {
|
||||||
return result, 0, nil
|
return result, 0, nil
|
||||||
}
|
}
|
||||||
@ -143,20 +143,17 @@ func (c *EventDaoImpl) GetEventsByTarget(target, targetID string, offset, limit
|
|||||||
|
|
||||||
// GetEventsByTenantID get event by tenantID
|
// GetEventsByTenantID get event by tenantID
|
||||||
func (c *EventDaoImpl) GetEventsByTenantID(tenantID string, offset, limit int) ([]*model.ServiceEvent, int, error) {
|
func (c *EventDaoImpl) GetEventsByTenantID(tenantID string, offset, limit int) ([]*model.ServiceEvent, int, error) {
|
||||||
var result []*model.ServiceEvent
|
|
||||||
var total int
|
var total int
|
||||||
start := time.Now()
|
|
||||||
if err := c.DB.Model(&model.ServiceEvent{}).Where("tenant_id=?", tenantID).Count(&total).Error; err != nil {
|
if err := c.DB.Model(&model.ServiceEvent{}).Where("tenant_id=?", tenantID).Count(&total).Error; err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
logrus.Debugf("query event count %d take time %s", total, time.Now().Sub(start))
|
var result []*model.ServiceEvent
|
||||||
if err := c.DB.Where("tenant_id=?", tenantID).Offset(offset).Limit(limit).Order("start_time DESC").Find(&result).Error; err != nil {
|
if err := c.DB.Where("tenant_id=?", tenantID).Offset(offset).Limit(limit).Order("start_time DESC, ID DESC").Find(&result).Error; err != nil {
|
||||||
if err == gorm.ErrRecordNotFound {
|
if err == gorm.ErrRecordNotFound {
|
||||||
return result, 0, nil
|
return result, 0, nil
|
||||||
}
|
}
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
logrus.Debugf("query event list take time %s", time.Now().Sub(start))
|
|
||||||
return result, total, nil
|
return result, total, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user