mirror of
https://github.com/veops/oneterm.git
synced 2025-09-27 03:36:02 +08:00
feat(backend): optimize recent sessions filtering
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -13,7 +13,7 @@ func GetProtocolIcon(protocol string) string {
|
||||
case "mysql":
|
||||
return "◆"
|
||||
case "redis":
|
||||
return "⚡"
|
||||
return "●"
|
||||
case "mongodb":
|
||||
return "◉"
|
||||
case "postgresql":
|
||||
|
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user