Only set last group fetch for server updates

This commit is contained in:
Jamie Kyle 2024-10-24 12:08:33 -07:00 committed by GitHub
parent 28c3bf8017
commit 56ccd02232
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2783,6 +2783,7 @@ export async function respondToGroupV2Migration({
let groupSendEndorsementResponse: Uint8Array | null | undefined; let groupSendEndorsementResponse: Uint8Array | null | undefined;
try { try {
const fetchedAt = Date.now();
const response: GroupLogResponseType = await makeRequestWithCredentials({ const response: GroupLogResponseType = await makeRequestWithCredentials({
logId: `getGroupLog/${logId}`, logId: `getGroupLog/${logId}`,
publicParams, publicParams,
@ -2799,6 +2800,7 @@ export async function respondToGroupV2Migration({
options options
), ),
}); });
setLastSuccessfulGroupFetch(conversation.id, fetchedAt);
// Attempt to start with the first group state, only later processing future updates // Attempt to start with the first group state, only later processing future updates
firstGroupState = response?.changes?.groupChanges?.[0]?.groupState; firstGroupState = response?.changes?.groupChanges?.[0]?.groupState;
@ -2809,12 +2811,14 @@ export async function respondToGroupV2Migration({
`respondToGroupV2Migration/${logId}: Failed to access log endpoint; fetching full group state` `respondToGroupV2Migration/${logId}: Failed to access log endpoint; fetching full group state`
); );
try { try {
const fetchedAt = Date.now();
const groupResponse = await makeRequestWithCredentials({ const groupResponse = await makeRequestWithCredentials({
logId: `getGroup/${logId}`, logId: `getGroup/${logId}`,
publicParams, publicParams,
secretParams, secretParams,
request: (sender, options) => sender.getGroup(options), request: (sender, options) => sender.getGroup(options),
}); });
setLastSuccessfulGroupFetch(conversation.id, fetchedAt);
firstGroupState = groupResponse.group; firstGroupState = groupResponse.group;
groupSendEndorsementResponse = groupSendEndorsementResponse =
@ -3051,9 +3055,8 @@ export async function waitThenMaybeUpdateGroup(
try { try {
// And finally try to update the group // And finally try to update the group
await maybeUpdateGroup(options, { viaFirstStorageSync }); await maybeUpdateGroup(options, { viaFirstStorageSync });
conversation.lastSuccessfulGroupFetch = Date.now();
} catch (error) { } catch (error) {
setLastSuccessfulGroupFetch(conversation.id, undefined);
log.error( log.error(
`${logId}: maybeUpdateGroup failure:`, `${logId}: maybeUpdateGroup failure:`,
Errors.toLogFormat(error) Errors.toLogFormat(error)
@ -3767,24 +3770,20 @@ async function updateGroupViaState({
dropInitialJoinMessage?: boolean; dropInitialJoinMessage?: boolean;
group: ConversationAttributesType; group: ConversationAttributesType;
}): Promise<UpdatesResultType> { }): Promise<UpdatesResultType> {
const logId = idForLogging(group.groupId); const { id, publicParams, secretParams } = group;
const { publicParams, secretParams } = group; const logId = `updateGroupViaState/${idForLogging(group.groupId)}`;
strictAssert( strictAssert(secretParams, `${logId}: Missing secretParams`);
secretParams, strictAssert(publicParams, `${logId}: Missing publicParams`);
'updateGroupViaState: group was missing secretParams!'
);
strictAssert(
publicParams,
'updateGroupViaState: group was missing publicParams!'
);
const fetchedAt = Date.now();
const groupResponse = await makeRequestWithCredentials({ const groupResponse = await makeRequestWithCredentials({
logId: `getGroup/${logId}`, logId: `getGroup/${logId}`,
publicParams, publicParams,
secretParams, secretParams,
request: (sender, requestOptions) => sender.getGroup(requestOptions), request: (sender, requestOptions) => sender.getGroup(requestOptions),
}); });
setLastSuccessfulGroupFetch(id, fetchedAt);
const { group: groupState, groupSendEndorsementResponse } = groupResponse; const { group: groupState, groupSendEndorsementResponse } = groupResponse;
strictAssert(groupState, 'updateGroupViaState: Group state must be present'); strictAssert(groupState, 'updateGroupViaState: Group state must be present');
@ -3853,6 +3852,9 @@ async function updateGroupViaSingleChange({
const previouslyKnewAboutThisGroup = const previouslyKnewAboutThisGroup =
isNumber(group.revision) && group.membersV2?.length; isNumber(group.revision) && group.membersV2?.length;
const wasInGroup = !group.left; const wasInGroup = !group.left;
setLastSuccessfulGroupFetch(group.id, undefined);
const singleChangeResult: UpdatesResultType = await integrateGroupChange({ const singleChangeResult: UpdatesResultType = await integrateGroupChange({
group, group,
groupChange, groupChange,
@ -4005,6 +4007,7 @@ async function updateGroupViaLogs({
let groupSendEndorsementResponse: Uint8Array | null = null; let groupSendEndorsementResponse: Uint8Array | null = null;
const changes: Array<Proto.IGroupChanges> = []; const changes: Array<Proto.IGroupChanges> = [];
do { do {
const fetchedAt = Date.now();
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
response = await makeRequestWithCredentials({ response = await makeRequestWithCredentials({
logId: `getGroupLog/${logId}`, logId: `getGroupLog/${logId}`,
@ -4024,6 +4027,7 @@ async function updateGroupViaLogs({
requestOptions requestOptions
), ),
}); });
setLastSuccessfulGroupFetch(group.id, fetchedAt);
// When the log is long enough that it needs to be paginated, the server is // When the log is long enough that it needs to be paginated, the server is
// not stateful enough to only give us endorsements when we need them. // not stateful enough to only give us endorsements when we need them.
@ -7238,3 +7242,15 @@ export function getMembershipList(
return { aci, uuidCiphertext }; return { aci, uuidCiphertext };
}); });
} }
function setLastSuccessfulGroupFetch(
conversationId: string,
timestamp: number | undefined
): void {
const conversation = window.ConversationController.get(conversationId);
strictAssert(
conversation,
`setLastSuccessfulGroupFetch/${idForLogging(conversationId)}: Conversation must exist`
);
conversation.lastSuccessfulGroupFetch = timestamp;
}