Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3375517
D8588.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D8588.diff
View Options
diff --git a/keyserver/src/push/crypto.js b/keyserver/src/push/crypto.js
--- a/keyserver/src/push/crypto.js
+++ b/keyserver/src/push/crypto.js
@@ -37,13 +37,11 @@
let encryptedSerializedPayload;
try {
const unencryptedSerializedPayload = JSON.stringify(unencryptedPayload);
- const { serializedPayload } = await encryptAndUpdateOlmSession(
- cookieID,
- 'notifications',
- {
- serializedPayload: unencryptedSerializedPayload,
- },
- );
+ const {
+ encryptedMessages: { serializedPayload },
+ } = await encryptAndUpdateOlmSession(cookieID, 'notifications', {
+ serializedPayload: unencryptedSerializedPayload,
+ });
encryptedSerializedPayload = serializedPayload;
} catch (e) {
console.log('Notification encryption failed: ' + e);
@@ -78,13 +76,11 @@
if (!unencryptedSerializedPayload) {
return unencryptedPayload;
}
- const { serializedPayload } = await encryptAndUpdateOlmSession(
- cookieID,
- 'notifications',
- {
- serializedPayload: unencryptedSerializedPayload,
- },
- );
+ const {
+ encryptedMessages: { serializedPayload },
+ } = await encryptAndUpdateOlmSession(cookieID, 'notifications', {
+ serializedPayload: unencryptedSerializedPayload,
+ });
return { encryptedPayload: serializedPayload.body };
} catch (e) {
console.log('Notification encryption failed: ' + e);
diff --git a/keyserver/src/updaters/olm-session-updater.js b/keyserver/src/updaters/olm-session-updater.js
--- a/keyserver/src/updaters/olm-session-updater.js
+++ b/keyserver/src/updaters/olm-session-updater.js
@@ -12,11 +12,17 @@
const maxOlmSessionUpdateAttemptTime = 30000;
const olmSessionUpdateRetryDelay = 50;
+type OlmEncryptionResult = {
+ +encryptedMessages: { +[string]: EncryptResult },
+ +dbPersistConditionViolated?: boolean,
+};
+
async function encryptAndUpdateOlmSession(
cookieID: string,
olmSessionType: 'content' | 'notifications',
messagesToEncrypt: $ReadOnly<{ [string]: string }>,
-): Promise<{ [string]: EncryptResult }> {
+ dbPersistCondition?: ({ +[string]: EncryptResult }) => boolean,
+): Promise<OlmEncryptionResult> {
const isContent = olmSessionType === 'content';
const { picklingKey } = await fetchOlmAccount(olmSessionType);
const olmUpdateAttemptStartTime = Date.now();
@@ -47,6 +53,10 @@
);
}
+ if (dbPersistCondition && !dbPersistCondition(encryptedMessages)) {
+ return { encryptedMessages, dbPersistConditionViolated: true };
+ }
+
const updatedSession = session.pickle(picklingKey);
const [transactionResult] = await dbQuery(
@@ -76,7 +86,7 @@
const [{ versionOnUpdateAttempt }] = selectResult;
if (version === versionOnUpdateAttempt) {
- return encryptedMessages;
+ return { encryptedMessages };
}
await sleep(olmSessionUpdateRetryDelay);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 8:40 PM (20 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2591632
Default Alt Text
D8588.diff (2 KB)
Attached To
Mode
D8588: Refactor olm-session-updater to enable to conditionally skip database content update
Attached
Detach File
Event Timeline
Log In to Comment