Aug 5 - Update code to follow up ST - MT14c
This commit is contained in:
@@ -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}>'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user