Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Jan 15, 2025
1 parent 35ac0fa commit 2dceafe
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 89 deletions.
11 changes: 2 additions & 9 deletions apps/gui/src/lib/components/lists/table/Filters.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@
// **Build Inverted Index**
function buildInvertedIndex(data: RecordData[], filtersInclude: string[]) {
// const begin = new Date().getTime();
// //console.log('begin buildInvertedIndex');
filtersInclude.forEach(filterKey => {
_invertedIndex[filterKey] = {};
data.forEach(record => {
Expand All @@ -140,7 +138,6 @@
}
});
});
// //console.log('end buildInvertedIndex', new Date().getTime() - begin);
}
// **Compute Active Record IDs Based on Active Filters**
Expand Down Expand Up @@ -318,8 +315,6 @@
// **Apply a Filter Value Based on Its Type and Mode**
function applyFilter(filterKey: string, value: any) {
// const begin = new Date().getTime();
// //console.log('begin applyFilter', filterKey, value);
const filter = $relayFilters.find(f => f.key === filterKey);
if (!filter) return;
Expand All @@ -338,26 +333,24 @@
}
} else if (filter.type === 'string' || filter.type === 'array') {
if (mode === 'OR') {
// OR mode allows multiple selections (union)
// union
if (Array.isArray(existingFilter)) {
if (existingFilter.includes(value)) {
// Deselect the value
const newValues = existingFilter.filter(v => v !== value);
if (newValues.length === 0) {
const { [filterKey]: _, ...rest } = currentFilters;
return rest;
}
return { ...currentFilters, [filterKey]: newValues };
} else {
// Select the value
return { ...currentFilters, [filterKey]: [...existingFilter, value] };
}
} else {
// Initialize with the new value
return { ...currentFilters, [filterKey]: [value] };
}
} else if (mode === 'AND') {
// AND mode requires all selected values to be present (intersection)
// intersection
if (Array.isArray(existingFilter)) {
if (existingFilter.includes(value)) {
// Deselect the value
Expand Down
2 changes: 0 additions & 2 deletions apps/gui/src/lib/components/partials/MonitorActions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
}
else {
monitor.enable()
// const lastSync = monitor.getLastSyncSince(30166)
const options = {
filters: [ monitor.checkFilter ],
options: {
Expand Down
7 changes: 6 additions & 1 deletion apps/gui/src/lib/stores/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { formatSeconds, timeAgo } from "../utils/time";
import { nip66 } from "./nip66";
import { delay } from "@nostrwatch/utils";

export type AppStateType = 'booting' | 'running' | 'sleeping' | 'shutdown'
export const appState: Writable<AppStateType> = writable()

export type TabStateType = 'idle' | 'leader' | 'follower' | 'unsupported';
export const tabState: Writable<TabStateType> = writable('follower');
export const nip66Initialized: Readable<boolean> = derived( nip66, ($nip66) => $nip66?.initialized? true: false )
export const unsupported: Writable<boolean> = writable(false)
export const isLivesyncing: Writable<boolean> = writable(false)
Expand All @@ -32,7 +36,7 @@ export const shouldSync = () => {
const threshold = 15*1
const timestamp = get(lastCompleteSync)
const now = Math.round(Date.now()/1000)
console.log('should snyc?', threshold<(now-timestamp), formatSeconds(threshold), timeAgo(now*1000), timeAgo(timestamp*1000))
console.log('should sync?', threshold<(now-timestamp), formatSeconds(threshold), timeAgo(now*1000), timeAgo(timestamp*1000))
if(threshold<(now-timestamp))
return true;
return false;
Expand All @@ -53,3 +57,4 @@ export const doAggregateCache: Writable<boolean> = writable(false)
export const shouldAggregate = (): boolean => {
return !get(doAggregateCache)
}

14 changes: 4 additions & 10 deletions apps/gui/src/lib/utils/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const bootstrapMonitorData = async () => {
if(!$nip66){
$nip66 = await instance();
}
bindBootstrapEmitters($nip66);
bindBootstrapEmitters();
await $nip66?.services?.monitors?.bootstrapMonitors();
}

Expand All @@ -148,7 +148,6 @@ export const bootstrapMonitorChecks = async () => {
await $nip66?.services?.monitors?.syncMonitorsChecks();
}


export const bootstrap = async () => {
console.log('bootstrap')
if(!$nip66){
Expand All @@ -163,7 +162,6 @@ export const bootstrap = async () => {
liveSyncBatcher.add(event);
}
}

if( shouldSync() ){
if( get(isBootstrapping) ) return;
isBootstrapping.set(true)
Expand All @@ -175,18 +173,16 @@ export const bootstrap = async () => {
})
}
else {
//console.log('skipping full sync')
//TODO: Send ready event from Cache Adapter Worker wait on Adapter ready.
// await $nip66?.adapters?.cache.ready();
await new Promise( (resolve) => setTimeout(resolve, 1000) )
//
await new Promise( (resolve) => setTimeout(resolve, 1000) )
seedFromCache().then( () => {
if(get(isLivesyncing)) return;
beginLiveSync({ onevents })
});
}
}

type LiveSyncResumer = () => Promise<void>

export const beginLiveSync = async (callbacks?: SubscribeHandlers): Promise<void> => {
isLivesyncing.set(true)
if(!$nip66){
Expand All @@ -203,8 +199,6 @@ export const stopLiveSync = async (): Promise<void> => {
$nip66?.services?.monitors?.stopLiveSync()
}

type LiveSyncResumer = () => Promise<void>

export const pauseLiveSync = async (): Promise<LiveSyncResumer> => {
console.log('Lifecycle:pauseLiveSync')
let wasLiveSyncing = get(isLivesyncing)
Expand Down
Loading

0 comments on commit 2dceafe

Please sign in to comment.