perf: don't fetch custom emoji on every page load (#1451)
fixes #812 follow-up to #1448 and #1450
This commit is contained in:
parent
ebd10a43d2
commit
de27d0e2bf
|
@ -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()
|
||||||
|
|
|
@ -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 () {
|
||||||
|
|
|
@ -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))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue