From ab8f1b4fbf50188dbaa6dd6d05be530b0e0b7c5d Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Fri, 8 Jul 2016 18:33:37 -0400 Subject: [PATCH] Silent transactions if only syncState changes --- packages/nylas-core/hook-transaction-log.js | 24 ++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/nylas-core/hook-transaction-log.js b/packages/nylas-core/hook-transaction-log.js index e6157999c..537ce51ab 100644 --- a/packages/nylas-core/hook-transaction-log.js +++ b/packages/nylas-core/hook-transaction-log.js @@ -9,13 +9,31 @@ module.exports = (db, sequelize) => { } } - const isTransaction = ({$modelOptions}) => { - return $modelOptions.name.singular === "transaction" + const isSilent = (data) => { + data._previousDataValues + data._changed + + if (data.$modelOptions.name.singular === "transaction") { + return true + } + + if (data._changed && data._changed.syncState) { + for (const key of Object.keys(data._changed)) { + if (key === "syncState") { continue } + if (data._changed[key] !== data._previousDataValues[key]) { + // SyncState changed, but so did something else + return false; + } + } + // Be silent due to nothing but sync state changing + return true; + } } const transactionLogger = (type) => { return (sequelizeHookData) => { - if (isTransaction(sequelizeHookData)) return; + if (isSilent(sequelizeHookData)) return; + const transactionData = Object.assign({type: type}, parseHookData(sequelizeHookData) );