Skip to content

Commit c697b6b

Browse files
authored
Merge branch 'rust-lang:master' into categorize-errors
2 parents 749e846 + 054b69f commit c697b6b

28 files changed

+428
-283
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ jobs:
2727
steps:
2828
- uses: actions/checkout@v4
2929

30-
- name: update rust toolchain
31-
run: |
32-
rustup override set stable
33-
rustup update stable
34-
3530
- name: install `just`
3631
run: sudo snap install --edge --classic just
3732

@@ -76,11 +71,6 @@ jobs:
7671
steps:
7772
- uses: actions/checkout@v4
7873

79-
- name: update rust toolchain
80-
run: |
81-
rustup override set stable
82-
rustup update stable
83-
8474
- name: restore build & cargo cache
8575
uses: Swatinem/rust-cache@v2
8676
with:
@@ -117,11 +107,6 @@ jobs:
117107
steps:
118108
- uses: actions/checkout@v4
119109

120-
- name: update rust toolchain
121-
run: |
122-
rustup override set stable
123-
rustup update stable
124-
125110
- name: restore build & cargo cache
126111
uses: Swatinem/rust-cache@v2
127112
with:
@@ -150,10 +135,7 @@ jobs:
150135
steps:
151136
- uses: actions/checkout@v4
152137
- name: update rust toolchain
153-
run: |
154-
rustup override set stable
155-
rustup update stable
156-
rustup component add rustfmt
138+
run: rustup component add rustfmt
157139

158140
- run: cargo fmt -- --check
159141

@@ -165,10 +147,7 @@ jobs:
165147
- uses: actions/checkout@v4
166148

167149
- name: update rust toolchain
168-
run: |
169-
rustup override set stable
170-
rustup update stable
171-
rustup component add clippy
150+
run: rustup component add clippy
172151

173152
- name: install `just`
174153
run: sudo snap install --edge --classic just

.sqlx/query-3bdc47a7b7457e290e2c63f9c22742d17a52940631caa0688d3c8b5e2c3765c8.json renamed to .sqlx/query-2fd2aad681960b30ca5149dfc7050c477667d5f022349661385026c757df88cc.json

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-f0239a895d0ef72aff8d99f77a35656d2642564a6a3c40d742fc1b62d1c80d59.json renamed to .sqlx/query-ce9cf294c964be76b19585a35c37f4b3643b09cfea98ed8ba13e4dadb5b5e48c.json

Lines changed: 4 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.lock

Lines changed: 24 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ derive_more = { version = "2.0.0", features = ["display"] }
6464

6565
# Async
6666
tokio = { version = "1.0", features = ["rt-multi-thread", "signal", "macros"] }
67+
tokio-util = { version = "0.7.15", default-features = false, features = ["io"] }
6768
futures-util = "0.3.5"
6869
async-stream = "0.3.5"
70+
async-compression = { version = "0.4.25", features = ["tokio", "bzip2", "zstd", "gzip"] }
6971
aws-config = "1.0.0"
7072
aws-sdk-s3 = "1.3.0"
7173
aws-sdk-cloudfront = "1.3.0"

dockerfiles/Dockerfile-gui-tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ RUN mkdir out
7474
# https://github.com/puppeteer/puppeteer/issues/375
7575
#
7676
# We also specify the version in case we need to update it to go around cache limitations.
77-
RUN npm install -g browser-ui-test@0.20.5 --unsafe-perm=true
77+
RUN npm install -g browser-ui-test@0.21.0 --unsafe-perm=true
7878

7979
EXPOSE 3000
8080

src/storage/database.rs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use super::{Blob, FileRange};
1+
use super::{Blob, FileRange, StreamingBlob};
22
use crate::{InstanceMetrics, db::Pool, error::Result};
33
use chrono::{DateTime, Utc};
44
use futures_util::stream::{Stream, TryStreamExt};
55
use sqlx::Acquire;
6-
use std::sync::Arc;
6+
use std::{io, sync::Arc};
77

88
pub(crate) struct DatabaseBackend {
99
pool: Pool,
@@ -58,38 +58,27 @@ impl DatabaseBackend {
5858
}
5959
}
6060

61-
pub(super) async fn get(
61+
pub(super) async fn get_stream(
6262
&self,
6363
path: &str,
64-
max_size: usize,
6564
range: Option<FileRange>,
66-
) -> Result<Blob> {
67-
// The maximum size for a BYTEA (the type used for `content`) is 1GB, so this cast is safe:
68-
// https://www.postgresql.org/message-id/162867790712200946i7ba8eb92v908ac595c0c35aee%40mail.gmail.com
69-
let max_size = max_size.min(i32::MAX as usize) as i32;
70-
65+
) -> Result<StreamingBlob> {
7166
struct Result {
7267
path: String,
7368
mime: String,
7469
date_updated: DateTime<Utc>,
7570
compression: Option<i32>,
7671
content: Option<Vec<u8>>,
77-
is_too_big: bool,
7872
}
7973

8074
let result = if let Some(r) = range {
81-
// when we only want to get a range we can validate already if the range is small enough
82-
if (r.end() - r.start() + 1) > max_size as u64 {
83-
return Err(std::io::Error::other(crate::error::SizeLimitReached).into());
84-
}
8575
let range_start = i32::try_from(*r.start())?;
8676

8777
sqlx::query_as!(
8878
Result,
8979
r#"SELECT
9080
path, mime, date_updated, compression,
91-
substring(content from $2 for $3) as content,
92-
FALSE as "is_too_big!"
81+
substring(content from $2 for $3) as content
9382
FROM files
9483
WHERE path = $1;"#,
9584
path,
@@ -105,35 +94,35 @@ impl DatabaseBackend {
10594
sqlx::query_as!(
10695
Result,
10796
r#"SELECT
108-
path, mime, date_updated, compression,
109-
(CASE WHEN LENGTH(content) <= $2 THEN content ELSE NULL END) AS content,
110-
(LENGTH(content) > $2) AS "is_too_big!"
97+
path,
98+
mime,
99+
date_updated,
100+
compression,
101+
content
111102
FROM files
112103
WHERE path = $1;"#,
113104
path,
114-
max_size,
115105
)
116106
.fetch_optional(&self.pool)
117107
.await?
118108
.ok_or(super::PathNotFoundError)?
119109
};
120110

121-
if result.is_too_big {
122-
return Err(std::io::Error::other(crate::error::SizeLimitReached).into());
123-
}
124-
125111
let compression = result.compression.map(|i| {
126112
i.try_into()
127113
.expect("invalid compression algorithm stored in database")
128114
});
129-
Ok(Blob {
115+
let content = result.content.unwrap_or_default();
116+
let content_len = content.len();
117+
Ok(StreamingBlob {
130118
path: result.path,
131119
mime: result
132120
.mime
133121
.parse()
134122
.unwrap_or(mime::APPLICATION_OCTET_STREAM),
135123
date_updated: result.date_updated,
136-
content: result.content.unwrap_or_default(),
124+
content: Box::new(io::Cursor::new(content)),
125+
content_length: content_len,
137126
compression,
138127
})
139128
}

0 commit comments

Comments
 (0)