mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
- Introduce `js/constants.js` with semantic time constants (e.g., `ONE_MINUTE_MS`, `STANDARD_TIMEOUT_MS`) and feature-specific TTLs. - Export `KIND_MUTE_LIST` from `js/nostrEventSchemas.js` to standardize NIP-51 mute list kind usage. - Refactor `js/state/cache.js`, `js/nostr/cachePolicies.js`, `js/channelProfile.js`, and various services to use centralized constants instead of hardcoded magic numbers. - Update `js/nostr/relayConstants.js` to derive values from the shared time constants. - Replace duplicate definitions of timeouts and retry delays across the codebase. Co-authored-by: PR0M3TH3AN <[email protected]>
98 lines
2.8 KiB
JavaScript
98 lines
2.8 KiB
JavaScript
import { NOTE_TYPES } from "../nostrEventSchemas.js";
|
|
import { WATCH_HISTORY_LIST_IDENTIFIER } from "../config.js";
|
|
import { FIVE_MINUTES_MS, TEN_MINUTES_MS, ONE_DAY_MS } from "../constants.js";
|
|
|
|
export const STORAGE_TIERS = Object.freeze({
|
|
MEMORY: "memory",
|
|
INDEXED_DB: "indexedDB",
|
|
LOCAL_STORAGE: "localStorage",
|
|
});
|
|
|
|
export const MERGE_STRATEGIES = Object.freeze({
|
|
REPLACEABLE: "replaceable",
|
|
APPEND_ONLY: "append-only",
|
|
});
|
|
|
|
export const CACHE_POLICIES = Object.freeze({
|
|
[NOTE_TYPES.VIDEO_POST]: {
|
|
storage: STORAGE_TIERS.INDEXED_DB,
|
|
ttl: TEN_MINUTES_MS,
|
|
addressing: "kind:pubkey:d",
|
|
merge: MERGE_STRATEGIES.REPLACEABLE,
|
|
},
|
|
[NOTE_TYPES.WATCH_HISTORY]: {
|
|
storage: STORAGE_TIERS.LOCAL_STORAGE,
|
|
ttl: ONE_DAY_MS,
|
|
addressing: "kind:pubkey:d",
|
|
defaultDTag: WATCH_HISTORY_LIST_IDENTIFIER,
|
|
merge: MERGE_STRATEGIES.APPEND_ONLY, // Bucketed append
|
|
},
|
|
[NOTE_TYPES.SUBSCRIPTION_LIST]: {
|
|
storage: STORAGE_TIERS.LOCAL_STORAGE,
|
|
ttl: Infinity, // Manual management
|
|
addressing: "kind:pubkey:d",
|
|
merge: MERGE_STRATEGIES.REPLACEABLE,
|
|
},
|
|
[NOTE_TYPES.USER_BLOCK_LIST]: {
|
|
storage: STORAGE_TIERS.LOCAL_STORAGE,
|
|
ttl: Infinity, // Manual management
|
|
addressing: "kind:pubkey:d",
|
|
merge: MERGE_STRATEGIES.REPLACEABLE,
|
|
},
|
|
[NOTE_TYPES.RELAY_LIST]: {
|
|
storage: STORAGE_TIERS.LOCAL_STORAGE,
|
|
ttl: Infinity, // Manual management
|
|
addressing: "kind:pubkey",
|
|
merge: MERGE_STRATEGIES.REPLACEABLE,
|
|
},
|
|
[NOTE_TYPES.ADMIN_MODERATION_LIST]: {
|
|
storage: STORAGE_TIERS.LOCAL_STORAGE,
|
|
ttl: Infinity,
|
|
addressing: "kind:pubkey:d",
|
|
merge: MERGE_STRATEGIES.REPLACEABLE,
|
|
},
|
|
[NOTE_TYPES.ADMIN_BLACKLIST]: {
|
|
storage: STORAGE_TIERS.LOCAL_STORAGE,
|
|
ttl: Infinity,
|
|
addressing: "kind:pubkey:d",
|
|
merge: MERGE_STRATEGIES.REPLACEABLE,
|
|
},
|
|
[NOTE_TYPES.ADMIN_WHITELIST]: {
|
|
storage: STORAGE_TIERS.LOCAL_STORAGE,
|
|
ttl: Infinity,
|
|
addressing: "kind:pubkey:d",
|
|
merge: MERGE_STRATEGIES.REPLACEABLE,
|
|
},
|
|
[NOTE_TYPES.VIDEO_COMMENT]: {
|
|
storage: STORAGE_TIERS.MEMORY,
|
|
ttl: FIVE_MINUTES_MS,
|
|
addressing: "id",
|
|
merge: MERGE_STRATEGIES.APPEND_ONLY,
|
|
},
|
|
[NOTE_TYPES.VIDEO_REACTION]: {
|
|
storage: STORAGE_TIERS.MEMORY,
|
|
ttl: FIVE_MINUTES_MS,
|
|
addressing: "id",
|
|
merge: MERGE_STRATEGIES.APPEND_ONLY,
|
|
},
|
|
[NOTE_TYPES.VIEW_EVENT]: {
|
|
storage: STORAGE_TIERS.MEMORY,
|
|
ttl: 0,
|
|
addressing: "id",
|
|
merge: MERGE_STRATEGIES.APPEND_ONLY,
|
|
},
|
|
[NOTE_TYPES.HASHTAG_PREFERENCES]: {
|
|
storage: STORAGE_TIERS.LOCAL_STORAGE,
|
|
ttl: Infinity,
|
|
addressing: "kind:pubkey:d",
|
|
defaultDTag: "bitvid:tag-preferences",
|
|
merge: MERGE_STRATEGIES.REPLACEABLE,
|
|
},
|
|
[NOTE_TYPES.PROFILE_METADATA]: {
|
|
storage: STORAGE_TIERS.LOCAL_STORAGE,
|
|
ttl: Infinity,
|
|
addressing: "kind:pubkey",
|
|
merge: MERGE_STRATEGIES.REPLACEABLE,
|
|
},
|
|
});
|