Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/creators/message-creator.js
Show All 26 Lines | |||||
import type { UpdatesForCurrentSession } from './update-creator.js'; | import type { UpdatesForCurrentSession } from './update-creator.js'; | ||||
import { createUpdates } from './update-creator.js'; | import { createUpdates } from './update-creator.js'; | ||||
import { | import { | ||||
dbQuery, | dbQuery, | ||||
SQL, | SQL, | ||||
appendSQLArray, | appendSQLArray, | ||||
mergeOrConditions, | mergeOrConditions, | ||||
} from '../database/database.js'; | } from '../database/database.js'; | ||||
import { processMessagesForSearch } from '../database/search_utils.js'; | |||||
import { | import { | ||||
fetchMessageInfoForLocalID, | fetchMessageInfoForLocalID, | ||||
fetchMessageInfoByID, | fetchMessageInfoByID, | ||||
} from '../fetchers/message-fetchers.js'; | } from '../fetchers/message-fetchers.js'; | ||||
import { fetchOtherSessionsForViewer } from '../fetchers/session-fetchers.js'; | import { fetchOtherSessionsForViewer } from '../fetchers/session-fetchers.js'; | ||||
import { fetchServerThreadInfos } from '../fetchers/thread-fetchers.js'; | import { fetchServerThreadInfos } from '../fetchers/thread-fetchers.js'; | ||||
import { sendPushNotifs, sendRescindNotifs } from '../push/send.js'; | import { sendPushNotifs, sendRescindNotifs } from '../push/send.js'; | ||||
import { handleAsyncPromise } from '../responders/handlers.js'; | import { handleAsyncPromise } from '../responders/handlers.js'; | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | ): Promise<RawMessageInfo[]> { | ||||
const messageInsertQuery = SQL` | const messageInsertQuery = SQL` | ||||
INSERT INTO messages(id, thread, user, type, content, time, | INSERT INTO messages(id, thread, user, type, content, time, | ||||
creation, target_message) | creation, target_message) | ||||
VALUES ${messageInsertRows} | VALUES ${messageInsertRows} | ||||
`; | `; | ||||
const messageInsertPromise = dbQuery(messageInsertQuery); | const messageInsertPromise = dbQuery(messageInsertQuery); | ||||
const processMessages = processMessagesForSearch(returnMessageInfos); | |||||
ashoat: We should only pass `newMessageInfos` in here. The messages that are in `returnMessageInfos`… | |||||
inkaAuthorUnsubmitted Done Inline ActionsThe indexing process is idempotent, but if we indexed a message that has a later edit, than this later edit needs to be indexed as well. Otherwise we would have the outdated content in the search table. inka: The indexing process is idempotent, but if we indexed a message that has a later edit, than… | |||||
const postMessageSendPromise = postMessageSend( | const postMessageSendPromise = postMessageSend( | ||||
viewer, | viewer, | ||||
threadsToMessageIndices, | threadsToMessageIndices, | ||||
subthreadPermissionsToCheck, | subthreadPermissionsToCheck, | ||||
stripLocalIDs(newMessageInfos), | stripLocalIDs(newMessageInfos), | ||||
newMessageDatas, | newMessageDatas, | ||||
updatesForCurrentSession, | updatesForCurrentSession, | ||||
); | ); | ||||
if (!viewer.isScriptViewer) { | if (!viewer.isScriptViewer) { | ||||
// If we're not being called from a script, then we avoid awaiting | // If we're not being called from a script, then we avoid awaiting | ||||
// postMessageSendPromise below so that we don't delay the response to the | // postMessageSendPromise below so that we don't delay the response to the | ||||
// user on external services. In that case, we use handleAsyncPromise to | // user on external services. In that case, we use handleAsyncPromise to | ||||
// make sure any exceptions are caught and logged. | // make sure any exceptions are caught and logged. | ||||
handleAsyncPromise(postMessageSendPromise); | handleAsyncPromise(postMessageSendPromise); | ||||
} | } | ||||
await Promise.all([ | await Promise.all([ | ||||
messageInsertPromise, | messageInsertPromise, | ||||
updateRepliesCount(threadsToMessageIndices, newMessageDatas), | updateRepliesCount(threadsToMessageIndices, newMessageDatas), | ||||
processMessages, | |||||
ashoatUnsubmitted Not Done Inline ActionsI don't think we should block the return on this. Search indexing is usually implemented as a "post-processing step"... the user creating the message shouldn't need to wait on the search indexing to complete for the endpoint to return. Instead, I think we should include this in postMessageSendPromise. Can you move the call to processMessagesForSearch into postMessageSend? You can use the messageInfos parameter (stripLocalIDs should have no effect on indexing I think) ashoat: I don't think we should block the return on this. Search indexing is usually implemented as a… | |||||
viewer.isScriptViewer ? postMessageSendPromise : undefined, | viewer.isScriptViewer ? postMessageSendPromise : undefined, | ||||
]); | ]); | ||||
if (updatesForCurrentSession !== 'return') { | if (updatesForCurrentSession !== 'return') { | ||||
return []; | return []; | ||||
} | } | ||||
return shimUnsupportedRawMessageInfos( | return shimUnsupportedRawMessageInfos( | ||||
▲ Show 20 Lines • Show All 471 Lines • Show Last 20 Lines |
We should only pass newMessageInfos in here. The messages that are in returnMessageInfos but not newMessageInfos are messages that have already been created. Those messages should have already been indexed
This brings to mind a question: is the indexing process idempotent? Meaning, if I index the same message twice, will it be the same as if I indexed that message once?