Skip to content

Commit 1f92b1a

Browse files
committed
v7.9.45
1 parent c0af457 commit 1f92b1a

4 files changed

Lines changed: 56 additions & 48 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nosflare",
3-
"version": "7.9.44",
3+
"version": "7.9.45",
44
"main": "worker.js",
55
"type": "module",
66
"scripts": {

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const relayInfo: RelayInfo = {
2323
contact: "lux@fed.wtf",
2424
supported_nips: [1, 2, 4, 5, 9, 11, 12, 13, 15, 16, 17, 20, 22, 25, 28, 33, 40, 42, 57],
2525
software: "https://github.com/Spl0itable/nosflare",
26-
version: "7.9.44",
26+
version: "7.9.45",
2727
icon: "https://raw.githubusercontent.com/Spl0itable/nosflare/main/images/flare.png",
2828

2929
// Optional fields (uncomment as needed):

src/relay-worker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,14 +2387,14 @@ async function getOptimalDO(cf: any, env: Env, url: URL): Promise<{ stub: Durabl
23872387

23882388
// Database pruning helper functions
23892389

2390-
// Get the current database size in bytes using SQLite pragmas
2390+
// Get the current database size in bytes
23912391
async function getDatabaseSizeBytes(session: D1DatabaseSession): Promise<number> {
23922392
try {
2393-
const pageCountResult = await session.prepare('PRAGMA page_count').first() as { page_count: number } | null;
2394-
const pageSizeResult = await session.prepare('PRAGMA page_size').first() as { page_size: number } | null;
2393+
const result = await session.prepare('SELECT 1').run();
2394+
const sizeAfter = (result.meta as { size_after?: number } | undefined)?.size_after;
23952395

2396-
if (pageCountResult && pageSizeResult) {
2397-
return pageCountResult.page_count * pageSizeResult.page_size;
2396+
if (typeof sizeAfter === 'number' && sizeAfter > 0) {
2397+
return sizeAfter;
23982398
}
23992399
return 0;
24002400
} catch (error) {

worker.js

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ var relayInfo = {
8080
contact: "lux@fed.wtf",
8181
supported_nips: [1, 2, 4, 5, 9, 11, 12, 13, 15, 16, 17, 20, 22, 25, 28, 33, 40, 42, 57],
8282
software: "https://github.com/Spl0itable/nosflare",
83-
version: "7.9.44",
83+
version: "7.9.45",
8484
icon: "https://raw.githubusercontent.com/Spl0itable/nosflare/main/images/flare.png",
8585
// Optional fields (uncomment as needed):
8686
// banner: "https://example.com/banner.jpg",
@@ -2939,42 +2939,50 @@ async function initializeDatabase(db) {
29392939
`).run();
29402940
} catch (_) {
29412941
}
2942-
const dropIndexes = [
2943-
"idx_events_pubkey",
2944-
"idx_events_kind",
2945-
"idx_events_created_at_kind",
2946-
"idx_events_authors_kinds",
2947-
"idx_events_tag_p_created_at",
2948-
"idx_events_tag_e_created_at",
2949-
"idx_events_tag_a_created_at",
2950-
"idx_events_tag_t_created_at",
2951-
"idx_events_tag_d_created_at",
2952-
"idx_events_tag_r_created_at",
2953-
"idx_events_tag_L_created_at",
2954-
"idx_events_tag_s_created_at",
2955-
"idx_events_tag_u_created_at",
2956-
"idx_events_kind_tag_p",
2957-
"idx_events_kind_tag_e",
2958-
"idx_events_kind_tag_a",
2959-
"idx_events_kind_tag_t",
2960-
"idx_events_kind_tag_L",
2961-
"idx_events_kind_tag_s",
2962-
"idx_events_reply_to",
2963-
"idx_events_root_thread",
2964-
"idx_events_kind_created_at_covering",
2965-
"idx_events_pubkey_kind_created_at_covering",
2966-
"idx_events_created_at_covering",
2967-
"idx_events_kind_pubkey_created_at_covering",
2968-
"idx_tags_name_value",
2969-
"idx_tags_value",
2970-
"idx_tags_name_value_event_created"
2971-
];
2972-
for (const idx of dropIndexes) {
2973-
await dropSession.prepare(`DROP INDEX IF EXISTS ${idx}`).run();
2974-
}
2975-
const dropTables = ["event_tags_cache", "mv_follow_graph", "mv_recent_notes", "mv_timeline_cache"];
2976-
for (const tbl of dropTables) {
2977-
await dropSession.prepare(`DROP TABLE IF EXISTS ${tbl}`).run();
2942+
const cleanupDone = await dropSession.prepare(
2943+
"SELECT value FROM system_config WHERE key = 'cleanup_v1' LIMIT 1"
2944+
).first().catch(() => null);
2945+
if (!cleanupDone || cleanupDone.value !== "1") {
2946+
const dropIndexes = [
2947+
"idx_events_pubkey",
2948+
"idx_events_kind",
2949+
"idx_events_created_at_kind",
2950+
"idx_events_authors_kinds",
2951+
"idx_events_tag_p_created_at",
2952+
"idx_events_tag_e_created_at",
2953+
"idx_events_tag_a_created_at",
2954+
"idx_events_tag_t_created_at",
2955+
"idx_events_tag_d_created_at",
2956+
"idx_events_tag_r_created_at",
2957+
"idx_events_tag_L_created_at",
2958+
"idx_events_tag_s_created_at",
2959+
"idx_events_tag_u_created_at",
2960+
"idx_events_kind_tag_p",
2961+
"idx_events_kind_tag_e",
2962+
"idx_events_kind_tag_a",
2963+
"idx_events_kind_tag_t",
2964+
"idx_events_kind_tag_L",
2965+
"idx_events_kind_tag_s",
2966+
"idx_events_reply_to",
2967+
"idx_events_root_thread",
2968+
"idx_events_kind_created_at_covering",
2969+
"idx_events_pubkey_kind_created_at_covering",
2970+
"idx_events_created_at_covering",
2971+
"idx_events_kind_pubkey_created_at_covering",
2972+
"idx_tags_name_value",
2973+
"idx_tags_value",
2974+
"idx_tags_name_value_event_created"
2975+
];
2976+
for (const idx of dropIndexes) {
2977+
await dropSession.prepare(`DROP INDEX IF EXISTS ${idx}`).run();
2978+
}
2979+
const dropTables = ["event_tags_cache", "mv_follow_graph", "mv_recent_notes", "mv_timeline_cache"];
2980+
for (const tbl of dropTables) {
2981+
await dropSession.prepare(`DROP TABLE IF EXISTS ${tbl}`).run();
2982+
}
2983+
await dropSession.prepare(
2984+
"INSERT OR REPLACE INTO system_config (key, value) VALUES ('cleanup_v1', '1')"
2985+
).run();
29782986
}
29792987
try {
29802988
const initCheck = await dropSession.prepare(
@@ -5087,10 +5095,10 @@ async function getOptimalDO(cf, env, url) {
50875095
__name(getOptimalDO, "getOptimalDO");
50885096
async function getDatabaseSizeBytes(session) {
50895097
try {
5090-
const pageCountResult = await session.prepare("PRAGMA page_count").first();
5091-
const pageSizeResult = await session.prepare("PRAGMA page_size").first();
5092-
if (pageCountResult && pageSizeResult) {
5093-
return pageCountResult.page_count * pageSizeResult.page_size;
5098+
const result = await session.prepare("SELECT 1").run();
5099+
const sizeAfter = result.meta?.size_after;
5100+
if (typeof sizeAfter === "number" && sizeAfter > 0) {
5101+
return sizeAfter;
50945102
}
50955103
return 0;
50965104
} catch (error) {

0 commit comments

Comments
 (0)