mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-06 08:47:23 +00:00
remove debug statemnts
This commit is contained in:
1 parent
6380b1980c
commit
440e02ff0e
2 files changed
+2
-63
No files matched your search
@@ -578,7 +578,6 @@ export function DMProvider({ children, config }: DMProviderProps) {
|
|||||||
let processedMessages = 0;
|
let processedMessages = 0;
|
||||||
let currentSince = sinceTimestamp || 0;
|
let currentSince = sinceTimestamp || 0;
|
||||||
|
|
||||||
console.log('[DM] loadPastNIP4Messages called with sinceTimestamp:', sinceTimestamp, '(using:', currentSince, ')');
|
|
||||||
|
|
||||||
setScanProgress(prev => ({ ...prev, nip4: { current: 0, status: SCAN_STATUS_MESSAGES.NIP4_STARTING } }));
|
setScanProgress(prev => ({ ...prev, nip4: { current: 0, status: SCAN_STATUS_MESSAGES.NIP4_STARTING } }));
|
||||||
|
|
||||||
@@ -643,7 +642,6 @@ export function DMProvider({ children, config }: DMProviderProps) {
|
|||||||
const TWO_DAYS_IN_SECONDS = 2 * 24 * 60 * 60;
|
const TWO_DAYS_IN_SECONDS = 2 * 24 * 60 * 60;
|
||||||
let currentSince = sinceTimestamp ? sinceTimestamp - TWO_DAYS_IN_SECONDS : 0;
|
let currentSince = sinceTimestamp ? sinceTimestamp - TWO_DAYS_IN_SECONDS : 0;
|
||||||
|
|
||||||
console.log('[DM] loadPastNIP17Messages called with sinceTimestamp:', sinceTimestamp, '(using:', currentSince, 'after adjusting for timestamp fuzzing)');
|
|
||||||
|
|
||||||
setScanProgress(prev => ({ ...prev, nip17: { current: 0, status: SCAN_STATUS_MESSAGES.NIP17_STARTING } }));
|
setScanProgress(prev => ({ ...prev, nip17: { current: 0, status: SCAN_STATUS_MESSAGES.NIP17_STARTING } }));
|
||||||
|
|
||||||
@@ -697,12 +695,9 @@ export function DMProvider({ children, config }: DMProviderProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (protocol === MESSAGE_PROTOCOL.NIP04) {
|
if (protocol === MESSAGE_PROTOCOL.NIP04) {
|
||||||
const fetchStartTime = performance.now();
|
|
||||||
const messages = await loadPastNIP4Messages(sinceTimestamp);
|
const messages = await loadPastNIP4Messages(sinceTimestamp);
|
||||||
console.log(`[DM] ⏱️ NIP-04 fetch from relay took ${(performance.now() - fetchStartTime).toFixed(0)}ms`);
|
|
||||||
|
|
||||||
if (messages && messages.length > 0) {
|
if (messages && messages.length > 0) {
|
||||||
const processStartTime = performance.now();
|
|
||||||
const newState = new Map();
|
const newState = new Map();
|
||||||
|
|
||||||
for (const message of messages) {
|
for (const message of messages) {
|
||||||
@@ -740,7 +735,6 @@ export function DMProvider({ children, config }: DMProviderProps) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mergeMessagesIntoState(newState);
|
mergeMessagesIntoState(newState);
|
||||||
console.log(`[DM] ⏱️ NIP-04 processing (decrypt + merge) took ${(performance.now() - processStartTime).toFixed(0)}ms`);
|
|
||||||
|
|
||||||
const currentTime = Math.floor(Date.now() / 1000);
|
const currentTime = Math.floor(Date.now() / 1000);
|
||||||
setLastSync(prev => ({ ...prev, nip4: currentTime }));
|
setLastSync(prev => ({ ...prev, nip4: currentTime }));
|
||||||
@@ -756,12 +750,9 @@ export function DMProvider({ children, config }: DMProviderProps) {
|
|||||||
return { lastMessageTimestamp: sinceTimestamp, messageCount: 0 };
|
return { lastMessageTimestamp: sinceTimestamp, messageCount: 0 };
|
||||||
}
|
}
|
||||||
} else if (protocol === MESSAGE_PROTOCOL.NIP17) {
|
} else if (protocol === MESSAGE_PROTOCOL.NIP17) {
|
||||||
const fetchStartTime = performance.now();
|
|
||||||
const messages = await loadPastNIP17Messages(sinceTimestamp);
|
const messages = await loadPastNIP17Messages(sinceTimestamp);
|
||||||
console.log(`[DM] ⏱️ NIP-17 fetch from relay took ${(performance.now() - fetchStartTime).toFixed(0)}ms`);
|
|
||||||
|
|
||||||
if (messages && messages.length > 0) {
|
if (messages && messages.length > 0) {
|
||||||
const processStartTime = performance.now();
|
|
||||||
const newState = new Map();
|
const newState = new Map();
|
||||||
|
|
||||||
for (const giftWrap of messages) {
|
for (const giftWrap of messages) {
|
||||||
@@ -798,7 +789,6 @@ export function DMProvider({ children, config }: DMProviderProps) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mergeMessagesIntoState(newState);
|
mergeMessagesIntoState(newState);
|
||||||
console.log(`[DM] ⏱️ NIP-17 processing (decrypt + merge) took ${(performance.now() - processStartTime).toFixed(0)}ms`);
|
|
||||||
|
|
||||||
const currentTime = Math.floor(Date.now() / 1000);
|
const currentTime = Math.floor(Date.now() / 1000);
|
||||||
setLastSync(prev => ({ ...prev, nip17: currentTime }));
|
setLastSync(prev => ({ ...prev, nip17: currentTime }));
|
||||||
@@ -1243,9 +1233,7 @@ export function DMProvider({ children, config }: DMProviderProps) {
|
|||||||
try {
|
try {
|
||||||
const { readMessagesFromDB } = await import('@/lib/dmMessageStore');
|
const { readMessagesFromDB } = await import('@/lib/dmMessageStore');
|
||||||
|
|
||||||
const dbReadStart = performance.now();
|
|
||||||
const cachedStore = await readMessagesFromDB(userPubkey);
|
const cachedStore = await readMessagesFromDB(userPubkey);
|
||||||
console.log(`[DM] ⏱️ IndexedDB read + decrypt took ${(performance.now() - dbReadStart).toFixed(0)}ms`);
|
|
||||||
|
|
||||||
if (!cachedStore || Object.keys(cachedStore.participants).length === 0) {
|
if (!cachedStore || Object.keys(cachedStore.participants).length === 0) {
|
||||||
return {};
|
return {};
|
||||||
@@ -1258,14 +1246,10 @@ export function DMProvider({ children, config }: DMProviderProps) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const newState = new Map();
|
const newState = new Map();
|
||||||
let messageCount = 0;
|
|
||||||
|
|
||||||
// Decrypt each message individually (they're stored in original encrypted form)
|
// Decrypt each message individually (they're stored in original encrypted form)
|
||||||
const decryptStartTime = performance.now();
|
|
||||||
for (const [participantPubkey, participant] of Object.entries(filteredParticipants)) {
|
for (const [participantPubkey, participant] of Object.entries(filteredParticipants)) {
|
||||||
const processedMessages = await Promise.all(participant.messages.map(async (msg) => {
|
const processedMessages = await Promise.all(participant.messages.map(async (msg) => {
|
||||||
messageCount++;
|
|
||||||
|
|
||||||
// Decrypt based on message kind
|
// Decrypt based on message kind
|
||||||
let decryptedContent: string | undefined;
|
let decryptedContent: string | undefined;
|
||||||
let error: string | undefined;
|
let error: string | undefined;
|
||||||
@@ -1319,14 +1303,10 @@ export function DMProvider({ children, config }: DMProviderProps) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[DM] ⏱️ Decrypted ${messageCount} messages in ${(performance.now() - decryptStartTime).toFixed(0)}ms`);
|
|
||||||
|
|
||||||
const setStateStart = performance.now();
|
|
||||||
setMessages(newState);
|
setMessages(newState);
|
||||||
if (cachedStore.lastSync) {
|
if (cachedStore.lastSync) {
|
||||||
setLastSync(cachedStore.lastSync);
|
setLastSync(cachedStore.lastSync);
|
||||||
}
|
}
|
||||||
console.log(`[DM] ⏱️ Setting state took ${(performance.now() - setStateStart).toFixed(0)}ms`);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
nip4Since: cachedStore.lastSync?.nip4 || undefined,
|
nip4Since: cachedStore.lastSync?.nip4 || undefined,
|
||||||
@@ -1342,17 +1322,12 @@ export function DMProvider({ children, config }: DMProviderProps) {
|
|||||||
const startMessageLoading = useCallback(async () => {
|
const startMessageLoading = useCallback(async () => {
|
||||||
if (isLoading) return;
|
if (isLoading) return;
|
||||||
|
|
||||||
const startTime = performance.now();
|
|
||||||
console.log('[DM] ⏱️ Starting message loading...');
|
|
||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setLoadingPhase(LOADING_PHASES.CACHE);
|
setLoadingPhase(LOADING_PHASES.CACHE);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// ===== PHASE 1: Load cache and show immediately =====
|
// ===== PHASE 1: Load cache and show immediately =====
|
||||||
const cacheStartTime = performance.now();
|
|
||||||
const { nip4Since, nip17Since } = await loadAllCachedMessages();
|
const { nip4Since, nip17Since } = await loadAllCachedMessages();
|
||||||
console.log(`[DM] ⏱️ Cache load took ${(performance.now() - cacheStartTime).toFixed(0)}ms`);
|
|
||||||
|
|
||||||
// Mark as completed BEFORE releasing isLoading to prevent re-trigger
|
// Mark as completed BEFORE releasing isLoading to prevent re-trigger
|
||||||
setHasInitialLoadCompleted(true);
|
setHasInitialLoadCompleted(true);
|
||||||
@@ -1360,54 +1335,30 @@ export function DMProvider({ children, config }: DMProviderProps) {
|
|||||||
// Show cached messages immediately! Don't wait for relays
|
// Show cached messages immediately! Don't wait for relays
|
||||||
setLoadingPhase(LOADING_PHASES.READY);
|
setLoadingPhase(LOADING_PHASES.READY);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
const cacheOnlyTime = performance.now() - startTime;
|
|
||||||
console.log(`[DM] ⏱️ UI ready (cache only): ${cacheOnlyTime.toFixed(0)}ms`);
|
|
||||||
|
|
||||||
// ===== PHASE 2: Query relays in background (non-blocking, parallel) =====
|
// ===== PHASE 2: Query relays in background (non-blocking, parallel) =====
|
||||||
console.log('[DM] 🔄 Querying relays in background...', { nip4Since, nip17Since });
|
|
||||||
setLoadingPhase(LOADING_PHASES.RELAYS);
|
setLoadingPhase(LOADING_PHASES.RELAYS);
|
||||||
|
|
||||||
const relayStartTime = performance.now();
|
|
||||||
|
|
||||||
// Run NIP-04 and NIP-17 queries IN PARALLEL
|
// Run NIP-04 and NIP-17 queries IN PARALLEL
|
||||||
const [nip4Result, nip17Result] = await Promise.all([
|
const [nip4Result, nip17Result] = await Promise.all([
|
||||||
(async () => {
|
queryRelaysForMessagesSince(MESSAGE_PROTOCOL.NIP04, nip4Since),
|
||||||
const nip4StartTime = performance.now();
|
enableNIP17 ? queryRelaysForMessagesSince(MESSAGE_PROTOCOL.NIP17, nip17Since) : Promise.resolve({ lastMessageTimestamp: undefined, messageCount: 0 })
|
||||||
const result = await queryRelaysForMessagesSince(MESSAGE_PROTOCOL.NIP04, nip4Since);
|
|
||||||
console.log(`[DM] ⏱️ NIP-04 relay query took ${(performance.now() - nip4StartTime).toFixed(0)}ms (${result.messageCount} messages)`);
|
|
||||||
return result;
|
|
||||||
})(),
|
|
||||||
enableNIP17 ? (async () => {
|
|
||||||
const nip17StartTime = performance.now();
|
|
||||||
const result = await queryRelaysForMessagesSince(MESSAGE_PROTOCOL.NIP17, nip17Since);
|
|
||||||
console.log(`[DM] ⏱️ NIP-17 relay query took ${(performance.now() - nip17StartTime).toFixed(0)}ms (${result.messageCount} messages)`);
|
|
||||||
return result;
|
|
||||||
})() : Promise.resolve({ lastMessageTimestamp: undefined, messageCount: 0 })
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const totalRelayTime = performance.now() - relayStartTime;
|
|
||||||
console.log(`[DM] ⏱️ Total relay queries (parallel): ${totalRelayTime.toFixed(0)}ms`);
|
|
||||||
|
|
||||||
const totalNewMessages = nip4Result.messageCount + (nip17Result?.messageCount || 0);
|
const totalNewMessages = nip4Result.messageCount + (nip17Result?.messageCount || 0);
|
||||||
if (totalNewMessages > 0) {
|
if (totalNewMessages > 0) {
|
||||||
setShouldSaveImmediately(true);
|
setShouldSaveImmediately(true);
|
||||||
console.log(`[DM] 📥 Received ${totalNewMessages} new messages from relays`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== PHASE 3: Setup subscriptions =====
|
// ===== PHASE 3: Setup subscriptions =====
|
||||||
setLoadingPhase(LOADING_PHASES.SUBSCRIPTIONS);
|
setLoadingPhase(LOADING_PHASES.SUBSCRIPTIONS);
|
||||||
|
|
||||||
const subStartTime = performance.now();
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
startNIP4Subscription(nip4Result.lastMessageTimestamp),
|
startNIP4Subscription(nip4Result.lastMessageTimestamp),
|
||||||
enableNIP17 ? startNIP17Subscription(nip17Result?.lastMessageTimestamp) : Promise.resolve()
|
enableNIP17 ? startNIP17Subscription(nip17Result?.lastMessageTimestamp) : Promise.resolve()
|
||||||
]);
|
]);
|
||||||
console.log(`[DM] ⏱️ Subscriptions setup took ${(performance.now() - subStartTime).toFixed(0)}ms`);
|
|
||||||
|
|
||||||
setLoadingPhase(LOADING_PHASES.READY);
|
setLoadingPhase(LOADING_PHASES.READY);
|
||||||
|
|
||||||
const totalTime = performance.now() - startTime;
|
|
||||||
console.log(`[DM] ⏱️ Total loading time (cache + background sync): ${totalTime.toFixed(0)}ms`);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[DM] Error in message loading:', error);
|
console.error('[DM] Error in message loading:', error);
|
||||||
setHasInitialLoadCompleted(true);
|
setHasInitialLoadCompleted(true);
|
||||||
@@ -1494,19 +1445,9 @@ export function DMProvider({ children, config }: DMProviderProps) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const relayChanged = previousRelayUrl.current !== appConfig.relayUrl;
|
const relayChanged = previousRelayUrl.current !== appConfig.relayUrl;
|
||||||
|
|
||||||
console.log('[DM] Relay change check:', {
|
|
||||||
previousRelay: previousRelayUrl.current,
|
|
||||||
currentRelay: appConfig.relayUrl,
|
|
||||||
relayChanged,
|
|
||||||
enabled,
|
|
||||||
userPubkey: !!userPubkey,
|
|
||||||
hasInitialLoadCompleted
|
|
||||||
});
|
|
||||||
|
|
||||||
previousRelayUrl.current = appConfig.relayUrl;
|
previousRelayUrl.current = appConfig.relayUrl;
|
||||||
|
|
||||||
if (relayChanged && enabled && userPubkey && hasInitialLoadCompleted) {
|
if (relayChanged && enabled && userPubkey && hasInitialLoadCompleted) {
|
||||||
console.log('[DM] Relay changed, clearing cache and refetching...');
|
|
||||||
clearCacheAndRefetch();
|
clearCacheAndRefetch();
|
||||||
}
|
}
|
||||||
}, [enabled, userPubkey, appConfig.relayUrl, hasInitialLoadCompleted, clearCacheAndRefetch]);
|
}, [enabled, userPubkey, appConfig.relayUrl, hasInitialLoadCompleted, clearCacheAndRefetch]);
|
||||||
@@ -1536,7 +1477,6 @@ export function DMProvider({ children, config }: DMProviderProps) {
|
|||||||
try {
|
try {
|
||||||
const shouldClearCache = sessionStorage.getItem('dm-clear-cache-on-load');
|
const shouldClearCache = sessionStorage.getItem('dm-clear-cache-on-load');
|
||||||
if (shouldClearCache) {
|
if (shouldClearCache) {
|
||||||
console.log('[DM] Hard refresh detected, clearing cache and refetching messages...');
|
|
||||||
sessionStorage.removeItem('dm-clear-cache-on-load');
|
sessionStorage.removeItem('dm-clear-cache-on-load');
|
||||||
clearCacheAndRefetch();
|
clearCacheAndRefetch();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ export async function writeMessagesToDB(
|
|||||||
// Store messages in their original encrypted form (no NIP-44 wrapper needed)
|
// Store messages in their original encrypted form (no NIP-44 wrapper needed)
|
||||||
// Each message content is already encrypted by the sender
|
// Each message content is already encrypted by the sender
|
||||||
await db.put(STORE_NAME, messageStore, userPubkey);
|
await db.put(STORE_NAME, messageStore, userPubkey);
|
||||||
console.log('[MessageStore] ✅ Cached', Object.keys(messageStore.participants).length, 'conversations');
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[MessageStore] ❌ Error writing to IndexedDB:', error);
|
console.error('[MessageStore] ❌ Error writing to IndexedDB:', error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
Reference in new issue
Block a user