MT: add session read warnings, partial index on removed_at
- Log tracing::warn on session read errors in MaybeUser extractor
instead of silently swallowing with .ok()
- Add partial index idx_posts_not_removed for soft-delete filtering
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2 files changed,
+17 insertions,
-2 deletions
|
1 |
+ |
-- Partial index for soft-deleted post filtering (WHERE removed_at IS NULL).
|
|
2 |
+ |
CREATE INDEX IF NOT EXISTS idx_posts_not_removed
|
|
3 |
+ |
ON posts(thread_id, created_at) WHERE removed_at IS NULL;
|
| 53 |
53 |
|
|
| 54 |
54 |
|
impl SessionUser {
|
| 55 |
55 |
|
async fn from_session(session: &Session) -> Option<Self> {
|
| 56 |
|
- |
let user_id: uuid::Uuid = session.get(SESSION_USER_ID).await.ok()??;
|
| 57 |
|
- |
let username: String = session.get(SESSION_USERNAME).await.ok()??;
|
|
56 |
+ |
let user_id: uuid::Uuid = match session.get(SESSION_USER_ID).await {
|
|
57 |
+ |
Ok(v) => v?,
|
|
58 |
+ |
Err(e) => {
|
|
59 |
+ |
tracing::warn!(error = %e, "failed to read user_id from session");
|
|
60 |
+ |
return None;
|
|
61 |
+ |
}
|
|
62 |
+ |
};
|
|
63 |
+ |
let username: String = match session.get(SESSION_USERNAME).await {
|
|
64 |
+ |
Ok(v) => v?,
|
|
65 |
+ |
Err(e) => {
|
|
66 |
+ |
tracing::warn!(error = %e, "failed to read username from session");
|
|
67 |
+ |
return None;
|
|
68 |
+ |
}
|
|
69 |
+ |
};
|
| 58 |
70 |
|
let display_name: Option<String> = session.get(SESSION_DISPLAY_NAME).await.ok().flatten();
|
| 59 |
71 |
|
Some(Self {
|
| 60 |
72 |
|
user_id,
|