Skip to content

Commit

Permalink
Conversation: proposed changes
Browse files Browse the repository at this point in the history
Signed-off-by: mrizzi <[email protected]>
  • Loading branch information
mrizzi authored and chirino committed Jan 7, 2025
1 parent 4d48563 commit 44ade24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 7 additions & 3 deletions migration/src/m0000820_create_conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl MigrationTrait for Migration {
.create_index(
Index::create()
.table(Conversation::Table)
.name(Conversation::ConverstationUserIdUpdatedAtIdx.to_string())
.name(Indexes::ConversationUserIdUpdatedAtIdx.to_string())
.col(Conversation::UserId)
.col(Conversation::UpdatedAt)
.to_owned(),
Expand All @@ -52,7 +52,7 @@ impl MigrationTrait for Migration {
Index::drop()
.if_exists()
.table(Conversation::Table)
.name(Conversation::ConverstationUserIdUpdatedAtIdx.to_string())
.name(Indexes::ConversationUserIdUpdatedAtIdx.to_string())
.to_owned(),
)
.await?;
Expand All @@ -63,12 +63,16 @@ impl MigrationTrait for Migration {
}
}

#[derive(DeriveIden)]
enum Indexes {
ConversationUserIdUpdatedAtIdx,
}

#[derive(DeriveIden)]
enum Conversation {
Table,
Id,
UserId,
ConverstationUserIdUpdatedAtIdx,
State,
Seq,
Summary,
Expand Down
7 changes: 3 additions & 4 deletions modules/fundamental/src/ai/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ use std::sync::Arc;
use time::OffsetDateTime;
use tokio::sync::OnceCell;

use trustify_common::db::{limiter::LimiterTrait, query::Filtering};
use trustify_common::db::limiter::LimiterTrait;

use trustify_common::db::query::q;
use trustify_common::db::Database;
use trustify_common::model::{Paginated, PaginatedResults};
use trustify_entity::conversation;
Expand Down Expand Up @@ -343,7 +342,7 @@ impl AiService {
id: Uuid,
connection: &C,
) -> Result<Option<conversation::Model>, Error> {
let select = conversation::Entity::find().filter(conversation::Column::Id.eq(id));
let select = conversation::Entity::find_by_id(id);

Ok(select.one(connection).await?)
}
Expand All @@ -356,7 +355,7 @@ impl AiService {
) -> Result<PaginatedResults<conversation::Model>, Error> {
let limiter = conversation::Entity::find()
.order_by_desc(conversation::Column::UpdatedAt)
.filtering(q(format!("user_id={}", user_id).as_str()))?
.filter(conversation::Column::UserId.eq(user_id))
.limiting(connection, paginated.offset, paginated.limit);

let total = limiter.total().await?;
Expand Down

0 comments on commit 44ade24

Please sign in to comment.