Skip to main content

max / makenotwork

Fix scheduler SQL errors, add robots.txt - integrity: use current_period_end instead of non-existent updated_at column on creator_subscriptions for stale subscription detection - cleanup: rewrite correlated subquery as LEFT JOIN LATERAL to fix ungrouped column error in storage size calculation - Add /robots.txt route disallowing /api/, /admin/, /settings/ Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author: Max J. <87768334+MaxJMath@users.noreply.github.com> · 2026-05-10 02:17 UTC
Commit: 4294dcc098284d92e3930f0eccbb64bfb76c58ae
Parent: 3288086
3 files changed, +16 insertions, -15 deletions
@@ -405,21 +405,16 @@ pub async fn get_expired_deleted_item_storage_by_user(pool: &PgPool) -> Result<V
405 405 COALESCE(SUM(
406 406 COALESCE(i.audio_file_size_bytes, 0) +
407 407 COALESCE(i.cover_file_size_bytes, 0) +
408 - COALESCE(i.video_file_size_bytes, 0)
409 - ), 0)::BIGINT +
410 - COALESCE((
411 - SELECT SUM(v.file_size_bytes)::BIGINT
412 - FROM versions v
413 - WHERE v.item_id = ANY(ARRAY(
414 - SELECT i2.id FROM items i2
415 - WHERE i2.project_id = p.id
416 - AND i2.deleted_at IS NOT NULL
417 - AND i2.deleted_at < NOW() - INTERVAL '7 days'
418 - ))
419 - AND v.file_size_bytes IS NOT NULL
420 - ), 0) AS total_bytes
408 + COALESCE(i.video_file_size_bytes, 0) +
409 + COALESCE(ver.version_bytes, 0)
410 + ), 0)::BIGINT AS total_bytes
421 411 FROM items i
422 412 JOIN projects p ON i.project_id = p.id
413 + LEFT JOIN LATERAL (
414 + SELECT COALESCE(SUM(v.file_size_bytes), 0)::BIGINT AS version_bytes
415 + FROM versions v
416 + WHERE v.item_id = i.id AND v.file_size_bytes IS NOT NULL
417 + ) ver ON true
423 418 WHERE i.deleted_at IS NOT NULL AND i.deleted_at < NOW() - INTERVAL '7 days'
424 419 GROUP BY p.user_id
425 420 "#,
@@ -139,6 +139,12 @@ pub fn build_app(
139 139 .merge(build_routes())
140 140 .merge(routes::embed::embed_routes())
141 141 .route("/api/openapi.json", axum::routing::get(openapi::openapi_json))
142 + .route("/robots.txt", axum::routing::get(|| async {
143 + axum::response::Response::builder()
144 + .header("content-type", "text/plain")
145 + .body(axum::body::Body::from("User-agent: *\nDisallow: /api/\nDisallow: /admin/\nDisallow: /settings/\n"))
146 + .unwrap()
147 + }))
142 148 .nest_service(
143 149 "/static",
144 150 tower::ServiceBuilder::new()
@@ -96,9 +96,9 @@ pub(super) async fn check_stale_subscriptions(state: &AppState) {
96 96 let count: i64 = match sqlx::query_scalar(
97 97 r#"
98 98 SELECT COUNT(*) FROM (
99 - SELECT 1 FROM creator_subscriptions WHERE status = 'past_due' AND updated_at < NOW() - INTERVAL '7 days'
99 + SELECT 1 FROM creator_subscriptions WHERE status = 'past_due' AND current_period_end < NOW() - INTERVAL '7 days'
100 100 UNION ALL
101 - SELECT 1 FROM subscriptions WHERE status = 'past_due' AND updated_at < NOW() - INTERVAL '7 days'
101 + SELECT 1 FROM subscriptions WHERE status = 'past_due' AND current_period_end < NOW() - INTERVAL '7 days'
102 102 ) stale
103 103 "#,
104 104 )