Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions crates/ingest-consumer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use lifecycle::{
shutdown::Shutdown,
};
use moderation::{Moderator, ModeratorConfig};
use serde_json::json;
use tokio::time::timeout;
use tokio_util::sync::CancellationToken;
use tracing::{error, info, info_span, warn};
Expand Down Expand Up @@ -424,7 +423,7 @@ async fn consume_labels(
// Only the version of a record that is currently indexed is
// moderated. Older versions are skipped, since a later message
// covers the newer one.
let inference = match collection.as_deref() {
let verdict = match collection.as_deref() {
Some(RouteRecord::NSID) => {
let Some(route) = fetch_route_moderation_view(pool, &uri)
.await?
Expand All @@ -434,14 +433,11 @@ async fn consume_labels(
return Ok(());
};
moderator
.infer_labels(
"route",
json!({
"name": route.name,
"description": route.description,
"tags": route.tags,
}),
)
.moderate(&moderation::Subject::Route {
name: route.name,
description: route.description,
tags: route.tags,
})
.await?
}
Some(ReviewRecord::NSID) => {
Expand All @@ -460,7 +456,7 @@ async fn consume_labels(
return Ok(());
};
moderator
.infer_labels("review", json!({ "text": body }))
.moderate(&moderation::Subject::Review { text: body })
.await?
}
Some(ProfileRecord::NSID) => {
Expand All @@ -472,7 +468,10 @@ async fn consume_labels(
return Ok(());
};
moderator
.infer_labels("profile", json!({ "name": user.name, "bio": user.bio }))
.moderate(&moderation::Subject::Profile {
name: user.name,
bio: user.bio,
})
.await?
}
_ => {
Expand All @@ -481,17 +480,18 @@ async fn consume_labels(
}
};

if inference.labels.is_empty() {
let labels = verdict.vals();
if labels.is_empty() {
info!(uri, cid, "no labels applied");
return Ok(());
}

let labels = NewLabels {
uri,
cid,
vals: inference.labels.iter().map(ToString::to_string).collect(),
vals: labels.iter().map(ToString::to_string).collect(),
cts: Timestamp::now(),
source: inference.source.as_str().to_owned(),
source: verdict.source.as_str().to_owned(),
};
database::labels::insert_labels(pool, &labels).await?;
info!(uri = labels.uri, cid = labels.cid, vals = ?labels.vals, "labels applied");
Expand Down
187 changes: 0 additions & 187 deletions crates/moderation/src/fast_path.rs

This file was deleted.

Loading
Loading