Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: skip message skeleton if it is cached #10750

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
52 changes: 35 additions & 17 deletions src/components/ThreadEnvelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@
</template>
</div>
</div>
<MessageLoadingSkeleton v-if="loading !== LOADING_DONE" />
<Message v-if="message && loading !== LOADING_MESSAGE"
v-show="loading === LOADING_DONE"
<MessageLoadingSkeleton v-if="loading === Loading.Skeleton" />
<Message v-if="message"
v-show="loading === Loading.Done"
:envelope="envelope"
:message="message"
:full-height="fullHeight"
:smart-replies="showFollowUpHeader ? [] : smartReplies"
:reply-button-label="replyButtonLabel"
@load="loading = LOADING_DONE"
@load="onMessageLoaded"
@reply="(body) => onReply(body, showFollowUpHeader)" />
<Error v-else-if="error"
:error="error.message || t('mail', 'Not found')"
Expand Down Expand Up @@ -317,9 +317,11 @@
import { mapStores } from 'pinia'

// Ternary loading state
const LOADING_DONE = 0
const LOADING_MESSAGE = 1
const LOADING_BODY = 2
const Loading = Object.seal({
Done: 0,
Silent: 1,
Skeleton: 2,
})

export default {
name: 'ThreadEnvelope',
Expand Down Expand Up @@ -389,16 +391,14 @@
},
data() {
return {
loading: LOADING_DONE,
loading: Loading.Done,
showListUnsubscribeConfirmation: false,
error: undefined,
message: undefined,
importantSvg,
unsubscribing: false,
seenTimer: undefined,
LOADING_BODY,
LOADING_DONE,
LOADING_MESSAGE,
Loading,
recomputeMenuSize: 0,
moreActionsOpen: false,
smartReplies: [],
Expand All @@ -412,6 +412,7 @@
rawMessage: '', // Will hold the raw source of the message when requested
isInternal: true,
enabledSmartReply: loadState('mail', 'llm_freeprompt_available', false),
loadingBodyTimeout: undefined,
}
},
computed: {
Expand Down Expand Up @@ -590,7 +591,7 @@
this.fetchMessage()
} else {
this.message = undefined
this.loading = LOADING_DONE
this.loading = Loading.Done
}
},
},
Expand Down Expand Up @@ -632,16 +633,33 @@
filterSubject(value) {
return value.replace(/((?:[\t ]*(?:R|RE|F|FW|FWD):[\t ]*)*)/i, '')
},
onMessageLoaded() {
if (this.loadingBodyTimeout) {
clearTimeout(this.loadingBodyTimeout)
this.loadingBodyTimeout = undefined
}

this.loading = Loading.Done
},
async fetchMessage() {
this.loading = LOADING_MESSAGE
this.error = undefined
let loadingTimeout
const isCached = !!this.mainStore.getMessage(this.envelope.databaseId)
if (!isCached) {
loadingTimeout = setTimeout(() => this.loading = Loading.Skeleton, 200)

Check failure on line 648 in src/components/ThreadEnvelope.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Arrow function should not return assignment
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint complains about the assignment as only expression of the array function

}

this.loading = Loading.Silent
this.error = undefined
logger.debug(`fetching thread message ${this.envelope.databaseId}`)

try {
this.message = await this.mainStore.fetchMessage(this.envelope.databaseId)
logger.debug(`message ${this.envelope.databaseId} fetched`, { message: this.message })

if (loadingTimeout) {
clearTimeout(loadingTimeout)
}

if (!this.envelope.flags.seen && this.hasSeenAcl) {
logger.info('Starting timer to mark message as seen/read')
this.seenTimer = setTimeout(() => {
Expand All @@ -651,13 +669,13 @@
}

if (this.message.hasHtmlBody) {
this.loading = LOADING_BODY
this.loadingBodyTimeout = setTimeout(() => this.loading = Loading.Skeleton, 200)

Check failure on line 672 in src/components/ThreadEnvelope.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Arrow function should not return assignment
} else {
this.loading = LOADING_DONE
this.loading = Loading.Done
}
} catch (error) {
this.error = error
this.loading = LOADING_DONE
this.loading = Loading.Done
logger.error('Could not fetch message', { error })
}

Expand Down
4 changes: 4 additions & 0 deletions src/store/mainStore/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,10 @@ export default function mainStoreActions() {
})
},
async fetchMessage(id) {
if (this.messages[id]) {
return this.messages[id]
}

return handleHttpAuthErrors(async () => {
const message = await fetchMessage(id)
// Only commit if not undefined (not found)
Expand Down
Loading