{"action":"opened","issue":{"url":"https://api.github.com/repos/MozillaFoundation/MoFo-Engineering-Handbook/issues/49","labels_url":"https://api.github.com/repos/MozillaFoundation/MoFo-Engineering-Handbook/issues/49/labels{/name}","comments_url":"https://api.github.com/repos/MozillaFoundation/MoFo-Engineering-Handbook/issues/49/comments","events_url":"https://api.github.com/repos/MozillaFoundation/MoFo-Engineering-Handbook/issues/49/events","html_url":"https://github.com/MozillaFoundation/MoFo-Engineering-Handbook/issues/49","id":99281341,"number":49,"title":"Sisyphus: The Big Batch Wolf","user":{"login":"simonwex","id":25260,"avatar_url":"https://avatars.githubusercontent.com/u/25260?v=3","gravatar_id":"","url":"https://api.github.com/users/simonwex","html_url":"https://github.com/simonwex","followers_url":"https://api.github.com/users/simonwex/followers","following_url":"https://api.github.com/users/simonwex/following{/other_user}","gists_url":"https://api.github.com/users/simonwex/gists{/gist_id}","starred_url":"https://api.github.com/users/simonwex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonwex/subscriptions","organizations_url":"https://api.github.com/users/simonwex/orgs","repos_url":"https://api.github.com/users/simonwex/repos","events_url":"https://api.github.com/users/simonwex/events{/privacy}","received_events_url":"https://api.github.com/users/simonwex/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-05T19:35:01Z","updated_at":"2015-08-05T19:35:01Z","closed_at":null,"body":"# API\r\n\r\n_Goal: Support front-end requirements to limit network requests to a minimum_\r\n\r\n## Original Solution: \r\n\r\nGiven an array of actions, reduce into an array of results\r\nhttp://git.io/vOX0w && http://bit.ly/1M5h5AO\r\n\r\n * Begin a database transaction (http://git.io/vOX0e)\r\n   * iterate over the keys of the action, to determine if values need to be resolved using values from previously processed actions (http://git.io/vOXEZ && http://git.io/vOXE1)\r\n      * if an error occurs, rollback the transaction, return details of the error\r\n    * select the appropriate stored query to execute for the current action (http://git.io/vOXuZ)\r\n    * format the values to pass into the query (http://git.io/vOXu2)\r\n    * gather the \"lookup\" values required to validate action permissions (http://git.io/vOXzT)\r\n    * Determine if auth'd user has permission to execute the current action\r\n      * if the action is a create action, continue (http://git.io/vOXzG)\r\n      * if the action depends on a previously created resource in the transaction, continue (http://git.io/vOXzu && http://git.io/vOXgG)\r\n      * if the action depends on a resource that is not part of this transaction, use the lookup values to find it and validate permissions (http://git.io/vOXgK)\r\n        * if not allowed, rollback the transaction.\r\n    * If allowed, execute the query with the values (http://git.io/vOXgQ)\r\n        * If there's an error, rollback\r\n    * format the results from the query (http://git.io/vOXgj)\r\n    * push the raw query results and formatted results onto the reduced result array, and return it to the reduce function for the next iteration (http://git.io/vOX2c)\r\n* Once finished reducing the actions array into a results array, commit the transaction  (http://git.io/vOX2y)\r\n* analyze the actions done and create a series of cache invalidation tails appropriate for the actions done.\r\n    * http://hapijs.com/api#requesttailname\r\n    * http://git.io/vOXaf && http://git.io/vOXas\r\n* return the array of formatted results to the client (http://git.io/vOXa6)\r\n\r\n_(I tried to do the nested list justice in MD, but I think I failed. This further illustrates some of the problems outlined below) - Simon_\r\n\r\n## Problems:\r\n * very nesty\r\n * heavy reliance on scoped variables, making it hard to refactor/maintain\r\n * plentiful amounts of redundancy abounds redundantly\r\n\r\n"}}