Skip to content

Commit

Permalink
fix: improve wm_labels indices + UX nits
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Sep 4, 2024
1 parent a7a08cf commit 31c6a03
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 32 deletions.
22 changes: 10 additions & 12 deletions backend/windmill-api/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,6 @@ impl Migrate for CustomMigrator {
migration.version,
migration.description
);
if migration.version == 20240424083501 {
tracing::info!("Special migration to add index concurrently on job labels 2");
sqlx::query!(
"DROP INDEX CONCURRENTLY IF EXISTS labeled_jobs_on_jobs"
).execute(&mut *self.inner).await?;
sqlx::query!(
"CREATE INDEX CONCURRENTLY labeled_jobs_on_jobs ON completed_job USING GIN ((result -> 'wm_labels')) WHERE result ? 'wm_label';"
).execute(&mut *self.inner).await?;
}
let r = self.inner.apply(migration).await;
tracing::info!("Finished applying migration {}", migration.version);
r
Expand Down Expand Up @@ -309,9 +300,6 @@ macro_rules! run_windmill_migration {
.await?;
tx.commit().await?;
tracing::info!("released lock for {migration_job_name}");


tracing::info!("Finished applying {migration_job_name} migration");
} else {
tracing::info!("migration {migration_job_name} already done");

Expand Down Expand Up @@ -481,6 +469,16 @@ async fn fix_job_completed_index(db: &DB) -> Result<(), Error> {
.await?;
});

run_windmill_migration!("fix_labeled_jobs_index", &db, {
tracing::info!("Special migration to add index concurrently on job labels 2");
sqlx::query!("DROP INDEX CONCURRENTLY IF EXISTS labeled_jobs_on_jobs")
.execute(db)
.await?;
sqlx::query!(
"CREATE INDEX CONCURRENTLY labeled_jobs_on_jobs ON completed_job USING GIN ((result -> 'wm_labels')) WHERE result ? 'wm_labels'"
).execute(db).await?;
});

Ok(())
}

Expand Down
14 changes: 7 additions & 7 deletions backend/windmill-api/src/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4664,6 +4664,13 @@ pub fn filter_list_completed_query(
.on_eq("id", "outstanding_wait_time.job_id");
}

if let Some(label) = &lq.label {
let mut wh = format!("result->'wm_labels' ? ");
wh.push_str(&format!("'{}'", &label.replace("'", "''")));
sqlb.and_where("result ? 'wm_labels'");
sqlb.and_where(&wh);
}

if w_id != "admins" || !lq.all_workspaces.is_some_and(|x| x) {
sqlb.and_where_eq("workspace_id", "?".bind(&w_id));
}
Expand Down Expand Up @@ -4752,13 +4759,6 @@ pub fn filter_list_completed_query(
sqlb.and_where("result @> ?".bind(&result.replace("'", "''")));
}

if let Some(label) = &lq.label {
let mut wh = format!("result->'wm_labels' ? ");
wh.push_str(&format!("'{}'", &label.replace("'", "''")));
sqlb.and_where(&wh);
sqlb.and_where("result ? 'wm_labels'");
}

if lq.is_not_schedule.unwrap_or(false) {
sqlb.and_where("schedule_path IS null");
}
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/lib/components/common/button/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
)
const iconMap = {
xs3: 12,
xs2: 14,
xs: 14,
sm: 16,
Expand All @@ -161,6 +162,7 @@
}
const iconOnlyPadding = {
xs3: 'm-[0.5px] qhd:m-[1px]',
xs2: 'm-[1px] qhd:m-[1.125px]',
xs: 'm-[1px] qhd:m-[1.125px]',
sm: 'm-[2px] qhd:m-[2.25px]',
Expand All @@ -169,12 +171,9 @@
xl: 'm-[5px] qhd:m-[5.625px]'
}
let innerWidth = 0
$: lucideIconSize = (iconMap[size] ?? 12) * (innerWidth > 2500 ? 1.125 : 1)
$: lucideIconSize = (iconMap[size] ?? 12) * 1
</script>

<svelte:window bind:innerWidth />

<div
class="{dropdownItems && dropdownItems.length > 0 && variant === 'contained'
? colorVariants[color].divider
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/lib/components/common/button/model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const BUTTON_COLORS = ['blue', 'red', 'dark', 'light', 'green', 'gray', 'none'] as const

export namespace ButtonType {
export type Size = 'xs2' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'
export type Size = 'xs3' | 'xs2' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'
export type Color = string
export type Variant = 'contained' | 'border' | 'divider'
export type Target = '_self' | '_blank'
Expand All @@ -13,6 +13,7 @@ export namespace ButtonType {
}

export const FontSizeClasses: Record<ButtonType.Size, string> = {
xs3: 'text-2xs',
xs2: 'text-xs',
xs: 'text-xs',
sm: 'text-sm',
Expand All @@ -22,6 +23,11 @@ export namespace ButtonType {
} as const

export const SpacingClasses: Record<ButtonType.Size, Record<ButtonType.Variant, string>> = {
xs3: {
border: 'px-0.5 py-[1px] !rounded-xs',
contained: 'px-0.5 py-[1px]',
divider: ''
},
xs2: {
border: 'px-2 py-[4px]',
contained: 'px-2 py-[4px]',
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/lib/components/runs/RunRow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@
{/if}
</div>
{#if containsLabel}
<div class="w-3/12 flex justify-start">
<div class="w-3/12 flex justify-start px-0.5">
{#if job && job?.['labels']}
<div class="flex flex-row items-center gap-1 overflow-x-auto">
{#if Array.isArray(job?.['labels'])}
{#each job?.['labels'] as label}
<Button
variant="border"
size="xs2"
size="xs3"
btnClasses={twMerge(
activeLabel == label ? 'bg-blue-50 dark:bg-blue-900/50' : '',
'!text-2xs !font-normal truncate max-w-28'
Expand All @@ -228,9 +228,9 @@
on:click={() => {
dispatch('filterByLabel', label)
}}
endIcon={{ icon: ListFilter }}
>
{label}
<ListFilter size={10} />
</Button>
{/each}
{/if}
Expand All @@ -248,7 +248,7 @@
btnClasses="font-normal"
on:click={() => scheduleEditor?.openEdit(job.schedule_path ?? '', job.job_kind == 'flow')}
>
<div class="truncate text-ellipsis text-left">
<div class="truncate text-ellipsis text-left" title={job.schedule_path}>
{truncateRev(job.schedule_path, 20)}
</div>
</Button>
Expand All @@ -264,15 +264,15 @@
</div>
{:else}
<div class="flex flex-row gap-1 items-center">
<div class="text-xs">
{job.created_by}
<div class="text-xs truncate text-ellipsis text-left" title={job.created_by}>
{truncateRev(job.created_by ?? '', 20)}
</div>
{#if !isExternal}
<Button
size="xs2"
color="light"
on:click={() => {
dispatch('filterByUser', job.created_by)
dispatch('filterByUser', job.created_by ?? '')
}}
>
<ListFilter size={10} />
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/lib/components/sidebar/WorkspaceMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
if (!isOnEditPage) {
switchWorkspace(id)
if ($page.url.searchParams.get('workspace')) {
$page.url.searchParams.set('workspace', id)
}
goto($page.url.toString())
} else {
await goto('/')
switchWorkspace(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
<PersistentScriptDrawer bind:this={persistentScriptDrawer} />
</Portal>

{#if notfound}
{#if notfound || (job?.workspace_id != undefined && $workspaceStore != undefined && job?.workspace_id != $workspaceStore)}
<div class="max-w-7xl px-4 mx-auto w-full">
<div class="flex flex-col gap-6">
<h1 class="text-red-400 mt-6">Job {$page.params.run} not found in {$workspaceStore}</h1>
Expand Down

0 comments on commit 31c6a03

Please sign in to comment.