Skip to content
Merged
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
20 changes: 10 additions & 10 deletions src/backend/stores/subdomain/SubdomainStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ const CACHE_KEY_PREFIX = 'subdomains';
const CACHE_TTL_SECONDS = 60 * 60;
// Sentinel so 404s on the same public subdomain don't hit the DB repeatedly.
const NEGATIVE_CACHE_MARKER = '__none__';
const NEGATIVE_CACHE_TTL_SECONDS = 60;
const NEGATIVE_CACHE_TTL_SECONDS = 10;

export class SubdomainStore extends PuterStore {
// ── Reads ────────────────────────────────────────────────────────

async getByUuid(uuid, { userId } = {}) {
async getByUuid(uuid, { userId, primary = false } = {}) {
const where =
userId !== undefined
? 'WHERE `uuid` = ? AND `user_id` = ?'
: 'WHERE `uuid` = ?';
const params = userId !== undefined ? [uuid, userId] : [uuid];
const rows = await this.clients.db.read(
`SELECT * FROM \`subdomains\` ${where} LIMIT 1`,
params,
);
const sql = `SELECT * FROM \`subdomains\` ${where} LIMIT 1`;
const rows = primary
? await this.clients.db.pread(sql, params)
: await this.clients.db.read(sql, params);
return rows[0] ?? null;
}

Expand Down Expand Up @@ -290,22 +290,22 @@ export class SubdomainStore extends PuterStore {
: 'WHERE `uuid` = ?';
const params = userId !== undefined ? [uuid, userId] : [uuid];

const result = await this.clients.db.write(
await this.clients.db.write(
`DELETE FROM \`subdomains\` ${where}`,
params,
);
const affected = (result?.affectedRows ?? result?.changes ?? 0) > 0;
if (affected && row?.subdomain) {
if (row?.subdomain) {
await this.publishCacheKeys({
keys: [this.#cacheKey(row.subdomain)],
serializedData: NEGATIVE_CACHE_MARKER,
ttlSeconds: NEGATIVE_CACHE_TTL_SECONDS,
broadcast: true,
});
if (row.user_id != null) {
await this.#invalidatePrefixListsForUser(row.user_id);
}
await this.#invalidateRootDirEntry(row.root_dir_id);
}
return affected;
}

// ── Internals ────────────────────────────────────────────────────
Expand Down