Phase 790: GUILD_SYNC guildEmojis slice and guild-sync-ready emojis count.
Export/ingest custom emoji bundles; emoji gossip emits structural sync-ready. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -475,6 +475,61 @@ async _ingestReactionsSyncBundle (reactions = []) {
|
||||
return changed
|
||||
},
|
||||
|
||||
async _exportGuildEmojisForSyncBundle (guildId) {
|
||||
if (!guildId) return []
|
||||
await this._initEmojiRegistry(guildId)
|
||||
if (!this.emojiRegistry) return []
|
||||
const rows = await this.emojiRegistry.list().catch(() => [])
|
||||
return rows
|
||||
.filter((e) => !e.builtin)
|
||||
.slice(0, 128)
|
||||
.map((e) => ({
|
||||
guildId: e.guildId || guildId,
|
||||
name: e.name,
|
||||
kind: e.kind || 'unicode',
|
||||
glyph: e.glyph || '',
|
||||
description: e.description || '',
|
||||
packName: e.packName || null,
|
||||
imageAttachmentId: e.imageAttachmentId || null,
|
||||
mimeType: e.mimeType || null,
|
||||
allowedRoles: e.allowedRoles || [],
|
||||
updatedAt: hyperdbScope.coerceSyncUint(e.updatedAt, 0),
|
||||
tombstone: false
|
||||
}))
|
||||
},
|
||||
|
||||
async _ingestGuildEmojisSyncBundle (rows = []) {
|
||||
const span = this.log.time('guild.sync.emojis', {
|
||||
spanKind: 'guild.sync.emojis',
|
||||
guildId: this.guild?.guild?.id,
|
||||
count: rows?.length || 0
|
||||
})
|
||||
let changed = 0
|
||||
const guildId = this.guild?.guild?.id
|
||||
if (!guildId) {
|
||||
span.end({ changed: 0, rows: 0 })
|
||||
return 0
|
||||
}
|
||||
await this._initEmojiRegistry(guildId)
|
||||
if (!this.emojiRegistry) {
|
||||
span.end({ changed: 0, rows: 0 })
|
||||
return 0
|
||||
}
|
||||
for (const r of rows) {
|
||||
if (!r?.name) continue
|
||||
if (r.tombstone || r.removed) {
|
||||
const removed = await this.emojiRegistry.remove(r.name).catch(() => null)
|
||||
if (removed) changed += 1
|
||||
continue
|
||||
}
|
||||
const out = await this.emojiRegistry.ingestGossip(r)
|
||||
if (out) changed += 1
|
||||
}
|
||||
span.end({ changed, rows: rows?.length || 0 })
|
||||
if (changed > 0) this.emit('guild-emoji', { batch: true })
|
||||
return changed
|
||||
},
|
||||
|
||||
async _ingestPresenceVectorBundle (guildId, rows = []) {
|
||||
const span = this.log.time('guild.sync.presence', {
|
||||
spanKind: 'guild.sync.presence',
|
||||
@@ -843,6 +898,7 @@ async _buildGuildSyncBundle (limitPerChannel, opts = {}) {
|
||||
guild.id,
|
||||
{ syncDelta, visibleOnly: true }
|
||||
)
|
||||
const guildEmojis = await this._exportGuildEmojisForSyncBundle(guild.id)
|
||||
const pins = await this._exportPinsForSyncBundle(
|
||||
guild.id,
|
||||
syncChannels.map((c) => c.id),
|
||||
@@ -955,6 +1011,7 @@ async _buildGuildSyncBundle (limitPerChannel, opts = {}) {
|
||||
sinceMessageId: syncDelta ? sinceId : null,
|
||||
channelCoreKeys,
|
||||
reactions,
|
||||
guildEmojis,
|
||||
presenceVector: this._exportPresenceVectorForSync(guild.id),
|
||||
forumIndex,
|
||||
voiceOccupancy,
|
||||
|
||||
@@ -596,6 +596,7 @@ async _ingestGuildSync (payload) {
|
||||
).catch(() => 0)) || 0
|
||||
}
|
||||
const reactionChanges = await this._ingestReactionsSyncBundle(payload.reactions || [])
|
||||
const emojiChanges = await this._ingestGuildEmojisSyncBundle(payload.guildEmojis || [])
|
||||
let sparse = { mode: 'gossip', added: 0 }
|
||||
if (payload.channelCoreKeys?.length) {
|
||||
this._lastGuildSyncChannelCoreKeys = payload.channelCoreKeys.slice(0, 96)
|
||||
@@ -627,6 +628,7 @@ async _ingestGuildSync (payload) {
|
||||
voice: voiceApplied,
|
||||
roles: rolesApplied,
|
||||
reactions: reactionChanges,
|
||||
emojis: emojiChanges,
|
||||
sparse,
|
||||
attachPull,
|
||||
ingestMs
|
||||
|
||||
@@ -18,6 +18,12 @@ const platformGuildSyncWireSparseMixin = {
|
||||
createdAt: hyperdbScope.coerceSyncUint(r.createdAt, 0)
|
||||
}))
|
||||
}
|
||||
if (Array.isArray(next.guildEmojis)) {
|
||||
next.guildEmojis = next.guildEmojis.map((e) => ({
|
||||
...e,
|
||||
updatedAt: hyperdbScope.coerceSyncUint(e.updatedAt, 0)
|
||||
}))
|
||||
}
|
||||
return next
|
||||
},
|
||||
|
||||
|
||||
@@ -259,6 +259,7 @@ _wireGuild (guildInstance) {
|
||||
(payload?.guildRoles?.length || 0) +
|
||||
(payload?.memberRoleLinks?.length || 0)
|
||||
const payloadReactions = payload?.reactions?.length || 0
|
||||
const payloadEmojis = payload?.guildEmojis?.length || 0
|
||||
const hasSlice =
|
||||
payloadMsgs > 0 ||
|
||||
payloadMems > 0 ||
|
||||
@@ -266,7 +267,8 @@ _wireGuild (guildInstance) {
|
||||
payloadChans > 0 ||
|
||||
payloadVoice > 0 ||
|
||||
payloadRoles > 0 ||
|
||||
payloadReactions > 0
|
||||
payloadReactions > 0 ||
|
||||
payloadEmojis > 0
|
||||
if (!result && !hasSlice) return
|
||||
this._lastGuildSyncIngestAt = Date.now()
|
||||
const msgCount =
|
||||
@@ -297,6 +299,10 @@ _wireGuild (guildInstance) {
|
||||
typeof result === 'object'
|
||||
? Math.max(result.reactions || 0, payloadReactions)
|
||||
: payloadReactions
|
||||
const emojisCount =
|
||||
typeof result === 'object'
|
||||
? Math.max(result.emojis || 0, payloadEmojis)
|
||||
: payloadEmojis
|
||||
if (
|
||||
msgCount > 0 ||
|
||||
memCount > 0 ||
|
||||
@@ -305,6 +311,7 @@ _wireGuild (guildInstance) {
|
||||
voiceCount > 0 ||
|
||||
rolesCount > 0 ||
|
||||
reactionsCount > 0 ||
|
||||
emojisCount > 0 ||
|
||||
hasSlice
|
||||
) {
|
||||
this.emit('guild-sync-ready', {
|
||||
@@ -315,7 +322,8 @@ _wireGuild (guildInstance) {
|
||||
channels: chanCount,
|
||||
voice: voiceCount,
|
||||
roles: rolesCount,
|
||||
reactions: reactionsCount
|
||||
reactions: reactionsCount,
|
||||
emojis: emojisCount
|
||||
})
|
||||
if (payload?.guildId === this.guild?.guild?.id) {
|
||||
this._touchAllGuildMeshPeersSeen(payload.guildId, 'guild-sync')
|
||||
@@ -537,10 +545,14 @@ _wireGuild (guildInstance) {
|
||||
this.log.debug('emoji attachment prefetch failed', { name: row?.name, err })
|
||||
})
|
||||
this.emit('guild-emoji', row)
|
||||
const gid = this.guild?.guild?.id
|
||||
if (gid) this.emit('guild-sync-ready', { guildId: gid, emojis: 1 })
|
||||
})
|
||||
guildInstance.on('guild-emoji-delete', (payload) => {
|
||||
this.emojiRegistry?.ingestDeleteGossip(payload).catch(() => {})
|
||||
this.emit('guild-emoji-delete', payload)
|
||||
const gid = this.guild?.guild?.id
|
||||
if (gid) this.emit('guild-sync-ready', { guildId: gid, emojis: 1 })
|
||||
})
|
||||
guildInstance.on('guild-emoji-pack', (row) => {
|
||||
this.emojiRegistry?.ingestPackGossip(row).catch(() => {})
|
||||
|
||||
Reference in New Issue
Block a user