Skip to content

Commit 3540400

Browse files
committed
feat: implement consecutive miss count query for status updates
1 parent fa49d84 commit 3540400

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/graphql/queries/member_queries.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,29 @@ impl StatusInfo {
165165
Ok(result)
166166
}
167167

168+
async fn consecutive_misses(&self, ctx: &Context<'_>) -> Result<Option<i64>> {
169+
let pool = ctx.data::<Arc<PgPool>>().expect("Pool must be in context.");
170+
171+
let result: Option<i64> = sqlx::query_scalar(
172+
"
173+
SELECT distance
174+
FROM (
175+
SELECT is_sent, ROW_NUMBER() OVER (ORDER BY date DESC) - 1 AS distance
176+
FROM StatusUpdateHistory
177+
WHERE member_id = $1
178+
)
179+
WHERE is_sent = TRUE
180+
ORDER BY distance ASC
181+
LIMIT 1;
182+
",
183+
)
184+
.bind(self.member_id)
185+
.fetch_optional(pool.as_ref())
186+
.await?;
187+
188+
Ok(result)
189+
}
190+
168191
async fn update_count(
169192
&self,
170193
ctx: &Context<'_>,

0 commit comments

Comments
 (0)