Skip to content

Instantly share code, notes, and snippets.

@BerkeleyTrue
Last active February 19, 2016 02:58
Show Gist options
  • Select an option

  • Save BerkeleyTrue/4eaba6684a07453129b6 to your computer and use it in GitHub Desktop.

Select an option

Save BerkeleyTrue/4eaba6684a07453129b6 to your computer and use it in GitHub Desktop.

Revisions

  1. Berkeley Martinez revised this gist Feb 16, 2016. 1 changed file with 0 additions and 17 deletions.
    17 changes: 0 additions & 17 deletions efficient-update.js
    Original file line number Diff line number Diff line change
    @@ -1,17 +0,0 @@
    function completedChallenge(req, res, next) {
    // build user update data, no longer mutates user object
    const { updateData, alreadyCompleted, points } = buildUpdateData(req);
    // calls an update data using user instance id and sends only updateData
    return user.update$(updateData)
    .subscribe(
    count => log('%s documents updated', count),
    next,
    function() {
    return res.json({
    points,
    alreadyCompleted
    });
    }
    );
    }
    }
  2. Berkeley Martinez renamed this gist Feb 16, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. Berkeley Martinez created this gist Feb 16, 2016.
    17 changes: 17 additions & 0 deletions efficient-update.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    function completedChallenge(req, res, next) {
    // build user update data, no longer mutates user object
    const { updateData, alreadyCompleted, points } = buildUpdateData(req);
    // calls an update data using user instance id and sends only updateData
    return user.update$(updateData)
    .subscribe(
    count => log('%s documents updated', count),
    next,
    function() {
    return res.json({
    points,
    alreadyCompleted
    });
    }
    );
    }
    }
    17 changes: 17 additions & 0 deletions inefficient-query.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    function completedChallenge(req, res, next) {
    const { user, body } = req;
    // mutates user object
    const { alreadyCompleted } = updateUserProgress(user, body);
    / sends entire user object to database
    return saveUser(req.user)
    .subscribe(
    () => {},
    next,
    function() {
    return res.json({
    points: user.progressTimestamps.length,
    alreadyCompleted
    });
    }
    );
    }