Skip to content

Commit

Permalink
[client-sync, client-app] Remove forceWrite optimization for message …
Browse files Browse the repository at this point in the history
…bodies

Summary:
It's not that much more expensive to just write the bodies while saving
to the DB in edgehill, and it's much less likely to cause unintended
side effects. E.g. this was causing empty bodies to be sent due to not
forceWrite-ing when re-saving later versions of a draft because the
local file already existed on disk.

Test Plan: Run locally, send a draft

Reviewers: evan, halla, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D4468
  • Loading branch information
Mark Hahnenberg committed Apr 20, 2017
1 parent bdde2ea commit af3de33
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
1 change: 0 additions & 1 deletion packages/client-app/src/flux/models/message.es6
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export default class Message extends ModelWithMetadata {
return MessageBodyUtils.writeBody({
msgId: this.id,
body: val,
forceWrite: false,
});
},
deserializeFn: function deserializeBody(val) {
Expand Down
19 changes: 2 additions & 17 deletions packages/isomorphic-core/src/message-body-utils.es6
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function pathForBodyFile(msgId) {
}

// NB: The return value of this function is what gets written into the database.
export function writeBody({msgId, body, forceWrite = true} = {}) {
export function writeBody({msgId, body} = {}) {
const bodyPath = pathForBodyFile(msgId);
const bodyDir = path.dirname(bodyPath);

Expand All @@ -63,22 +63,7 @@ export function writeBody({msgId, body, forceWrite = true} = {}) {
}

try {
let exists;

// If we don't have to write to the file and it already exists then don't.
if (!forceWrite) {
exists = fs.existsSync(bodyPath);
if (exists) {
return result;
}
}

// We want to minimize the number of times we interact with the filesystem
// since it can be slow.
if (exists === undefined) {
exists = fs.existsSync(bodyPath);
}
if (!exists) {
if (!fs.existsSync(bodyPath)) {
mkdirp.sync(bodyDir);
}

Expand Down

0 comments on commit af3de33

Please sign in to comment.