feat(backend): optimize recent sessions filtering

This commit is contained in:
pycook
2025-08-12 15:43:16 +08:00
parent b76519400e
commit ae4e8fb51f
4 changed files with 13 additions and 10 deletions

View File

@@ -194,6 +194,8 @@ func (r *sessionRepository) GetRecentSessionsByUser(ctx context.Context, uid int
Where("uid = ?", uid).
Where("asset_id > 0").
Where("account_id > 0").
Where("protocol NOT LIKE ?", "rdp%").
Where("protocol NOT LIKE ?", "vnc%").
Group("asset_id, account_id").
Find(&maxSessions).Error
@@ -214,6 +216,8 @@ func (r *sessionRepository) GetRecentSessionsByUser(ctx context.Context, uid int
// Get the full session records for those IDs
err = dbpkg.DB.Model(&model.Session{}).
Where("id IN ?", sessionIds).
Where("protocol NOT LIKE ?", "rdp%").
Where("protocol NOT LIKE ?", "vnc%").
Order("created_at DESC").
Limit(limit).
Find(&sessions).Error

View File

@@ -30,7 +30,7 @@ var (
// Protocol-specific colors (using primary palette)
SSHColor = PrimaryColor9 // Bright blue for SSH
MySQLColor = PrimaryColor // Deep blue for MySQL
RedisColor = lipgloss.Color("#DC382D") // Keep Redis brand red
RedisColor = lipgloss.Color("#9C27B0") // Purple for Redis
MongoDBColor = lipgloss.Color("#4DB33D") // Keep MongoDB brand green
PostgreSQLColor = PrimaryColor2 // Light blue for PostgreSQL
TelnetColor = PrimaryColor8 // Soft blue for Telnet

View File

@@ -13,7 +13,7 @@ func GetProtocolIcon(protocol string) string {
case "mysql":
return "◆"
case "redis":
return ""
return ""
case "mongodb":
return "◉"
case "postgresql":

View File

@@ -265,7 +265,7 @@ func (m *view) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
height = 24
}
// Get recent sessions
// Get recent sessions (filtered at database level)
sessions, err := m.getRecentSessions()
if err != nil {
return m, tea.Sequence(
@@ -744,7 +744,6 @@ func (m *view) magicn() tea.Msg {
}
func (m *view) getRecentSessions() ([]*model.Session, error) {
// Use repository to get recent sessions, deduplicated by asset_id and account_id
sessionRepo := repository.NewSessionRepository()
return sessionRepo.GetRecentSessionsByUser(m.gctx, m.currentUser.GetUid(), 20)
}