robstein / Nooz

22 North, Inc. codebase
http://www.nooz-app.com
0 stars 0 forks source link

Nooz Stories aren't showing up #28

Open robstein opened 10 years ago

robstein commented 10 years ago

Log entry details

ERROR

Error occurred executing query: Error: [Microsoft][SQL Server Native Client 10.0][SQL Server]Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

The subquery that the log refers to is "select input from relevance where user_id = ? and story_id = S.id".

This subquery should hypothetically never return more than one result. There should only be 1 relevance record for each unique user for each story.

In the client code, we simply insert each new relevance input. The relevance table's insert script updates if there is matching record : function insert(item, user, request) {

var relevanceTable = tables.getTable('relevance');
relevanceTable.where({ user_id : item.user_id, story_id : item.story_id }).read({
        success: function(results) {
            if (results.length === 1) {
                // We already have a record, we need to update it
                results[0].input = item.input;
                relevanceTable.update(results[0]);
                console.log('Updated relevance');
                request.respond(200, results[0]);
            } else {
                // We don't have a record, we need to create it
                console.log('Added relevance');
                request.execute();
            }
        }
    });

}

robstein commented 10 years ago

The error occurs when the users mashes the relevance buttons. The solution is to lock the insert function, so it can only happen once the previous update returns.

robstein commented 10 years ago

I'm having trouble db bug by reenacting the relevance button mashing cause. ..maybe this won't be an issue. Come back to this later and write a scrip in the insert that notices if there are ever more than 1 result, and takes the most recent one.