Skip to content
Merged
Show file tree
Hide file tree
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
40 changes: 11 additions & 29 deletions db/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,24 @@ import {

// ─── Desktop-Only Filter ─────────────────────────────────────────────
// Desktop-only = has at least one desktop platform tag but NO mobile tag.

const DESKTOP_TAG_SLUGS = ["desktop", "linux", "macos", "windows"];
const MOBILE_TAG_SLUGS = ["android", "ios"];
// Single query with conditional aggregation instead of 4 nested subqueries.

function desktopOnlyAppIds(db: DrizzleDB) {
const desktopTagIds = db
.select({ id: tags.id })
.from(tags)
.where(inArray(tags.slug, DESKTOP_TAG_SLUGS));

const mobileTagIds = db
.select({ id: tags.id })
.from(tags)
.where(inArray(tags.slug, MOBILE_TAG_SLUGS));

const appsWithDesktopTag = db
.select({ appId: appTags.appId })
.from(appTags)
.where(inArray(appTags.tagId, desktopTagIds));

const appsWithMobileTag = db
.select({ appId: appTags.appId })
.from(appTags)
.where(inArray(appTags.tagId, mobileTagIds));

// Apps that have a desktop tag but no mobile tag
return db
.select({ appId: appTags.appId })
.from(appTags)
.innerJoin(tags, eq(appTags.tagId, tags.id))
.where(
and(
inArray(appTags.appId, appsWithDesktopTag),
notInArray(appTags.appId, appsWithMobileTag),
or(
inArray(tags.slug, ["desktop", "linux", "macos", "windows"]),
inArray(tags.slug, ["android", "ios"]),
),
)
.groupBy(appTags.appId);
.groupBy(appTags.appId)
.having(
sql`sum(case when ${tags.slug} in ('desktop','linux','macos','windows') then 1 else 0 end) > 0
and sum(case when ${tags.slug} in ('android','ios') then 1 else 0 end) = 0`,
);
}

// ─── Types ──────────────────────────────────────────────────────────
Expand Down Expand Up @@ -376,7 +358,7 @@ export async function listDesktopApps(
const desktopTagIds = db
.select({ id: tags.id })
.from(tags)
.where(inArray(tags.slug, DESKTOP_TAG_SLUGS));
.where(inArray(tags.slug, ["desktop", "linux", "macos", "windows"]));

const appsWithDesktopTag = db
.select({ appId: appTags.appId })
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"format": "biome format --write .",
"typecheck": "tsc --noEmit",
"seed:fetch": "tsx db/seed/fetch.ts",
"seed:import": "tsx db/seed/import.ts",
"seed:enrich": "tsx db/seed/enrich.ts",
"seed:import": "tsx db/seed/import.ts && pnpm cache:purge",
"seed:enrich": "tsx db/seed/enrich.ts && pnpm cache:purge",
"cache:purge": "tsx scripts/cache-purge.ts",
"seed:comparisons": "tsx db/seed/generate-comparisons.ts",
"seed:embeddings": "tsx db/seed/generate-embeddings.ts"
Expand Down
17 changes: 3 additions & 14 deletions src/components/layout/site-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ function HeaderSearchForm() {
);
}

function MobileSearchBar({
onClose,
}: {
onClose: () => void;
}) {
function MobileSearchBar({ onClose }: { onClose: () => void }) {
const navigate = useNavigate();
const [query, setQuery] = useState("");
const inputRef = useRef<HTMLInputElement>(null);
Expand Down Expand Up @@ -107,12 +103,7 @@ function MobileSearchBar({
className="h-9 w-full rounded-4xl border border-input bg-input/30 pl-9 pr-3 text-sm text-foreground transition-colors placeholder:text-muted-foreground focus:border-ring focus:ring-[3px] focus:ring-ring/50 focus:outline-none"
/>
</div>
<Button
type="button"
variant="ghost"
size="icon-sm"
onClick={onClose}
>
<Button type="button" variant="ghost" size="icon-sm" onClick={onClose}>
<HugeiconsIcon icon={Cancel01Icon} strokeWidth={2} />
<span className="sr-only">Close search</span>
</Button>
Expand Down Expand Up @@ -189,9 +180,7 @@ export function SiteHeader() {
</div>
</div>

{searchOpen && (
<MobileSearchBar onClose={() => setSearchOpen(false)} />
)}
{searchOpen && <MobileSearchBar onClose={() => setSearchOpen(false)} />}
</header>
);
}
15 changes: 10 additions & 5 deletions src/routes/-worker-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,27 @@ const SITE_URL = "https://unclouded.app";

type CacheRule = { pattern: RegExp; header: string };

// Data only changes on manual DB writes (seed/enrich), then cache:purge.
// Cache everything aggressively — 1 week fresh, 1 week stale fallback.
const ONE_WEEK = 604800;

const cacheRules: CacheRule[] = [
{ pattern: /^\/search/, header: "no-store" },
{
pattern: /^\/sitemap.*\.xml$|^\/robots\.txt$/,
header: "public, s-maxage=86400",
header: `public, s-maxage=${ONE_WEEK}`,
},
{
pattern: /^\/compare\//,
header: "public, s-maxage=86400, stale-while-revalidate=604800",
header: `public, s-maxage=${ONE_WEEK}, stale-while-revalidate=${ONE_WEEK}`,
},
{
pattern: /^\/(apps|alternatives)\/[^/]+$|^\/(category|tags|license)\//,
header: "public, s-maxage=3600, stale-while-revalidate=86400",
header: `public, s-maxage=${ONE_WEEK}, stale-while-revalidate=${ONE_WEEK}`,
},
{
pattern: /^\/(apps|alternatives|discover)?$/,
header: "public, s-maxage=600, stale-while-revalidate=3600",
pattern: /^\/(apps|alternatives|discover|desktop)?$/,
header: `public, s-maxage=${ONE_WEEK}, stale-while-revalidate=${ONE_WEEK}`,
},
];

Expand All @@ -52,6 +56,7 @@ function robotsTxt(): Response {
const body = `User-agent: *
Allow: /
Disallow: /search
Crawl-delay: 10

Sitemap: ${SITE_URL}/sitemap.xml
`;
Expand Down
Loading