Monday, April 04, 2011 at 1:08 AM.


on getCounts (adruser) {
		<<3/24/11; 9:00:48 AM by DW
			<<Gather stats on getCount errors.
		<<3/3/11; 11:57:42 PM by DW
			<<Disable logging. 
		<<3/3/11; 10:55:34 AM by DW
			<<Eliminate the scheduling code. The only place this is called is from the everyMinute script. Let it worry about the scheduling. No need for the code to be in two places. 
		<<3/3/11; 9:55:55 AM by DW
			<<Add logging when we get counts and rebuild the associated files. Now we might get a clue what's going wrong when it fails to get the counts.
		<<3/2/11; 8:32:42 PM by DW
			<<Rebuild the Top 40 HTML file too.
		<<2/24/11; 12:10:45 PM by DW
			<<Rebuild the Javascript include for the counts every time we get fresh counts.
		<<2/18/11; 1:16:57 PM by DW
	local (adrdata = radio2suite.init (), adrfeed, recentitems, maxct = adruser^.prefs.counts.maxcount, urls);
	local (now = (), startticks = clock.ticks (), logtext = "");
	radio2suite.inituser (adruser);
	try {
		new (tabletype, @recentitems);
		bundle { //get urls, filter out url garbage
			local (urlsraw, adrrawurl, url, adrurl);
			adjix.getaccounturls (@urlsraw, adruser^, adruser^.prefs.shortener.password);
			new (tabletype, @urls);
			for adrrawurl in @urlsraw {
				url = string.removeUrlGarbage (nameof (adrrawurl^));
				adrurl = @urls.[url];
				if defined (adrurl^) {
					adrurl^ = adrurl^ + adrrawurl^}
				else {
					adrurl^ = adrrawurl^}}};
		for adrfeed in @adruser^.feeds {
			local (ct = 0);
			on visit (adrpost) {
				local (adrurl = @urls.[adrpost^.link]);
				if defined (adrurl^) {
					radio2suite.initpost (adrpost);
					adrpost^.stats.ctReads = adrurl^;
					adrpost^.stats.whenCtReadsUpdated = now;
					recentitems.[string.popfilefromaddress (adrpost)] = adrurl^;
					<<if defined (adrpost^.stats.count)
						<<delete (@adrpost^.stats.count)
					<<if defined (adrpost^.stats.whenCountUpdated)
						<<delete (@adrpost^.stats.whenCountUpdated)
				if ++ct >= maxct {
					return (false)};
				return (true)};
			mainresponder.calendar.visitReverseChronologic (@adrfeed^.calendar, @visit)};
		bundle { //sort recentitems
			local (oldtarget = target.set (@recentitems));
			table.sortby ("Value");
			target.set (oldtarget)};
		adruser^.stats.counts.recentItems = recentitems;
		adruser^.stats.counts.whenLastGet = now;
		adruser^.stats.counts.ctTicksLastGet = clock.ticks () - startticks;
		radio2Suite.buildJavascript (adruser); //2/24/11 by DW
		radio2Suite.buildTop40Html (adruser); //3/2/11 by DW
		logtext = "Got the counts for user \"" + nameof (adruser^) + "\" and rebuilt the embed code and top-40 html."}
		<<scripterror ("this is a test of the error tracking code")
	else {
		adruser^.stats.ctGetCountErrors++; //3/24/11 by DW
		adruser^.stats.lastGetCountError = tryerror; //3/24/11 by DW
		adruser^.stats.whenLastGetCountError = now; //3/24/11 by DW
		logtext = "Error getting counts for user \"" + nameof (adruser^) + ".\" " + tryerror}};
	<<log2.add (, "Counts", logtext, startticks)
bundle { //test code
	config.radio2.users.dave.stats.counts.whenLastGet = date (0); //force it to get the counts
	getcounts (@config.radio2.users.dave)}

This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.