Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 1.62 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. /* Loads the user data and executes callback() ; also executes it (but with no userData passed) if failed */
  3. loadUserData = function(argsDict, userID, callback)
  4. {
  5.         var installationName = argsDict.Installation || "main";
  6.        
  7.         if (!userDataCache[userID])
  8.                 userDataCache[userID] = new Object();
  9.        
  10.         /* Checks if the entry is cached */
  11.         if (userDataCache[userID][installationName])
  12.         {
  13.                 callback(userDataCache[userID][installationName]);
  14.                 return;
  15.         }
  16.        
  17.         /* Build the actual userData after finding the installation */
  18.         installationsCol.findOne({Name: installationName, userID: userID}, function(err, installation)
  19.         {
  20.                 var userData = new Object(), appCollection;
  21.                
  22.                 if (!installation || !Object.keys(installation.InstalledApps).length || !(appCollection = appCollections[installation.OSRelease]))
  23.                 {
  24.                         callback();
  25.                         return;
  26.                 }
  27.                
  28.                 console.log("Building userdata for "+userID);
  29.                 userData.installed = {}, userData.upgradable = {};
  30.                
  31.                 var userDataBuilt = function()
  32.                 {
  33.                         console.log(userData);
  34.                         userDataCache[userID][installationName] = userData;
  35.                         setTimeout(function()
  36.                         {
  37.                                 /* Don't keep that in memory forever */
  38.                                 delete userDataCache[userID][installationName];
  39.                         }, 30*60*1000);
  40.                         callback(userData);
  41.                 };
  42.                
  43.                 var i=0;
  44.                 for (Name in installation.InstalledApps)
  45.                 {
  46.                         var Versions = installation.InstalledApps[Name];
  47.                        
  48.                         appCollection.findOne({Name: Name}, function(err, app)
  49.                         {
  50.                                 if (app)
  51.                                 {
  52.                                         userData.installed.push(app._id);
  53.                                         if (Versions.indexOf(app.Version) == -1)
  54.                                                 userData.upgradable[app._id] = 1;
  55.                                 }
  56.                                
  57.                                 if (++i==Object.keys(installation.InstalledApps).length)
  58.                                         userDataBuilt();
  59.                         });
  60.                 }
  61.         });            
  62. }