-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into rsc-tier-cache-dirs
- Loading branch information
Showing
11 changed files
with
271 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
rust/migration/src/m20240731_152842_create_job_size_proc.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use sea_orm_migration::prelude::*; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.get_connection() | ||
.execute_unprepared( | ||
" | ||
CREATE OR REPLACE PROCEDURE calculate_job_size( | ||
job_lim int, | ||
INOUT updated_count int | ||
) | ||
language plpgsql | ||
as $$ | ||
BEGIN | ||
-- Run the query that find the jobs, calcs their sizes, and then updates the table | ||
WITH | ||
eligible_jobs as ( | ||
SELECT id, stdout_blob_id, stderr_blob_id | ||
FROM job | ||
WHERE size IS NULL | ||
ORDER BY created_at | ||
ASC | ||
LIMIT job_lim | ||
), | ||
job_blob_size as ( | ||
SELECT ej.id, SUM(COALESCE(b.size,0)) as size | ||
FROM eligible_jobs ej | ||
LEFT JOIN output_file o | ||
ON ej.id = o.job_id | ||
LEFT JOIN blob b | ||
ON o.blob_id = b.id | ||
GROUP BY ej.id | ||
), | ||
full_size as ( | ||
SELECT | ||
ej.id, | ||
CAST(jb.size + stdout.size + stderr.size as BIGINT) as size | ||
FROM eligible_jobs ej | ||
INNER JOIN job_blob_size jb | ||
ON ej.id = jb.id | ||
INNER JOIN blob stdout | ||
ON ej.stdout_blob_id = stdout.id | ||
INNER JOIN blob stderr | ||
ON ej.stderr_blob_id = stderr.id | ||
) | ||
UPDATE job j | ||
SET size = f.size | ||
FROM full_size f | ||
WHERE j.id = f.id; | ||
-- Grab the rows affected count | ||
GET DIAGNOSTICS updated_count = ROW_COUNT; | ||
END; | ||
$$; | ||
", | ||
) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.get_connection() | ||
.execute_unprepared("DROP PROCEDURE IF EXISTS calculate_job_size(int, int)") | ||
.await?; | ||
Ok(()) | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
rust/migration/src/m20240731_201632_create_job_blob_timestamp_index.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use sea_orm_migration::prelude::*; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.get_connection() | ||
.execute_unprepared( | ||
" | ||
CREATE INDEX IF NOT EXISTS blob_updated_at_idx | ||
ON blob(updated_at) | ||
", | ||
) | ||
.await?; | ||
|
||
manager | ||
.get_connection() | ||
.execute_unprepared( | ||
" | ||
CREATE INDEX IF NOT EXISTS job_created_at_idx | ||
ON job(created_at) | ||
", | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.get_connection() | ||
.execute_unprepared( | ||
" | ||
DROP INDEX IF EXISTS job_created_at_idx | ||
", | ||
) | ||
.await?; | ||
|
||
manager | ||
.get_connection() | ||
.execute_unprepared( | ||
" | ||
DROP INDEX IF EXISTS blob_updated_at_idx | ||
", | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.