forked from Ivasoft/mattermost-mobile
[Gekidou] Performance & UI fixes (#6122)
* Fix search bar style * MM-42983 Align mention badge on channel list item * MM-42985 polish channel intro UI * MM-42984 update fonts on 'Show' bottom sheet * MM-42982 Increase tap area of back button on channel view * Set StatusBar style based on theme sidebarBg * Reconnect other WS after 20 seconds insted of 5 * Only fetch missing profiles for DM/GMs * Database prepare records optimization * Do not use fallbackUsername for storing GM/DM in the database * fix filter for fetching missing dm/gm * remove use of indexOf inside another loop * remove use of includes inside another loop * remove use of find inside another loop * Add missing translations * disable Flipper on iOS * Remove Flipper code from AppDelegate * feedback review * trim DM display name to make sure is not empty * fixing missing direct channels display name * UI/UX feedback * fix WS channel viewed and mark as unread * Remove duplicate emojis from reaction bar
This commit is contained in:
@@ -23,8 +23,8 @@ import type {
|
||||
|
||||
export interface BaseDataOperatorType {
|
||||
database: Database;
|
||||
handleRecords: ({findMatchingRecordBy, fieldName, transformer, createOrUpdateRawValues, deleteRawValues, tableName, prepareRecordsOnly}: HandleRecordsArgs) => Promise<Model[]>;
|
||||
processRecords: ({createOrUpdateRawValues, deleteRawValues, tableName, findMatchingRecordBy, fieldName}: ProcessRecordsArgs) => Promise<ProcessRecordResults>;
|
||||
handleRecords: ({buildKeyRecordBy, fieldName, transformer, createOrUpdateRawValues, deleteRawValues, tableName, prepareRecordsOnly}: HandleRecordsArgs) => Promise<Model[]>;
|
||||
processRecords: ({createOrUpdateRawValues, deleteRawValues, tableName, buildKeyRecordBy, fieldName}: ProcessRecordsArgs) => Promise<ProcessRecordResults>;
|
||||
batchRecords: (models: Model[]) => Promise<void>;
|
||||
prepareRecords: ({tableName, createRaws, deleteRaws, updateRaws, transformer}: OperationArgs) => Promise<Model[]>;
|
||||
}
|
||||
@@ -43,10 +43,10 @@ export default class BaseDataOperator {
|
||||
* @param {RawValue[]} inputsArg.createOrUpdateRawValues
|
||||
* @param {string} inputsArg.tableName
|
||||
* @param {string} inputsArg.fieldName
|
||||
* @param {(existing: Model, newElement: RawValue) => boolean} inputsArg.findMatchingRecordBy
|
||||
* @param {(existing: Model, newElement: RawValue) => boolean} inputsArg.buildKeyRecordBy
|
||||
* @returns {Promise<{ProcessRecordResults}>}
|
||||
*/
|
||||
processRecords = async ({createOrUpdateRawValues = [], deleteRawValues = [], tableName, findMatchingRecordBy, fieldName}: ProcessRecordsArgs): Promise<ProcessRecordResults> => {
|
||||
processRecords = async ({createOrUpdateRawValues = [], deleteRawValues = [], tableName, buildKeyRecordBy, fieldName}: ProcessRecordsArgs): Promise<ProcessRecordResults> => {
|
||||
const getRecords = async (rawValues: RawValue[]) => {
|
||||
// We will query a table where one of its fields can match a range of values. Hence, here we are extracting all those potential values.
|
||||
const columnValues: string[] = getRangeOfValues({fieldName, raws: rawValues});
|
||||
@@ -78,15 +78,22 @@ export default class BaseDataOperator {
|
||||
|
||||
// for create or update flow
|
||||
const createOrUpdateRaws = await getRecords(createOrUpdateRawValues);
|
||||
const recordsByKeys = createOrUpdateRaws.reduce((result: Record<string, Model>, record) => {
|
||||
// @ts-expect-error object with string key
|
||||
const key = buildKeyRecordBy?.(record) || record[fieldName];
|
||||
result[key] = record;
|
||||
return result;
|
||||
}, {});
|
||||
|
||||
if (createOrUpdateRawValues.length > 0) {
|
||||
createOrUpdateRawValues.forEach((newElement: RawValue) => {
|
||||
const findIndex = createOrUpdateRaws.findIndex((existing: Model) => {
|
||||
return findMatchingRecordBy(existing, newElement);
|
||||
});
|
||||
for (const newElement of createOrUpdateRawValues) {
|
||||
// @ts-expect-error object with string key
|
||||
const key = buildKeyRecordBy?.(newElement) || newElement[fieldName];
|
||||
const existingRecord = recordsByKeys[key];
|
||||
|
||||
// We found a record in the database that matches this element; hence, we'll proceed for an UPDATE operation
|
||||
if (findIndex > -1) {
|
||||
const existingRecord = createOrUpdateRaws[findIndex];
|
||||
if (existingRecord) {
|
||||
// const existingRecord = createOrUpdateRaws[findIndex];
|
||||
|
||||
// Some raw value has an update_at field. We'll proceed to update only if the update_at value is different from the record's value in database
|
||||
const updateRecords = getValidRecordsForUpdate({
|
||||
@@ -96,12 +103,12 @@ export default class BaseDataOperator {
|
||||
});
|
||||
|
||||
updateRaws.push(updateRecords);
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
// This RawValue is not present in the database; hence, we need to create it
|
||||
createRaws.push({record: undefined, raw: newElement});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -194,7 +201,7 @@ export default class BaseDataOperator {
|
||||
/**
|
||||
* handleRecords : Utility that processes some records' data against values already present in the database so as to avoid duplicity.
|
||||
* @param {HandleRecordsArgs} handleRecordsArgs
|
||||
* @param {(existing: Model, newElement: RawValue) => boolean} handleRecordsArgs.findMatchingRecordBy
|
||||
* @param {(existing: Model, newElement: RawValue) => boolean} handleRecordsArgs.buildKeyRecordBy
|
||||
* @param {string} handleRecordsArgs.fieldName
|
||||
* @param {(TransformerArgs) => Promise<Model>} handleRecordsArgs.composer
|
||||
* @param {RawValue[]} handleRecordsArgs.createOrUpdateRawValues
|
||||
@@ -202,7 +209,7 @@ export default class BaseDataOperator {
|
||||
* @param {string} handleRecordsArgs.tableName
|
||||
* @returns {Promise<Model[]>}
|
||||
*/
|
||||
handleRecords = async ({findMatchingRecordBy, fieldName, transformer, createOrUpdateRawValues, deleteRawValues = [], tableName, prepareRecordsOnly = true}: HandleRecordsArgs): Promise<Model[]> => {
|
||||
handleRecords = async ({buildKeyRecordBy, fieldName, transformer, createOrUpdateRawValues, deleteRawValues = [], tableName, prepareRecordsOnly = true}: HandleRecordsArgs): Promise<Model[]> => {
|
||||
if (!createOrUpdateRawValues.length) {
|
||||
throw new DataOperatorException(
|
||||
`An empty "rawValues" array has been passed to the handleRecords method for tableName ${tableName}`,
|
||||
@@ -213,7 +220,7 @@ export default class BaseDataOperator {
|
||||
createOrUpdateRawValues,
|
||||
deleteRawValues,
|
||||
tableName,
|
||||
findMatchingRecordBy,
|
||||
buildKeyRecordBy,
|
||||
fieldName,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user