Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions src/db/marketplace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ pub async fn list_approved_by_creator(
t.status,
t.is_configurable,
t.view_count,
t.deploy_count,
GREATEST(
t.deploy_count,
(SELECT COUNT(*) FROM project p WHERE p.source_template_id = t.id)::int,
(SELECT COUNT(*) FROM stack_template_deployment d WHERE d.template_id = t.id)::int
) AS deploy_count,
t.required_plan_name,
t.price,
t.billing_cycle,
Expand All @@ -110,7 +114,7 @@ pub async fn list_approved_by_creator(

match sort.unwrap_or("recent") {
"popular" => base.push_str(
" ORDER BY (t.verifications @> '{\"hardened_images\":true}') DESC, t.deploy_count DESC, t.view_count DESC",
" ORDER BY (t.verifications @> '{\"hardened_images\":true}') DESC, deploy_count DESC, t.view_count DESC",
),
"rating" => base.push_str(&format!(
" ORDER BY (t.verifications @> '{{\"hardened_images\":true}}') DESC, {} DESC NULLS LAST",
Expand Down Expand Up @@ -160,7 +164,11 @@ pub async fn list_approved(
t.status,
t.is_configurable,
t.view_count,
t.deploy_count,
GREATEST(
t.deploy_count,
(SELECT COUNT(*) FROM project p WHERE p.source_template_id = t.id)::int,
(SELECT COUNT(*) FROM stack_template_deployment d WHERE d.template_id = t.id)::int
) AS deploy_count,
t.required_plan_name,
t.price,
t.billing_cycle,
Expand Down Expand Up @@ -201,7 +209,7 @@ pub async fn list_approved(
match sort.unwrap_or("recent") {
// Hardened images always float to the top of each sort bucket
"popular" => base.push_str(
" ORDER BY (t.verifications @> '{\"hardened_images\":true}') DESC, t.deploy_count DESC, t.view_count DESC",
" ORDER BY (t.verifications @> '{\"hardened_images\":true}') DESC, deploy_count DESC, t.view_count DESC",
),
"rating" => base.push_str(&format!(
" ORDER BY (t.verifications @> '{{\"hardened_images\":true}}') DESC, {} DESC NULLS LAST",
Expand Down Expand Up @@ -264,7 +272,11 @@ pub async fn get_by_slug_and_user(
t.status,
t.is_configurable,
t.view_count,
t.deploy_count,
GREATEST(
t.deploy_count,
(SELECT COUNT(*) FROM project p WHERE p.source_template_id = t.id)::int,
(SELECT COUNT(*) FROM stack_template_deployment d WHERE d.template_id = t.id)::int
) AS deploy_count,
t.required_plan_name,
t.price,
t.billing_cycle,
Expand Down Expand Up @@ -319,7 +331,11 @@ pub async fn get_by_slug_with_latest(
t.status,
t.is_configurable,
t.view_count,
t.deploy_count,
GREATEST(
t.deploy_count,
(SELECT COUNT(*) FROM project p WHERE p.source_template_id = t.id)::int,
(SELECT COUNT(*) FROM stack_template_deployment d WHERE d.template_id = t.id)::int
) AS deploy_count,
t.required_plan_name,
t.price,
t.billing_cycle,
Expand Down Expand Up @@ -438,7 +454,11 @@ pub async fn get_by_id(
t.status,
t.is_configurable,
t.view_count,
t.deploy_count,
GREATEST(
t.deploy_count,
(SELECT COUNT(*) FROM project p WHERE p.source_template_id = t.id)::int,
(SELECT COUNT(*) FROM stack_template_deployment d WHERE d.template_id = t.id)::int
) AS deploy_count,
t.created_at,
t.updated_at,
t.approved_at,
Expand Down Expand Up @@ -1419,7 +1439,11 @@ pub async fn list_mine(pool: &PgPool, user_id: &str) -> Result<Vec<StackTemplate
t.status,
t.is_configurable,
t.view_count,
t.deploy_count,
GREATEST(
t.deploy_count,
(SELECT COUNT(*) FROM project p WHERE p.source_template_id = t.id)::int,
(SELECT COUNT(*) FROM stack_template_deployment d WHERE d.template_id = t.id)::int
) AS deploy_count,
t.required_plan_name,
t.price,
t.billing_cycle,
Expand Down Expand Up @@ -1508,7 +1532,11 @@ pub async fn admin_list_submitted(pool: &PgPool) -> Result<Vec<StackTemplate>, S
t.status,
t.is_configurable,
t.view_count,
t.deploy_count,
GREATEST(
t.deploy_count,
(SELECT COUNT(*) FROM project p WHERE p.source_template_id = t.id)::int,
(SELECT COUNT(*) FROM stack_template_deployment d WHERE d.template_id = t.id)::int
) AS deploy_count,
t.required_plan_name,
t.price,
t.billing_cycle,
Expand Down Expand Up @@ -2996,7 +3024,11 @@ pub async fn get_approved_by_slug(
t.status,
t.is_configurable,
t.view_count,
t.deploy_count,
GREATEST(
t.deploy_count,
(SELECT COUNT(*) FROM project p WHERE p.source_template_id = t.id)::int,
(SELECT COUNT(*) FROM stack_template_deployment d WHERE d.template_id = t.id)::int
) AS deploy_count,
t.required_plan_name,
t.price,
t.billing_cycle,
Expand Down
Loading