fix: reduce number of blurhash performance measures (#1395)
This commit is contained in:
parent
2c2ea6325c
commit
be3b5eb9d9
|
@ -1,6 +1,7 @@
|
||||||
import { database } from '../_database/database'
|
import { database } from '../_database/database'
|
||||||
import { decode as decodeBlurhash, init as initBlurhash } from '../_utils/blurhash'
|
import { decode as decodeBlurhash, init as initBlurhash } from '../_utils/blurhash'
|
||||||
import { mark, stop } from '../_utils/marks'
|
import { mark, stop } from '../_utils/marks'
|
||||||
|
import { get } from '../_utils/lodash-lite'
|
||||||
|
|
||||||
async function getNotification (instanceName, timelineType, timelineValue, itemId) {
|
async function getNotification (instanceName, timelineType, timelineValue, itemId) {
|
||||||
return {
|
return {
|
||||||
|
@ -28,16 +29,15 @@ function tryInitBlurhash () {
|
||||||
|
|
||||||
async function decodeAllBlurhashes (statusOrNotification) {
|
async function decodeAllBlurhashes (statusOrNotification) {
|
||||||
const status = statusOrNotification.status || statusOrNotification.notification.status
|
const status = statusOrNotification.status || statusOrNotification.notification.status
|
||||||
if (status && status.media_attachments) {
|
const mediaWithBlurhashes = get(status, ['media_attachments'], []).filter(_ => _.blurhash)
|
||||||
|
if (mediaWithBlurhashes.length) {
|
||||||
mark(`decodeBlurhash-${status.id}`)
|
mark(`decodeBlurhash-${status.id}`)
|
||||||
await Promise.all(status.media_attachments.map(async media => {
|
await Promise.all(mediaWithBlurhashes.map(async media => {
|
||||||
if (media.blurhash) {
|
|
||||||
try {
|
try {
|
||||||
media.decodedBlurhash = await decodeBlurhash(media.blurhash)
|
media.decodedBlurhash = await decodeBlurhash(media.blurhash)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('Could not decode blurhash, ignoring', err)
|
console.warn('Could not decode blurhash, ignoring', err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
stop(`decodeBlurhash-${status.id}`)
|
stop(`decodeBlurhash-${status.id}`)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue