Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/creators/update-creator.js
Show First 20 Lines • Show All 372 Lines • ▼ Show 20 Lines | const insertQuery = SQL` | ||||
INSERT INTO updates(id, user, type, \`key\`, | INSERT INTO updates(id, user, type, \`key\`, | ||||
content, time, updater, target) | content, time, updater, target) | ||||
`; | `; | ||||
insertQuery.append(SQL`VALUES ${insertRows}`); | insertQuery.append(SQL`VALUES ${insertRows}`); | ||||
promises.insert = dbQuery(insertQuery); | promises.insert = dbQuery(insertQuery); | ||||
} | } | ||||
if (publishInfos.size > 0) { | if (publishInfos.size > 0) { | ||||
promises.redis = redisPublish(publishInfos.values(), dontBroadcastSession); | promises.messageBroker = messageBrokerPublish( | ||||
publishInfos.values(), | |||||
dontBroadcastSession, | |||||
); | |||||
} | } | ||||
if (deleteSQLConditions.length > 0) { | if (deleteSQLConditions.length > 0) { | ||||
promises.delete = (async () => { | promises.delete = (async () => { | ||||
while (deleteSQLConditions.length > 0) { | while (deleteSQLConditions.length > 0) { | ||||
const batch = deleteSQLConditions.splice(0, deleteUpdatesBatchSize); | const batch = deleteSQLConditions.splice(0, deleteUpdatesBatchSize); | ||||
await deleteUpdatesByConditions(batch); | await deleteUpdatesByConditions(batch); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 318 Lines • ▼ Show 20 Lines | ): Promise<FetchUpdatesResult> { | ||||
return { updateInfos: mergedUpdates, userInfos }; | return { updateInfos: mergedUpdates, userInfos }; | ||||
} | } | ||||
type PublishInfo = { | type PublishInfo = { | ||||
updateTarget: UpdateTarget, | updateTarget: UpdateTarget, | ||||
rawUpdateInfos: RawUpdateInfo[], | rawUpdateInfos: RawUpdateInfo[], | ||||
}; | }; | ||||
async function redisPublish( | async function messageBrokerPublish( | ||||
publishInfos: Iterator<PublishInfo>, | publishInfos: Iterator<PublishInfo>, | ||||
dontBroadcastSession: ?string, | dontBroadcastSession: ?string, | ||||
): Promise<void> { | ): Promise<void> { | ||||
for (const publishInfo of publishInfos) { | for (const publishInfo of publishInfos) { | ||||
const { updateTarget, rawUpdateInfos } = publishInfo; | const { updateTarget, rawUpdateInfos } = publishInfo; | ||||
const redisMessage: NewUpdatesRedisMessage = { | const redisMessage: NewUpdatesRedisMessage = { | ||||
type: redisMessageTypes.NEW_UPDATES, | type: redisMessageTypes.NEW_UPDATES, | ||||
updates: rawUpdateInfos, | updates: rawUpdateInfos, | ||||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |