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 { getCustomEmoji } from '../_api/emoji'
import { store } from '../_store/store'
export async function updateCustomEmojiForInstance (instanceName) {
await cacheFirstUpdateAfter(
async function syncEmojiForInstance (instanceName, syncMethod) {
await syncMethod(
() => getCustomEmoji(instanceName),
() => database.getCustomEmoji(instanceName),
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) {
const emojiText = emoji.custom ? emoji.colons : emoji.native
const { composeSelectionStart } = store.get()

View File

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

View File

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