add log position tracking
This commit is contained in:
@@ -26,3 +26,21 @@ func (r *StateHistoryRepository) GetAll(ctx context.Context, filter *model.State
|
||||
func (r *StateHistoryRepository) Insert(ctx context.Context, model *model.StateHistory) error {
|
||||
return r.BaseRepository.Insert(ctx, model)
|
||||
}
|
||||
|
||||
// GetLastSessionID gets the last session ID for a server
|
||||
func (r *StateHistoryRepository) GetLastSessionID(ctx context.Context, serverID uint) (uint, error) {
|
||||
var lastSession model.StateHistory
|
||||
result := r.BaseRepository.db.WithContext(ctx).
|
||||
Where("server_id = ?", serverID).
|
||||
Order("session_id DESC").
|
||||
First(&lastSession)
|
||||
|
||||
if result.Error != nil {
|
||||
if result.Error == gorm.ErrRecordNotFound {
|
||||
return 0, nil // Return 0 if no sessions found
|
||||
}
|
||||
return 0, result.Error
|
||||
}
|
||||
|
||||
return lastSession.SessionID, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user