Skip to content

Commit

Permalink
Reduce ceremony requests (#3171)
Browse files Browse the repository at this point in the history
  • Loading branch information
Swepool authored Oct 30, 2024
2 parents e5c9e76 + 7868e11 commit dca70b4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 33 deletions.
17 changes: 14 additions & 3 deletions ceremony/src/lib/components/Terminal/Activity.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
<script lang="ts">
import { getState } from "$lib/state/index.svelte.ts"
import Print from "$lib/components/Terminal/Print.svelte"
import { onDestroy, onMount } from "svelte"
import { Activity } from "$lib/state/activity.svelte.ts"
const { activity } = getState()
let activity: Activity | null = $state(null)
onMount(() => {
activity = new Activity()
})
onDestroy(() => {
if (activity) {
activity = null
}
})
function formatTimestamp(timestamp: string): string {
const date = new Date(timestamp)
Expand All @@ -20,7 +31,7 @@ function formatTimestamp(timestamp: string): string {
}
</script>

{#if activity.data}
{#if activity && activity.data}
<div class="flex flex-col-reverse">
{#each activity.data as item, i (item)}
{@const type = item.message.type}
Expand Down
44 changes: 24 additions & 20 deletions ceremony/src/lib/components/Terminal/Contributors.svelte
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
<script lang="ts">
import { getState } from "$lib/state/index.svelte.ts"
import { goto } from "$app/navigation"
import { onMount } from "svelte"
import { onMount, onDestroy } from "svelte"
import Buttons from "$lib/components/Terminal/Install/Buttons.svelte"
import type { Contributions } from "$lib/state/contributions.svelte.ts"
import type { Terminal } from "$lib/state/terminal.svelte.ts"
import { Contributions } from "$lib/state/contributions.svelte.ts"
import { getState } from "$lib/state/index.svelte.ts"
type State = {
contributions: Contributions
terminal: Terminal
}
const { terminal } = getState()
const { contributions, terminal }: State = getState()
let contributions: Contributions | null = null
let data: Array<{ text: string; action: string }> = $state([])
let focusedIndex = $state(0)
let buttons: Array<HTMLButtonElement> = []
let data = $state([])
onMount(() => {
contributions.data.map(contribution => {
data.push({ text: contribution.payload_id, action: contribution.public_key_hash })
})
contributions = new Contributions()
})
onDestroy(() => {
if (contributions) {
contributions = null
}
})
$effect(() => {
if (contributions) {
data = contributions.data.map(contribution => ({
text: contribution.payload_id,
action: contribution.public_key_hash
}))
}
})
function trigger(value: any) {
function trigger(value: string) {
goto(`/contributions/${value}`)
terminal.setTab(4)
terminal.setHash(value)
}
</script>
<Buttons
{data}
trigger={(value) => trigger(value)}
/>
<Buttons {data} trigger={(value) => trigger(value)}/>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Activity {
.from("log")
.select("message, created_at")
.order("created_at", { ascending: false })
.limit(100)
.limit(50)

if (error) {
console.error("Error fetching initial data:", error)
Expand Down
4 changes: 2 additions & 2 deletions ceremony/src/lib/state/contributor.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ type QueueInfoResult = QueueInfoSuccess | QueueInfoError

const second = 1000
const CLIENT_POLING_INTERVAL = second * 5
const CONTRIBUTION_POLLING_INTERVAL = second * 15
const QUEUE_POLLING_INTERVAL = second * 30
const CONTRIBUTION_POLLING_INTERVAL = second * 30
const QUEUE_POLLING_INTERVAL = second * 60

export class Contributor {
userId = $state<string | undefined>(undefined)
Expand Down
6 changes: 0 additions & 6 deletions ceremony/src/lib/state/index.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ import { getContext, setContext } from "svelte"
import { Contributor } from "./contributor.svelte.ts"
import { Terminal } from "./terminal.svelte.ts"
import { user, type UserSession } from "$lib/state/session.svelte.ts"
import { Activity } from "$lib/state/live.svelte.ts"
import { Contributions } from "$lib/state/contributions.svelte.ts"

export interface AppState {
contributor: Contributor
terminal: Terminal
activity: Activity
contributions: Contributions
user: UserSession
}

Expand All @@ -20,8 +16,6 @@ export function createState() {
const state: AppState = {
contributor: new Contributor(),
terminal: new Terminal(),
activity: new Activity(),
contributions: new Contributions(),
user: user
}

Expand Down
2 changes: 1 addition & 1 deletion ceremony/src/lib/supabase/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const SUPABASE_URL = import.meta.env.VITE_SUPABASE_URL
export const createSupabaseClient = () => {
let client: SupabaseClient | null = null
let refreshInterval: NodeJS.Timeout | null = null
const REFRESH_INTERVAL = 5 * 60 * 1000 // 5 minutes
const REFRESH_INTERVAL = 30 * 60 * 1000 // 30 minutes

const getClient = () => {
if (client) return client
Expand Down

0 comments on commit dca70b4

Please sign in to comment.