   # Add a commit to the store.
   # @api public
   addCommit: (commit, callback) ->
-    @session (err, session) ->
-      return callback err if err
-
-      selectQuery = Queries.selectCommitBySha1(commit.sha1())
-      session.query selectQuery, (err, result) ->
-        return callback err if err
-        return callback null if result.rows.length > 0
+    sha1 = commit.sha1()
+    @getCommits [sha1], (err, commits) =>
+      return callback err if err
+      return callback null if commits.length > 0
+
+      @session (err, session) ->
+        return callback err if err
 
         queries = [
           Queries.insertObject(commit)

    @query query, (err, result) ->
      return callback err if err

      commits = []
      for row in result.rows
        row.parent_sha1s = Queries.parseArray(row.parent_sha1s)
        commits.push new Commit( row )

      return callback null, commits


    @query query, (err, result) ->
      return callback err if err

      data = {}
      for row in result.rows
        row.parent_sha1s = Queries.parseArray(row.parent_sha1s)
        data[row.commit_sha1] = row

      commits = []
      for hash in hashes
        row = data[hash]
        commits.push new Commit( row ) if row

      return callback null, commits

