Skip to content

Commit

Permalink
fix(db): should use update message
Browse files Browse the repository at this point in the history
  • Loading branch information
zwpaper committed Oct 31, 2024
1 parent 2c7de9f commit 640aeaa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
18 changes: 18 additions & 0 deletions ee/tabby-db/src/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,24 @@ impl DbConn {
Ok(())
}

pub async fn update_thread_message_content(
&self,
thread_id: i64,
message_id: i64,
content: &str,
) -> Result<()> {
query!(
"UPDATE thread_messages SET content = ?, updated_at = DATETIME('now') WHERE thread_id = ? AND id = ?",
content,
thread_id,
message_id
)
.execute(&self.pool)
.await?;

Check warning on line 236 in ee/tabby-db/src/threads.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/threads.rs#L223-L236

Added lines #L223 - L236 were not covered by tests

Ok(())
}

Check warning on line 239 in ee/tabby-db/src/threads.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/threads.rs#L238-L239

Added lines #L238 - L239 were not covered by tests

pub async fn append_thread_message_content(
&self,
message_id: i64,
Expand Down
5 changes: 0 additions & 5 deletions ee/tabby-schema/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,11 +1179,6 @@ impl Mutation {

user.policy.check_update_thread_message(&thread.user_id)?;

Check warning on line 1180 in ee/tabby-schema/src/schema/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-schema/src/schema/mod.rs#L1180

Added line #L1180 was not covered by tests

let message = svc.get_thread_message(&input.id).await?;
if input.content == message.content {
return Ok(true);
}

svc.update_thread_message(&input).await?;
Ok(true)
}

Check warning on line 1184 in ee/tabby-schema/src/schema/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-schema/src/schema/mod.rs#L1182-L1184

Added lines #L1182 - L1184 were not covered by tests
Expand Down
6 changes: 5 additions & 1 deletion ee/tabby-webserver/src/service/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ impl ThreadService for ThreadServiceImpl {

async fn update_thread_message(&self, input: &UpdateMessageInput) -> Result<()> {
self.db
.append_thread_message_content(input.id.as_rowid()?, &input.content)
.update_thread_message_content(
input.thread_id.as_rowid()?,
input.id.as_rowid()?,
&input.content,

Check warning on line 76 in ee/tabby-webserver/src/service/thread.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/thread.rs#L71-L76

Added lines #L71 - L76 were not covered by tests
)
.await?;
Ok(())
}

Check warning on line 80 in ee/tabby-webserver/src/service/thread.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/thread.rs#L78-L80

Added lines #L78 - L80 were not covered by tests
Expand Down

0 comments on commit 640aeaa

Please sign in to comment.