Posted By

cybersonic on 08/12/11


Tagged


Versions (?)

Optiming the query lookup


 / Published in: JavaScript
 

  1. getExemptionBoard : function(documentid){
  2. var ex = new ExemptionBoard();
  3. var exemptions = horton.exempt.getExemptionInfo(documentid);
  4. ex.exemptions = exemptions; //do length check
  5. ex.locations = horton.services.locationService.getAllItems() ;
  6. var profile = new PageDataManager("profile",documentid);
  7.  
  8. //Get all the ExemptionLocations and add them as needed, rather than a query for each since we are opening and closing connections:
  9.  
  10. var tempExemtLocations = quickQuery("SELECT Location_Amt, Position_ID, Location_ID FROM PHD_MM_ExemptionsLocations WHERE Document_ID = ?", [documentid]);
  11.  
  12.  
  13. for(var i = 0; i < ex.exemptions.length; i++){
  14. ex.exemptions[i].profile = profile;
  15. ex.exemptions[i].locations = [];
  16. for(var l = 0; l < ex.locations.length; l++){
  17. var exemptionInfo = {}
  18. exemptionInfo.location = ex.locations[l];
  19. exemptionInfo.location_id = ex.locations[l].location_id;
  20. exemptionInfo.exempt_val = 0;
  21. //Go find the right one in the previous array
  22.  
  23. for(var e = 0; e < tempExemtLocations.length; e++){
  24. if((tempExemtLocations[e].location_id == ex.locations[l].location_id) && (tempExemtLocations[e].position_id == i+1)){
  25. exemptionInfo.exempt_val = tempExemtLocations[e].location_amt;
  26. break; //Found it, done.
  27. }
  28. }
  29.  
  30. ex.exemptions[i].locations.push(exemptionInfo); //We go and get the ExemptionLocation Value
  31. }
  32. }
  33. return ex;
  34. },

Report this snippet  

You need to login to post a comment.