Skip to content

Commit 98827a6

Browse files
committed
feat: update source_id to i64
1 parent ca98800 commit 98827a6

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

init_db.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CREATE EXTENSION vector;
66

77
CREATE TABLE issues (
88
id SERIAL PRIMARY KEY,
9-
source_id VARCHAR NOT NULL UNIQUE,
9+
source_id BIGINT NOT NULL UNIQUE,
1010
source VARCHAR NOT NULL,
1111
title TEXT NOT NULL,
1212
body TEXT NOT NULL,
@@ -22,7 +22,7 @@ CREATE TABLE issues (
2222

2323
CREATE TABLE comments (
2424
id SERIAL PRIMARY KEY,
25-
source_id VARCHAR NOT NULL UNIQUE,
25+
source_id BIGINT NOT NULL UNIQUE,
2626
issue_id INT NOT NULL REFERENCES issues(id) ON DELETE CASCADE,
2727
body TEXT NOT NULL,
2828
url VARCHAR NOT NULL,

issue-bot/src/main.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ async fn start_main_server(config: ServerConfig, state: AppState) -> anyhow::Res
178178
}
179179

180180
struct IssueData {
181-
source_id: String,
181+
source_id: i64,
182182
action: Action,
183183
title: String,
184184
body: String,
@@ -191,9 +191,9 @@ struct IssueData {
191191
}
192192

193193
struct CommentData {
194-
source_id: String,
194+
source_id: i64,
195195
action: Action,
196-
issue_id: String,
196+
issue_id: i64,
197197
body: String,
198198
url: String,
199199
}
@@ -402,7 +402,7 @@ async fn handle_webhooks(
402402
r#"insert into issues (source_id, source, title, body, is_pull_request, number, html_url, url, repository_full_name, embedding)
403403
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)"#
404404
)
405-
.bind(&issue.source_id)
405+
.bind(issue.source_id)
406406
.bind(issue.source.to_string())
407407
.bind(issue.title)
408408
.bind(issue.body)
@@ -612,7 +612,7 @@ async fn handle_webhooks(
612612
Vector::from(raw_embedding);
613613
let issue_id: Option<i32> = match sqlx::query_scalar!(
614614
"select id from issues where source_id = $1",
615-
issue.id.to_string()
615+
issue.id
616616
)
617617
.fetch_optional(&pool)
618618
.await {
@@ -630,7 +630,7 @@ async fn handle_webhooks(
630630
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
631631
returning id"#
632632
)
633-
.bind(issue.id.to_string())
633+
.bind(issue.id)
634634
.bind(source)
635635
.bind(issue.title)
636636
.bind(issue.body)
@@ -751,7 +751,7 @@ async fn handle_webhooks(
751751
let embedding = Vector::from(raw_embedding);
752752
let issue_id: Option<i32> = match sqlx::query_scalar!(
753753
"select id from issues where source_id = $1",
754-
issue.id.to_string()
754+
issue.id
755755
)
756756
.fetch_optional(&pool)
757757
.await
@@ -774,7 +774,7 @@ async fn handle_webhooks(
774774
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
775775
returning id"#
776776
)
777-
.bind(issue.id.to_string())
777+
.bind(issue.id)
778778
.bind(source)
779779
.bind(issue.title)
780780
.bind(issue.body)
@@ -868,7 +868,7 @@ async fn handle_webhooks(
868868
info!("regenerating embeddings for {} issues", total_issues);
869869
for (current_issue_nb, issue) in issues.into_iter().enumerate() {
870870
if let Err(err) =
871-
update_issue_embeddings(&embedding_api, &pool, &issue.source_id)
871+
update_issue_embeddings(&embedding_api, &pool, issue.source_id)
872872
.await
873873
{
874874
error!(
@@ -927,7 +927,7 @@ async fn handle_webhooks(
927927
};
928928

929929
if let Some(issue_id) = issue_id {
930-
if let Err(err) = update_issue_embeddings(&embedding_api, &pool, &issue_id).await {
930+
if let Err(err) = update_issue_embeddings(&embedding_api, &pool, issue_id).await {
931931
error!(
932932
issue_id = issue_id,
933933
err = err.to_string(),
@@ -941,15 +941,15 @@ async fn handle_webhooks(
941941
async fn update_issue_embeddings(
942942
embedding_api: &EmbeddingApi,
943943
pool: &Pool<Postgres>,
944-
issue_id: &str,
944+
issue_id: i64,
945945
) -> anyhow::Result<()> {
946946
let issue = sqlx::query!(
947947
r#"
948948
SELECT
949949
i.title,
950950
i.body,
951951
(
952-
SELECT JSON_AGG(c.body)
952+
SELECT JSON_AGG(c.body ORDER BY c.source_id)
953953
FROM comments AS c
954954
WHERE c.issue_id = i.id
955955
) AS comments

issue-bot/src/routes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub async fn github_webhook(
170170
state
171171
.tx
172172
.send(EventData::Issue(crate::IssueData {
173-
source_id: issue.issue.id.to_string(),
173+
source_id: issue.issue.id,
174174
action: issue.action.to_action(),
175175
title: issue.issue.title,
176176
body: issue.issue.body,
@@ -191,8 +191,8 @@ pub async fn github_webhook(
191191
state
192192
.tx
193193
.send(EventData::Comment(crate::CommentData {
194-
source_id: comment.comment.id.to_string(),
195-
issue_id: comment.issue.id.to_string(),
194+
source_id: comment.comment.id,
195+
issue_id: comment.issue.id,
196196
action: comment.action.to_action(),
197197
body: comment.comment.body,
198198
url: comment.comment.url,
@@ -293,7 +293,7 @@ struct Url {
293293
#[derive(Debug, Deserialize)]
294294
#[serde(rename_all = "camelCase")]
295295
struct Discussion {
296-
id: String,
296+
id: i64,
297297
is_pull_request: bool,
298298
num: i32,
299299
title: String,
@@ -313,7 +313,7 @@ struct Author {
313313
#[derive(Debug, Deserialize)]
314314
#[serde(rename_all = "camelCase")]
315315
struct HfComment {
316-
id: String,
316+
id: i64,
317317
#[serde(default)]
318318
content: String,
319319
author: Author,

0 commit comments

Comments
 (0)