perf: don't fetch custom emoji on every page load (#1451)

fixes #812

follow-up to #1448 and #1450
This commit is contained in:
Nolan Lawson 2019-08-29 19:15:30 -07:00 committed by GitHub
parent ebd10a43d2
commit de27d0e2bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 6 deletions

View file

@ -1,10 +1,13 @@
import { cacheFirstUpdateAfter } from '../_utils/sync' import {
cacheFirstUpdateAfter,
cacheFirstUpdateOnlyIfNotInCache
} from '../_utils/sync'
import { database } from '../_database/database' import { database } from '../_database/database'
import { getCustomEmoji } from '../_api/emoji' import { getCustomEmoji } from '../_api/emoji'
import { store } from '../_store/store' import { store } from '../_store/store'
export async function updateCustomEmojiForInstance (instanceName) { async function syncEmojiForInstance (instanceName, syncMethod) {
await cacheFirstUpdateAfter( await syncMethod(
() => getCustomEmoji(instanceName), () => getCustomEmoji(instanceName),
() => database.getCustomEmoji(instanceName), () => database.getCustomEmoji(instanceName),
emoji => database.setCustomEmoji(instanceName, emoji), emoji => database.setCustomEmoji(instanceName, emoji),
@ -16,6 +19,14 @@ export async function updateCustomEmojiForInstance (instanceName) {
) )
} }
export async function updateCustomEmojiForInstance (instanceName) {
await syncEmojiForInstance(instanceName, cacheFirstUpdateAfter)
}
export async function setupCustomEmojiForInstance (instanceName) {
await syncEmojiForInstance(instanceName, cacheFirstUpdateOnlyIfNotInCache)
}
export function insertEmoji (realm, emoji) { export function insertEmoji (realm, emoji) {
const emojiText = emoji.custom ? emoji.colons : emoji.native const emojiText = emoji.custom ? emoji.colons : emoji.native
const { composeSelectionStart } = store.get() const { composeSelectionStart } = store.get()

View file

@ -68,6 +68,7 @@
import { toggleContentWarningShown } from '../../_actions/contentWarnings' import { toggleContentWarningShown } from '../../_actions/contentWarnings'
import { mediaAccept } from '../../_static/media' import { mediaAccept } from '../../_static/media'
import { enablePoll, disablePoll } from '../../_actions/composePoll' import { enablePoll, disablePoll } from '../../_actions/composePoll'
import { updateCustomEmojiForInstance } from '../../_actions/emoji'
export default { export default {
components: { components: {
@ -80,7 +81,11 @@
methods: { methods: {
async onEmojiClick () { async onEmojiClick () {
const { realm } = this.get() const { realm } = this.get()
const showEmojiDialog = await importShowEmojiDialog() const { currentInstance } = this.store.get()
const [showEmojiDialog] = await Promise.all([
importShowEmojiDialog(),
updateCustomEmojiForInstance(currentInstance)
])
showEmojiDialog(realm) showEmojiDialog(realm)
}, },
onMediaClick () { onMediaClick () {

View file

@ -2,7 +2,7 @@ import { updateInstanceInfo, updateVerifyCredentialsForInstance } from '../../_a
import { setupListsForInstance } from '../../_actions/lists' import { setupListsForInstance } from '../../_actions/lists'
import { createStream } from '../../_actions/stream/streaming' import { createStream } from '../../_actions/stream/streaming'
import { updatePushSubscriptionForInstance } from '../../_actions/pushSubscription' import { updatePushSubscriptionForInstance } from '../../_actions/pushSubscription'
import { updateCustomEmojiForInstance } from '../../_actions/emoji' import { setupCustomEmojiForInstance } from '../../_actions/emoji'
import { scheduleIdleTask } from '../../_utils/scheduleIdleTask' import { scheduleIdleTask } from '../../_utils/scheduleIdleTask'
import { mark, stop } from '../../_utils/marks' import { mark, stop } from '../../_utils/marks'
import { store } from '../store' import { store } from '../store'
@ -41,7 +41,7 @@ async function doRefreshInstanceDataAndStream (store, instanceName) {
async function refreshInstanceData (instanceName) { async function refreshInstanceData (instanceName) {
// these are all low-priority // these are all low-priority
scheduleIdleTask(() => updateCustomEmojiForInstance(instanceName)) scheduleIdleTask(() => setupCustomEmojiForInstance(instanceName))
scheduleIdleTask(() => setupListsForInstance(instanceName)) scheduleIdleTask(() => setupListsForInstance(instanceName))
scheduleIdleTask(() => updatePushSubscriptionForInstance(instanceName)) scheduleIdleTask(() => updatePushSubscriptionForInstance(instanceName))