Click here to Skip to main content
15,904,822 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: The perfect teacher Pin
AspDotNetDev8-Jun-11 20:16
protectorAspDotNetDev8-Jun-11 20:16 
GeneralRe: The perfect teacher Pin
OriginalGriff2-Jun-11 3:50
mveOriginalGriff2-Jun-11 3:50 
GeneralRe: The perfect teacher Pin
RobCroll2-Jun-11 4:38
RobCroll2-Jun-11 4:38 
GeneralRe: The perfect teacher Pin
GibbleCH2-Jun-11 6:15
GibbleCH2-Jun-11 6:15 
GeneralRe: The perfect teacher Pin
BobJanova7-Jun-11 4:10
BobJanova7-Jun-11 4:10 
GeneralRe: The perfect teacher Pin
AspDotNetDev2-Jun-11 10:11
protectorAspDotNetDev2-Jun-11 10:11 
GeneralRe: The perfect teacher Pin
StM0n2-Jun-11 9:41
StM0n2-Jun-11 9:41 
GeneralRe: The perfect teacher PinPopular
Jeroen De Dauw2-Jun-11 10:01
Jeroen De Dauw2-Jun-11 10:01 
GeneralRe: The perfect teacher Pin
Anuj Tripathi15-Jun-11 2:58
Anuj Tripathi15-Jun-11 2:58 
GeneralRe: The perfect teacher Pin
Brad Barnhill15-Jun-11 11:27
Brad Barnhill15-Jun-11 11:27 
Generalcode for browser Pin
tarunbatra33931-Jun-11 2:26
tarunbatra33931-Jun-11 2:26 
GeneralRe: code for browser Pin
Member 13249541-Jun-11 3:53
Member 13249541-Jun-11 3:53 
GeneralRe: code for browser PinPopular
_Erik_1-Jun-11 4:23
_Erik_1-Jun-11 4:23 
GeneralRe: code for browser Pin
StM0n1-Jun-11 9:19
StM0n1-Jun-11 9:19 
GeneralRe: code for browser Pin
Lutosław4-Jun-11 0:44
Lutosław4-Jun-11 0:44 
GeneralRe: code for browser Pin
Joan M1-Jun-11 23:06
professionalJoan M1-Jun-11 23:06 
GeneralRe: code for browser Pin
Jeroen De Dauw2-Jun-11 10:02
Jeroen De Dauw2-Jun-11 10:02 
GeneralRe: code for browser Pin
walterhevedeich2-Jun-11 14:23
professionalwalterhevedeich2-Jun-11 14:23 
GeneralRe: code for browser Pin
fjdiewornncalwe4-Jun-11 7:11
professionalfjdiewornncalwe4-Jun-11 7:11 
GeneralRe: code for browser Pin
DerekT-P8-Jun-11 4:57
professionalDerekT-P8-Jun-11 4:57 
GeneralRe: code for browser Pin
Mel Pama8-Jun-11 20:17
professionalMel Pama8-Jun-11 20:17 
GeneralRe: code for browser Pin
Anuj Tripathi15-Jun-11 20:59
Anuj Tripathi15-Jun-11 20:59 
Generaltry to throw and catch. Pin
Kim Togo31-May-11 23:38
professionalKim Togo31-May-11 23:38 
GeneralLooks like a database call obsession to me… Pin
saxenaabhi631-May-11 15:18
saxenaabhi631-May-11 15:18 
C#
protected void LiveList_OnItemDataBound(object sender, RepeaterItemEventArgs e)
  {
      HiddenField username = (HiddenField)e.Item.FindControl("hidden_username");
      Image mapbtn = (Image)e.Item.FindControl("mapbtn");
      System.Web.UI.HtmlControls.HtmlTableRow tr = (System.Web.UI.HtmlControls.HtmlTableRow)e.Item.FindControl("rowlive");

      if (mapbtn != null && username != null)
      {
          UserProfile selectedUser = null;
          selectedUser = Sql.GetUserDetails(username.Value);
          if (selectedUser != null)
          {
              BroadcastOptions broadcastOptions = BroadcastOptions.None;
              int sessionId = 0;
              if (Sql.CheckActiveSession(selectedUser.UserId, Visibility.IncludePrivate, out sessionId, out broadcastOptions))
              {
                  Location[] locs = Sql.GetLocationByVodID(sessionId);
                  if (locs.Length > 0)
                  {
                      String mapUrl = mViewWebSite.AbsolutePath(
                        String.Format("/map.aspx?live=true&target_id={0}&uid={1}", sessionId, selectedUser.UserId.ToString()));
                      mapbtn.Enabled = true;
                      mapbtn.ImageUrl = "Images/miniWorldMap.png";
                      mapbtn.Attributes.Add("style", "Cursor:Pointer");
                      mapbtn.Attributes.Add("onclick", "ShowLocation('" + mapUrl + "')");
                  }
              }
          }
      }
  }


The above code was written by our previous senior web developer (that's what told to me when I was hired).
On every item bound on the repeater he
1) reads the username from hidden control D'Oh! | :doh:
2) call database to load user details Hmmm | :|
3) another call to database to check any active sessions OMG | :OMG:
4) another call to load whole list of gps locations to find whether gps is enables or not D'Oh! | :doh:
5) then finally enable the map button if gps is enabled

Amazingly this list is inside an update panel that updated every 10 seconds Cry | :(( Cry | :((

So for an average list of 30 users => total 3x30 = 90 database calls every 10 seconds
when i traced the page it was hauling at 320 Kb every 10 sec. Dead | X|

Fixed this in database, bringing a bool flag back by doing some joins and determining weather gps is enabled or not. Now only 1 db call every 10 sec.
GeneralRe: Looks like a database call obsession to me… Pin
Firo Atrum Ventus31-May-11 16:05
Firo Atrum Ventus31-May-11 16:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.