Aug 5 - Update code to follow up ST - MT14c

This commit is contained in:
2026-08-05 10:02:12 -04:00
parent be5484e1fb
commit 9bd6b364b7
6 changed files with 667 additions and 5 deletions
+23
View File
@@ -18,6 +18,29 @@ class SupportChatSession(db.Model):
order_by='SupportChatMessage.created_at',
)
@property
def message_count(self):
"""Number of turns in this session.
`messages` is a plain list relationship here (ST's is lazy='dynamic'),
so this is len() rather than .count(). It is already loaded whenever the
session is, so this costs no extra query.
"""
return len(self.messages)
@property
def preview(self):
"""First user message, for list views.
Scans the loaded list instead of ST's .filter_by(role='user').first(),
for the same reason. `messages` is ordered by created_at, so the first
match is the opening question.
"""
for m in self.messages:
if m.role == 'user':
return m.content
return '(no messages)'
def __repr__(self):
return f'<SupportChatSession {self.id}>'