forked from Ivasoft/mattermost-mobile
Process notifications when the app is in the background and other perf improvements (#7129)
This commit is contained in:
@@ -318,12 +318,12 @@ const ChannelHandler = <TBase extends Constructor<ServerDataOperatorBase>>(super
|
||||
}));
|
||||
|
||||
const uniqueRaws = getUniqueRawsBy({raws: memberships, key: 'id'}) as ChannelMember[];
|
||||
const ids = uniqueRaws.map((cm: ChannelMember) => cm.channel_id);
|
||||
const ids = uniqueRaws.map((cm: ChannelMember) => `${cm.channel_id}-${cm.user_id}`);
|
||||
const db: Database = this.database;
|
||||
const existing = await db.get<ChannelMembershipModel>(CHANNEL_MEMBERSHIP).query(
|
||||
Q.where('id', Q.oneOf(ids)),
|
||||
).fetch();
|
||||
const membershipMap = new Map<string, ChannelMembershipModel>(existing.map((member) => [member.id, member]));
|
||||
const membershipMap = new Map<string, ChannelMembershipModel>(existing.map((member) => [member.channelId, member]));
|
||||
const createOrUpdateRawValues = uniqueRaws.reduce((res: ChannelMember[], cm) => {
|
||||
const e = membershipMap.get(cm.channel_id);
|
||||
if (!e) {
|
||||
|
||||
@@ -148,13 +148,15 @@ const GroupHandler = <TBase extends Constructor<ServerDataOperatorBase>>(supercl
|
||||
rawValues.push(...Object.values(groupsSet));
|
||||
}
|
||||
|
||||
records.push(...(await this.handleRecords({
|
||||
fieldName: 'id',
|
||||
transformer: transformGroupMembershipRecord,
|
||||
createOrUpdateRawValues: rawValues,
|
||||
tableName: GROUP_MEMBERSHIP,
|
||||
prepareRecordsOnly: true,
|
||||
}, 'handleGroupMembershipsForMember')));
|
||||
if (rawValues.length) {
|
||||
records.push(...(await this.handleRecords({
|
||||
fieldName: 'id',
|
||||
transformer: transformGroupMembershipRecord,
|
||||
createOrUpdateRawValues: rawValues,
|
||||
tableName: GROUP_MEMBERSHIP,
|
||||
prepareRecordsOnly: true,
|
||||
}, 'handleGroupMembershipsForMember')));
|
||||
}
|
||||
|
||||
// Batch update if there are records
|
||||
if (records.length && !prepareRecordsOnly) {
|
||||
|
||||
@@ -164,11 +164,11 @@ describe('*** Operator: Thread Handlers tests ***', () => {
|
||||
|
||||
expect(spyOnPrepareRecords).toHaveBeenCalledWith({
|
||||
createRaws: [{
|
||||
raw: {team_id: 'team_id_1', thread_id: 'thread-1'},
|
||||
}, {
|
||||
raw: {team_id: 'team_id_1', thread_id: 'thread-2'},
|
||||
record: undefined,
|
||||
}, {
|
||||
raw: {team_id: 'team_id_2', thread_id: 'thread-2'},
|
||||
record: undefined,
|
||||
}],
|
||||
transformer: transformThreadInTeamRecord,
|
||||
tableName: 'ThreadsInTeam',
|
||||
|
||||
@@ -124,7 +124,9 @@ const ThreadHandler = <TBase extends Constructor<ServerDataOperatorBase>>(superc
|
||||
threadsMap: {[teamId]: threads},
|
||||
prepareRecordsOnly: true,
|
||||
}) as ThreadInTeamModel[];
|
||||
batch.push(...threadsInTeam);
|
||||
if (threadsInTeam.length) {
|
||||
batch.push(...threadsInTeam);
|
||||
}
|
||||
}
|
||||
|
||||
if (batch.length && !prepareRecordsOnly) {
|
||||
@@ -199,7 +201,7 @@ const ThreadHandler = <TBase extends Constructor<ServerDataOperatorBase>>(superc
|
||||
const threadIds = threadsMap[teamId].map((thread) => thread.id);
|
||||
const chunks = await (this.database as Database).get<ThreadInTeamModel>(THREADS_IN_TEAM).query(
|
||||
Q.where('team_id', teamId),
|
||||
Q.where('id', Q.oneOf(threadIds)),
|
||||
Q.where('thread_id', Q.oneOf(threadIds)),
|
||||
).fetch();
|
||||
const chunksMap = chunks.reduce((result: Record<string, ThreadInTeamModel>, chunk) => {
|
||||
result[chunk.threadId] = chunk;
|
||||
|
||||
Reference in New Issue
Block a user