Add LastMessageAt field to conversation
Replaced `LatestConversationMessages` with `LoadConversationList`, which utilizes `LastMessageAt` for much faster conversation loading in the conversation listing TUI and `lmcli list` command.
This commit is contained in:
@@ -20,9 +20,9 @@ func ListCmd(ctx *lmcli.Context) *cobra.Command {
|
||||
Short: "List conversations",
|
||||
Long: `List conversations in order of recent activity`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
messages, err := ctx.Conversations.LatestConversationMessages()
|
||||
list, err := ctx.Conversations.LoadConversationList()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not fetch conversations: %v", err)
|
||||
return fmt.Errorf("Could not load conversations: %v", err)
|
||||
}
|
||||
|
||||
type Category struct {
|
||||
@@ -57,12 +57,12 @@ func ListCmd(ctx *lmcli.Context) *cobra.Command {
|
||||
|
||||
all, _ := cmd.Flags().GetBool("all")
|
||||
|
||||
for _, message := range messages {
|
||||
messageAge := now.Sub(message.CreatedAt)
|
||||
for _, item := range list.Items {
|
||||
age := now.Sub(item.LastMessageAt)
|
||||
|
||||
var category string
|
||||
for _, c := range categories {
|
||||
if messageAge < c.cutoff {
|
||||
if age < c.cutoff {
|
||||
category = c.name
|
||||
break
|
||||
}
|
||||
@@ -70,14 +70,14 @@ func ListCmd(ctx *lmcli.Context) *cobra.Command {
|
||||
|
||||
formatted := fmt.Sprintf(
|
||||
"%s - %s - %s",
|
||||
message.Conversation.ShortName.String,
|
||||
util.HumanTimeElapsedSince(messageAge),
|
||||
message.Conversation.Title,
|
||||
item.ShortName,
|
||||
util.HumanTimeElapsedSince(age),
|
||||
item.Title,
|
||||
)
|
||||
|
||||
categorized[category] = append(
|
||||
categorized[category],
|
||||
ConversationLine{messageAge, formatted},
|
||||
ConversationLine{age, formatted},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func ListCmd(ctx *lmcli.Context) *cobra.Command {
|
||||
fmt.Printf("%s:\n", category.name)
|
||||
for _, conv := range conversationLines {
|
||||
if conversationsPrinted >= count && !all {
|
||||
fmt.Printf("%d remaining conversation(s), use --all to view.\n", len(messages)-conversationsPrinted)
|
||||
fmt.Printf("%d remaining conversation(s), use --all to view.\n", list.Total-conversationsPrinted)
|
||||
break outer
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user