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("uid = ?", uid).
|
||||||
Where("asset_id > 0").
|
Where("asset_id > 0").
|
||||||
Where("account_id > 0").
|
Where("account_id > 0").
|
||||||
|
Where("protocol NOT LIKE ?", "rdp%").
|
||||||
|
Where("protocol NOT LIKE ?", "vnc%").
|
||||||
Group("asset_id, account_id").
|
Group("asset_id, account_id").
|
||||||
Find(&maxSessions).Error
|
Find(&maxSessions).Error
|
||||||
|
|
||||||
@@ -214,6 +216,8 @@ func (r *sessionRepository) GetRecentSessionsByUser(ctx context.Context, uid int
|
|||||||
// Get the full session records for those IDs
|
// Get the full session records for those IDs
|
||||||
err = dbpkg.DB.Model(&model.Session{}).
|
err = dbpkg.DB.Model(&model.Session{}).
|
||||||
Where("id IN ?", sessionIds).
|
Where("id IN ?", sessionIds).
|
||||||
|
Where("protocol NOT LIKE ?", "rdp%").
|
||||||
|
Where("protocol NOT LIKE ?", "vnc%").
|
||||||
Order("created_at DESC").
|
Order("created_at DESC").
|
||||||
Limit(limit).
|
Limit(limit).
|
||||||
Find(&sessions).Error
|
Find(&sessions).Error
|
||||||
|
@@ -30,7 +30,7 @@ var (
|
|||||||
// Protocol-specific colors (using primary palette)
|
// Protocol-specific colors (using primary palette)
|
||||||
SSHColor = PrimaryColor9 // Bright blue for SSH
|
SSHColor = PrimaryColor9 // Bright blue for SSH
|
||||||
MySQLColor = PrimaryColor // Deep blue for MySQL
|
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
|
MongoDBColor = lipgloss.Color("#4DB33D") // Keep MongoDB brand green
|
||||||
PostgreSQLColor = PrimaryColor2 // Light blue for PostgreSQL
|
PostgreSQLColor = PrimaryColor2 // Light blue for PostgreSQL
|
||||||
TelnetColor = PrimaryColor8 // Soft blue for Telnet
|
TelnetColor = PrimaryColor8 // Soft blue for Telnet
|
||||||
|
@@ -13,7 +13,7 @@ func GetProtocolIcon(protocol string) string {
|
|||||||
case "mysql":
|
case "mysql":
|
||||||
return "◆"
|
return "◆"
|
||||||
case "redis":
|
case "redis":
|
||||||
return "⚡"
|
return "●"
|
||||||
case "mongodb":
|
case "mongodb":
|
||||||
return "◉"
|
return "◉"
|
||||||
case "postgresql":
|
case "postgresql":
|
||||||
|
@@ -265,7 +265,7 @@ func (m *view) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
height = 24
|
height = 24
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get recent sessions
|
// Get recent sessions (filtered at database level)
|
||||||
sessions, err := m.getRecentSessions()
|
sessions, err := m.getRecentSessions()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return m, tea.Sequence(
|
return m, tea.Sequence(
|
||||||
@@ -744,7 +744,6 @@ func (m *view) magicn() tea.Msg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *view) getRecentSessions() ([]*model.Session, error) {
|
func (m *view) getRecentSessions() ([]*model.Session, error) {
|
||||||
// Use repository to get recent sessions, deduplicated by asset_id and account_id
|
|
||||||
sessionRepo := repository.NewSessionRepository()
|
sessionRepo := repository.NewSessionRepository()
|
||||||
return sessionRepo.GetRecentSessionsByUser(m.gctx, m.currentUser.GetUid(), 20)
|
return sessionRepo.GetRecentSessionsByUser(m.gctx, m.currentUser.GetUid(), 20)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user