Skip to content

Commit 0b24ad3

Browse files
committed
debug: add comprehensive console logging to investigate pagination hang
Add extensive console logging to track the flow of chunked note loading: - NotesService.fetchNotes(): Log API calls, response structure, and update paths - App.loadNotes(): Log initial load flow and cursor management - NotesView.onEndOfNotes(): Log scroll trigger, cursor state, and display count updates This will help diagnose why the pagination is still hanging despite the chunked loading implementation. The logging will show: - When and with what parameters fetchNotes is called - What data structure is returned from the API - Which update path is taken (incremental vs full) - How the cursor and display count are being managed
1 parent 5d1e727 commit 0b24ad3

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

src/App.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,22 @@ export default {
131131
132132
methods: {
133133
async loadNotes() {
134+
console.log('[App.loadNotes] Starting initial load')
134135
try {
135136
// Load only the first chunk on initial load (50 notes)
136137
// Subsequent chunks will be loaded on-demand when scrolling
137138
const data = await fetchNotes(50, null)
139+
console.log('[App.loadNotes] fetchNotes returned:', data)
138140
139141
if (data === null) {
140142
// nothing changed (304 response)
143+
console.log('[App.loadNotes] 304 Not Modified - no changes')
141144
return
142145
}
143146
144147
if (data && data.noteIds) {
148+
console.log('[App.loadNotes] Success - received', data.noteIds.length, 'note IDs')
149+
console.log('[App.loadNotes] Next cursor:', data.chunkCursor)
145150
this.error = false
146151
// Route to default note after first chunk
147152
this.routeDefault(0)
@@ -150,6 +155,7 @@ export default {
150155
store.commit('setNotesChunkCursor', data.chunkCursor || null)
151156
} else if (this.loading.notes) {
152157
// only show error state if not loading in background
158+
console.log('[App.loadNotes] Error - no noteIds in response')
153159
this.error = data?.errorMessage || true
154160
} else {
155161
console.error('Server error while updating list of notes: ' + (data?.errorMessage || 'Unknown error'))
@@ -159,7 +165,7 @@ export default {
159165
if (this.loading.notes) {
160166
this.error = true
161167
}
162-
console.error('Failed to load notes:', err)
168+
console.error('[App.loadNotes] Exception:', err)
163169
} finally {
164170
this.loading.notes = false
165171
this.startRefreshTimer(config.interval.notes.refresh)

src/NotesService.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export const getDashboardData = () => {
7474
}
7575

7676
export const fetchNotes = async (chunkSize = 50, chunkCursor = null) => {
77+
console.log('[fetchNotes] Called with chunkSize:', chunkSize, 'cursor:', chunkCursor)
7778
const lastETag = store.state.sync.etag
7879
const lastModified = store.state.sync.lastModified
7980
const headers = {}
@@ -107,27 +108,36 @@ export const fetchNotes = async (chunkSize = 50, chunkCursor = null) => {
107108
params.append('chunkCursor', chunkCursor) // Continue from previous chunk
108109
}
109110

110-
const response = await axios.get(
111-
generateUrl('/apps/notes/api/v1/notes' + (params.toString() ? '?' + params.toString() : '')),
112-
{ headers },
113-
)
111+
const url = generateUrl('/apps/notes/api/v1/notes' + (params.toString() ? '?' + params.toString() : ''))
112+
console.log('[fetchNotes] Requesting:', url)
113+
114+
const response = await axios.get(url, { headers })
115+
116+
console.log('[fetchNotes] Response received, status:', response.status)
117+
console.log('[fetchNotes] Response data type:', Array.isArray(response.data) ? 'array' : typeof response.data)
118+
console.log('[fetchNotes] Response data keys:', Object.keys(response.data || {}))
114119

115120
const data = response.data
116121
const notes = data.notes || []
117122
const noteIds = data.noteIds || notes.map(note => note.id)
118123
const nextCursor = data.chunkCursor || null
119124
const isLastChunk = !nextCursor
120125

126+
console.log('[fetchNotes] Processed:', notes.length, 'notes, noteIds:', noteIds.length, 'nextCursor:', nextCursor, 'isLastChunk:', isLastChunk)
127+
121128
// Update notes incrementally
122129
if (chunkCursor) {
123130
// Subsequent chunk - use incremental update
131+
console.log('[fetchNotes] Using incremental update for subsequent chunk')
124132
store.dispatch('updateNotesIncremental', { notes, isLastChunk })
125133
if (isLastChunk) {
126134
// Final chunk - clean up deleted notes
135+
console.log('[fetchNotes] Final chunk - cleaning up deleted notes')
127136
store.dispatch('finalizeNotesUpdate', noteIds)
128137
}
129138
} else {
130139
// First chunk - use full update
140+
console.log('[fetchNotes] Using full update for first chunk')
131141
store.dispatch('updateNotes', { noteIds, notes })
132142
}
133143

@@ -136,6 +146,7 @@ export const fetchNotes = async (chunkSize = 50, chunkCursor = null) => {
136146
store.commit('setSyncLastModified', response.headers['last-modified'])
137147
store.commit('setNotesLoadingInProgress', false)
138148

149+
console.log('[fetchNotes] Completed successfully')
139150
return {
140151
noteIds,
141152
chunkCursor: nextCursor,
@@ -144,10 +155,11 @@ export const fetchNotes = async (chunkSize = 50, chunkCursor = null) => {
144155
} catch (err) {
145156
store.commit('setNotesLoadingInProgress', false)
146157
if (err?.response?.status === 304) {
158+
console.log('[fetchNotes] 304 Not Modified - no changes')
147159
store.commit('setSyncLastModified', err.response.headers['last-modified'])
148160
return null
149161
} else {
150-
console.error(err)
162+
console.error('[fetchNotes] Error:', err)
151163
handleSyncError(t('notes', 'Fetching notes has failed.'), err)
152164
throw err
153165
}

src/components/NotesView.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ export default {
209209
},
210210
211211
async onEndOfNotes(isVisible) {
212+
console.log('[NotesView.onEndOfNotes] Triggered, isVisible:', isVisible, 'isLoadingMore:', this.isLoadingMore)
212213
// Prevent rapid-fire loading by checking if we're already loading a batch
213214
if (!isVisible || this.isLoadingMore) {
215+
console.log('[NotesView.onEndOfNotes] Skipping - not visible or already loading')
214216
return
215217
}
216218
@@ -220,33 +222,46 @@ export default {
220222
try {
221223
// Check if there are more notes to fetch from the server
222224
const chunkCursor = store.state.sync.chunkCursor
225+
console.log('[NotesView.onEndOfNotes] Current cursor:', chunkCursor)
226+
console.log('[NotesView.onEndOfNotes] displayedNotesCount:', this.displayedNotesCount, 'filteredNotes.length:', this.filteredNotes.length)
223227
224228
if (chunkCursor) {
225229
// Fetch next chunk from the API
230+
console.log('[NotesView.onEndOfNotes] Fetching next chunk from API')
226231
const data = await fetchNotes(50, chunkCursor)
232+
console.log('[NotesView.onEndOfNotes] Fetch complete, data:', data)
227233
228234
if (data && data.noteIds) {
229235
// Update cursor for next fetch
236+
console.log('[NotesView.onEndOfNotes] Updating cursor to:', data.chunkCursor)
230237
store.commit('setNotesChunkCursor', data.chunkCursor || null)
231238
232239
// Increment display count to show newly loaded notes
233-
this.displayedNotesCount = Math.min(
240+
const newCount = Math.min(
234241
this.displayedNotesCount + 50,
235242
this.filteredNotes.length
236243
)
244+
console.log('[NotesView.onEndOfNotes] Updating displayedNotesCount from', this.displayedNotesCount, 'to', newCount)
245+
this.displayedNotesCount = newCount
237246
}
238247
} else if (this.displayedNotesCount < this.filteredNotes.length) {
239248
// No more chunks to fetch, but we have cached notes to display
249+
console.log('[NotesView.onEndOfNotes] No cursor, but have cached notes to display')
240250
this.$nextTick(() => {
241-
this.displayedNotesCount = Math.min(
251+
const newCount = Math.min(
242252
this.displayedNotesCount + 50,
243253
this.filteredNotes.length
244254
)
255+
console.log('[NotesView.onEndOfNotes] Updating displayedNotesCount from', this.displayedNotesCount, 'to', newCount)
256+
this.displayedNotesCount = newCount
245257
})
258+
} else {
259+
console.log('[NotesView.onEndOfNotes] All notes loaded, nothing to do')
246260
}
247261
} finally {
248262
// Reset loading flag after operation completes
249263
this.$nextTick(() => {
264+
console.log('[NotesView.onEndOfNotes] Resetting isLoadingMore flag')
250265
this.isLoadingMore = false
251266
})
252267
}

0 commit comments

Comments
 (0)