Flag broken stores on search page with red X and auto-deselect

- Add last_scrape_ok and last_scrape_at columns (migration 004)
- Update scrape status after every search, test, and streaming search
- Search page: broken stores show red X checkbox, strikethrough name,
  "failing" label, and are auto-deselected on page load
- Untested stores show "untested" label
- Users can still manually select broken stores if they want to try

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
mariosemes
2026-03-26 23:12:44 +01:00
parent cb71421d8d
commit 72980e0dd6
5 changed files with 43 additions and 10 deletions

View File

@@ -12,9 +12,9 @@
onMount(async () => {
try {
[categories, stores] = await Promise.all([getCategories(), getStores()]);
// Start with all enabled stores selected
const enabledIds = stores.filter(s => s.enabled).map(s => s.id);
selectedStoreIds = new Set(enabledIds);
// Start with all enabled & healthy stores selected (exclude broken ones)
const healthyIds = stores.filter(s => s.enabled && s.last_scrape_ok !== 0).map(s => s.id);
selectedStoreIds = new Set(healthyIds);
} catch { /* server may not be ready yet */ }
});
@@ -156,21 +156,38 @@
<!-- Store list -->
<div class="space-y-0.5">
{#each group.stores as store}
{@const isBroken = store.last_scrape_ok === 0}
<button
onclick={() => toggleStore(store.id)}
class="flex items-center gap-2.5 w-full text-left -mx-2 px-2 py-1 rounded transition-colors hover:bg-surface-hover/50"
>
<span class="w-3.5 h-3.5 rounded border flex items-center justify-center flex-shrink-0 transition-colors
{selectedStoreIds.has(store.id)
{isBroken
? 'border-red-500/50 bg-red-500/20'
: selectedStoreIds.has(store.id)
? 'border-accent bg-accent'
: 'border-text-tertiary/40'}">
{#if selectedStoreIds.has(store.id)}
{#if isBroken}
<svg class="w-2.5 h-2.5 text-red-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="3">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
{:else if selectedStoreIds.has(store.id)}
<svg class="w-2.5 h-2.5 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="3">
<path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5" />
</svg>
{/if}
</span>
<span class="text-xs transition-colors {selectedStoreIds.has(store.id) ? 'text-text-primary' : 'text-text-tertiary'}">{store.name}</span>
<span class="text-xs transition-colors
{isBroken
? 'text-red-400/70 line-through'
: selectedStoreIds.has(store.id)
? 'text-text-primary'
: 'text-text-tertiary'}">{store.name}</span>
{#if isBroken}
<span class="text-2xs text-red-400/50">failing</span>
{:else if store.last_scrape_ok === null}
<span class="text-2xs text-text-tertiary/50">untested</span>
{/if}
</button>
{/each}
</div>

View File

@@ -0,0 +1,2 @@
ALTER TABLE stores ADD COLUMN last_scrape_ok INTEGER DEFAULT NULL;
ALTER TABLE stores ADD COLUMN last_scrape_at TEXT DEFAULT NULL;

View File

@@ -9,6 +9,8 @@ export interface Store {
enabled: number;
render_js: number;
test_query: string;
last_scrape_ok: number | null;
last_scrape_at: string | null;
sel_container: string;
sel_name: string;
sel_price: string;
@@ -163,6 +165,12 @@ export function updateStore(id: number, input: Partial<CreateStoreInput>): Store
return getStoreById(id);
}
export function updateScrapeStatus(id: number, success: boolean): void {
const db = getDatabase();
db.run("UPDATE stores SET last_scrape_ok = ?, last_scrape_at = datetime('now') WHERE id = ?", [success ? 1 : 0, id]);
saveDatabase();
}
export function toggleStoreEnabled(id: number): Store | undefined {
const db = getDatabase();
db.run("UPDATE stores SET enabled = CASE WHEN enabled = 1 THEN 0 ELSE 1 END, updated_at = datetime('now') WHERE id = ?", [id]);

View File

@@ -1,5 +1,5 @@
import type { FastifyPluginAsync } from 'fastify';
import { getStoreById } from '../models/store.js';
import { getStoreById, updateScrapeStatus } from '../models/store.js';
import { logScrape, getLogsByStore, getStoreHealth } from '../models/scrape-log.js';
import { scrapeStore } from '../scraper/http-scraper.js';
import { scrapeStoreWithBrowser } from '../scraper/browser-scraper.js';
@@ -37,6 +37,7 @@ export const testRoutes: FastifyPluginAsync = async (app) => {
);
logScrape(store.id, request.body.query, true, products.length, duration);
updateScrapeStatus(store.id, true);
return {
success: true,
@@ -55,6 +56,7 @@ export const testRoutes: FastifyPluginAsync = async (app) => {
const duration = Date.now() - startTime;
const errorMessage = err instanceof Error ? err.message : String(err);
logScrape(store.id, request.body.query, false, 0, duration, errorMessage);
updateScrapeStatus(store.id, false);
return {
success: false,

View File

@@ -1,6 +1,6 @@
import pLimit from 'p-limit';
import type { Store } from '../models/store.js';
import { getEnabledStores, getStoresByCategory, getStoresByGroup, getStoresByIds } from '../models/store.js';
import { getEnabledStores, getStoresByCategory, getStoresByGroup, getStoresByIds, updateScrapeStatus } from '../models/store.js';
import { logScrape } from '../models/scrape-log.js';
import { scrapeStore } from './http-scraper.js';
import { scrapeStoreWithBrowser } from './browser-scraper.js';
@@ -90,11 +90,13 @@ export async function search(options: SearchOptions): Promise<SearchResult> {
);
logScrape(store.id, query, true, products.length, duration);
updateScrapeStatus(store.id, true);
return products;
} catch (err) {
const duration = Date.now() - storeStart;
const errorMessage = err instanceof Error ? err.message : String(err);
logScrape(store.id, query, false, 0, duration, errorMessage);
updateScrapeStatus(store.id, false);
errors.push({ storeId: store.id, storeName: store.name, error: errorMessage });
return [];
}
@@ -188,6 +190,7 @@ export async function searchStreaming(
);
logScrape(store.id, query, true, products.length, duration);
updateScrapeStatus(store.id, true);
totalResults += products.length;
onProgress({
@@ -202,6 +205,7 @@ export async function searchStreaming(
const duration = Date.now() - storeStart;
const errorMessage = err instanceof Error ? err.message : String(err);
logScrape(store.id, query, false, 0, duration, errorMessage);
updateScrapeStatus(store.id, false);
errors.push({ storeId: store.id, storeName: store.name, error: errorMessage });
onProgress({