@@ -179,119 +179,119 @@ impl Build {
179179 identifier : & str ,
180180 ) -> Option < ( Self , Self , super :: version:: MinifiedVersion ) > {
181181 cache. cached ( & format ! ( "build::{identifier}" ) , 3600 , || async {
182- let hash: Option < & str > = match identifier. len ( ) {
183- 32 => Some ( "md5" ) ,
184- 40 => Some ( "sha1" ) ,
185- 56 => Some ( "sha224" ) ,
186- 64 => Some ( "sha256" ) ,
187- 96 => Some ( "sha384" ) ,
188- 128 => Some ( "sha512" ) ,
189- _ => {
190- if let Ok ( id) = identifier. parse :: < i32 > ( ) {
191- if id < 1 {
192- return None ;
182+ let hash: Option < & str > = match identifier. len ( ) {
183+ 32 => Some ( "md5" ) ,
184+ 40 => Some ( "sha1" ) ,
185+ 56 => Some ( "sha224" ) ,
186+ 64 => Some ( "sha256" ) ,
187+ 96 => Some ( "sha384" ) ,
188+ 128 => Some ( "sha512" ) ,
189+ _ => {
190+ if let Ok ( id) = identifier. parse :: < i32 > ( ) {
191+ if id < 1 {
192+ return None ;
193+ } else {
194+ None
195+ }
193196 } else {
194- None
197+ return None ;
195198 }
196- } else {
197- return None ;
198199 }
199- }
200- } ;
200+ } ;
201201
202- let query = sqlx:: query ( & format ! (
203- r#"
204- WITH spec_build AS (
205- SELECT {}
206- FROM {}
207- LIMIT 1
208- ),
202+ let query = sqlx:: query ( & format ! (
203+ r#"
204+ WITH spec_build AS (
205+ SELECT {}
206+ FROM {}
207+ LIMIT 1
208+ ),
209209
210- filtered_builds AS (
211- SELECT {}
212- FROM builds b
213- INNER JOIN spec_build sb ON
214- sb.id = b.id
215- OR (COALESCE(sb.version_id, sb.project_version_id) = COALESCE(b.version_id, b.project_version_id) AND sb.type = b.type)
216- WHERE b.type <> 'ARCLIGHT'
217- OR split_part(sb.project_version_id, '-', -1) = split_part(b.project_version_id, '-', -1)
218- OR split_part(sb.project_version_id, '-', -1) NOT IN ('forge', 'neoforge', 'fabric')
219- ),
210+ filtered_builds AS (
211+ SELECT {}
212+ FROM builds b
213+ INNER JOIN spec_build sb ON
214+ sb.id = b.id
215+ OR (COALESCE(sb.version_id, sb.project_version_id) = COALESCE(b.version_id, b.project_version_id) AND sb.type = b.type)
216+ WHERE b.type <> 'ARCLIGHT'
217+ OR split_part(sb.project_version_id, '-', -1) = split_part(b.project_version_id, '-', -1)
218+ OR split_part(sb.project_version_id, '-', -1) NOT IN ('forge', 'neoforge', 'fabric')
219+ ),
220220
221- build_count AS (
222- SELECT count(*) AS count
223- FROM builds
224- WHERE COALESCE(version_id, project_version_id) = COALESCE(
225- (SELECT version_id FROM spec_build),
226- (SELECT project_version_id FROM spec_build)
221+ build_count AS (
222+ SELECT count(*) AS count
223+ FROM builds
224+ WHERE COALESCE(version_id, project_version_id) = COALESCE(
225+ (SELECT version_id FROM spec_build),
226+ (SELECT project_version_id FROM spec_build)
227+ )
227228 )
228- )
229229
230- SELECT
231- *,
232- 0 AS build_count,
233- now()::timestamp as version2_created,
234- 'RELEASE' AS version_type,
235- false AS version_supported,
236- 0 AS version_java,
237- now()::timestamp AS version_created
238- FROM spec_build
230+ SELECT
231+ *,
232+ 0 AS build_count,
233+ now()::timestamp as version2_created,
234+ 'RELEASE' AS version_type,
235+ false AS version_supported,
236+ 0 AS version_java,
237+ now()::timestamp AS version_created
238+ FROM spec_build
239239
240- UNION ALL
240+ UNION ALL
241241
242- SELECT
243- x.*,
244- mv.type AS version_type,
245- mv.supported AS version_supported,
246- mv.java AS version_java,
247- mv.created AS version_created
248- FROM (
249- SELECT *
242+ SELECT
243+ x.*,
244+ mv.type AS version_type,
245+ mv.supported AS version_supported,
246+ mv.java AS version_java,
247+ mv.created AS version_created
250248 FROM (
251- SELECT
252- {},
253- (SELECT count FROM build_count) AS build_count,
254- min(b.created) OVER () AS version2_created
255- FROM filtered_builds b
256- ORDER BY b.id DESC
257- ) LIMIT 1
258- ) x
259- LEFT JOIN minecraft_versions mv ON mv.id = x.version_id
260- "# ,
261- Self :: columns_sql( None , None ) ,
262- if let Some ( hash) = hash {
263- format!( "build_hashes INNER JOIN builds ON builds.id = build_hashes.build_id WHERE {hash} = decode($1, 'hex')" )
264- } else {
265- "builds WHERE builds.id = $1::int" . to_string( )
266- } ,
267- Self :: columns_sql( None , Some ( "b" ) ) ,
268- Self :: columns_sql( None , Some ( "b" ) )
269- ) )
270- . bind ( identifier)
271- . fetch_all ( database. read ( ) )
272- . await
273- . unwrap ( ) ;
249+ SELECT *
250+ FROM (
251+ SELECT
252+ {},
253+ (SELECT count FROM build_count) AS build_count,
254+ min(b.created) OVER () AS version2_created
255+ FROM filtered_builds b
256+ ORDER BY b.id DESC
257+ ) LIMIT 1
258+ ) x
259+ LEFT JOIN minecraft_versions mv ON mv.id = x.version_id
260+ "# ,
261+ Self :: columns_sql( None , None ) ,
262+ if let Some ( hash) = hash {
263+ format!( "build_hashes INNER JOIN builds ON builds.id = build_hashes.build_id WHERE {hash} = decode($1, 'hex')" )
264+ } else {
265+ "builds WHERE builds.id = $1::int" . to_string( )
266+ } ,
267+ Self :: columns_sql( None , Some ( "b" ) ) ,
268+ Self :: columns_sql( None , Some ( "b" ) )
269+ ) )
270+ . bind ( identifier)
271+ . fetch_all ( database. read ( ) )
272+ . await
273+ . unwrap ( ) ;
274274
275- if query. len ( ) != 2 {
276- return None ;
277- }
275+ if query. len ( ) != 2 {
276+ return None ;
277+ }
278278
279- Some ( (
280- Self :: map ( None , & query[ 0 ] ) ,
281- Self :: map ( None , & query[ 1 ] ) ,
282- super :: version:: MinifiedVersion {
283- id : query[ 1 ]
284- . try_get ( "version_id" )
285- . unwrap_or_else ( |_| query[ 1 ] . get ( "project_version_id" ) ) ,
286- r#type : query[ 1 ] . try_get ( "version_type" ) . unwrap_or ( VersionType :: Release ) ,
287- supported : query[ 1 ] . try_get ( "version_supported" ) . unwrap_or ( true ) ,
288- java : query[ 1 ] . try_get ( "version_java" ) . unwrap_or ( 21 ) ,
289- builds : query[ 1 ] . try_get ( "build_count" ) . unwrap_or ( 0 ) ,
290- created : query[ 1 ]
291- . try_get ( "version_created" )
292- . unwrap_or ( query[ 1 ] . try_get ( "version2_created" ) . unwrap_or_default ( ) ) ,
293- } ,
294- ) ) } )
279+ Some ( (
280+ Self :: map ( None , & query[ 0 ] ) ,
281+ Self :: map ( None , & query[ 1 ] ) ,
282+ super :: version:: MinifiedVersion {
283+ id : query[ 1 ]
284+ . try_get ( "version_id" )
285+ . unwrap_or_else ( |_| query[ 1 ] . get ( "project_version_id" ) ) ,
286+ r#type : query[ 1 ] . try_get ( "version_type" ) . unwrap_or ( VersionType :: Release ) ,
287+ supported : query[ 1 ] . try_get ( "version_supported" ) . unwrap_or ( true ) ,
288+ java : query[ 1 ] . try_get ( "version_java" ) . unwrap_or ( 21 ) ,
289+ builds : query[ 1 ] . try_get ( "build_count" ) . unwrap_or ( 0 ) ,
290+ created : query[ 1 ]
291+ . try_get ( "version_created" )
292+ . unwrap_or ( query[ 1 ] . try_get ( "version2_created" ) . unwrap_or_default ( ) ) ,
293+ } ,
294+ ) ) } )
295295 . await
296296 }
297297
0 commit comments