06. februar 2004 - 11:06
Der er
4 kommentarer og
1 løsning
Generel optimering af ASP og mySQL
Hej Eksperter
Jeg har for nyligt, konverteret min database fra Access til mySQL, og er nu blevet gevaldig træt af, at min Access (åbenbart) performede bedre end mySQL databasen.
Det er ikke abnormalt, at siderne hænger 15 sek eller mere, før de hentes. For mig virker dette underligt, da genereringstiden med Access aldrig var over 5 sek.
Derfor vil jeg gerne høre, om der er nogle generelle ting, man kan gøre for at optimere koden og evt. databasen? Ligeledes vil jeg gerne høre, om der er ting som er "Big no no's" i forbindelse med ASP og mySQL? Jeg må jo gøre et eller andet forkert.
Hvis i vil sek eksempler på kode, som er langsom, så sig endelig til.
06. februar 2004 - 19:01
#2
Ja, du kan vel lige så godt få hele forsiden :)
dim RS1, nameStr, totalphotos, todayphotos, counter, rowcounter,topicstr, RScount, graphwidth, totalvotes, userfound
response.write("<table width='556' border='0' cellspacing='0' cellpadding='0'>")
response.write("<tr>")
response.write("<td width='265' valign='top'>")
response.write("<div style='height:20px;padding:3px;margin-bottom:10px;border:1px solid #ECECEC;background:#F7F7F7;'>5 nyeste emner i forum</div>")
SQL = "SELECT id,forum,date_format(addeddate,'%d/%m') as datestr,topic FROM topics ORDER BY addeddate DESC limit 0,5"
set RS = conn.execute(SQL)
if RS.EOF then
response.write("<div style='color:#CCCCCC;'>Ingen fundet</div>")
end if
do while not RS.EOF
topicstr = left(RS("topic"),25)
if len(RS("topic")) > 25 then topicstr = topicstr & "..."
SQL = "SELECT COUNT(*) AS found FROM replys WHERE topic = " & RS("id")
set RScount = conn.execute(SQL)
response.write("<div style='margin-top:2px;padding-left:2px;'>" & replace(RS("datestr"),"-",".") & " - <a href='?page=4&mode=showreply&fora=" & RS("forum") & "&topic=" & RS("id") & "'>" & topicstr & "</a> (" & RScount("found") & ")</div>")
RS.movenext
loop
response.write("</td>")
response.write("<td width='26'></td>")
response.write("<td width='265' valign='top'>")
SQL = "SELECT id, date_format(addeddate,'%d/%m') as datestr, topic FROM news ORDER BY addeddate DESC limit 0,5"
set RS = conn.execute(SQL)
response.write("<div style='height:20px;padding:3px;margin-bottom:10px;border:1px solid #ECECEC;background:#F7F7F7;'>5 seneste nyheder</div>")
if RS.EOF then
response.write("<div style='color:#CCCCCC;'>Ingen fundet</div>")
end if
do while not RS.EOF
topicstr = left(RS("topic"),25)
if len(RS("topic")) > 25 then topicstr = topicstr & "..."
response.write("<div style='margin-top:2px;padding-left:2px;'>" & replace(RS("datestr"),"-",".") & " - <a href='?page=2'>" & topicstr & "</a></div>")
RS.movenext
loop
response.write("<div style='text-align:right;margin-top:2px;'><a href='?page=2'>Se alle nyheder</a></div>")
response.write("</td>")
response.write("</tr>")
response.write("</table>")
'end if
' Nyeste 8 billeder
response.write("<div class='sitesubheader' style='margin-top:30px;'>Nyeste billeder</div>")
response.write("<div style='margin-top:4px; margin-bottom: 5px;'><img src='gfx/gif/spacer.gif' border='0'></div>")
response.write("<div style='margin-bottom:15px;'><a href='?page=28' class='cat'>Se de 100 nyeste billeder</a></div>")
'SQL = "SELECT photos.id, photos.name, path, category,addeddate FROM photos, categories WHERE category = categories.id AND monthpic = 0 AND hidden = 0 AND trip = 0 AND category <> 32 AND category <> 48 ORDER BY photos.id DESC limit 0,8"
SQL = "SELECT photos.id, photos.name,photos.path,photos.category,photos.addeddate FROM photos INNER JOIN categories ON photos.category = categories.id WHERE monthpic = 0 AND hidden = 0 AND trip = 0 AND categories.id <> 32 AND categories.id <> 48 ORDER BY photos.id DESC limit 0,8"
set RS = conn.execute(SQL)
rowcounter = 0
counter = 0
if RS.EOF then
response.write("<font color='#CCCCCC'>Ingen billeder fundet i databasen</font>")
else
response.write("<table width='556' border='0' cellpadding='0' cellspacing='0'>")
response.write("<tr>")
do while not RS.EOF and counter < 8
rowcounter = rowcounter + 1
counter = counter + 1
nameStr = RS("name")
if len(nameStr) > 20 then nameStr = left(nameStr,18) & "..."
if rowcounter <= 4 then
response.write("<td width='139' height='140' align='center' valign='middle'>")
response.write("<table width='120' height='140' border='0' cellspacing='1' cellpadding='0' bgcolor='ECECEC'>")
response.write("<tr>")
response.write("<td align='center' valign='middle' bgcolor='F7F7F7'>")
response.write("<a href='?page=30&id=" & RS("id") & "'><img src='../log/lowres_" & RS("path") & "' border='0' alt='" & RS("name") & "'></a>")
response.write("</td>")
response.write("</tr>")
response.write("</table>")
response.write("<font color='#CCCCCC'>" & formatdatetime(RS("addeddate"),2) & " kl. " & formatdatetime(RS("addeddate"),4) & "</font><br>" & nameStr)
nameStr = ""
response.write("</td>")
elseif counter = 5 then
response.write("</tr>")
response.write("<tr>")
response.write("<td colspan='4' height='10'></td>")
response.write("</tr>")
response.write("<tr>")
response.write("<td width='139' height='140' align='center' valign='middle'>")
response.write("<table width='120' height='140' border='0' cellspacing='1' cellpadding='0' bgcolor='ECECEC'>")
response.write("<tr>")
response.write("<td align='center' valign='middle' bgcolor='F7F7F7'>")
response.write("<a href='?page=30&id=" & RS("id") & "'><img src='../log/lowres_" & RS("path") & "' border='0' alt='" & RS("name") & "'></a>")
response.write("</td>")
response.write("</tr>")
response.write("</table>")
response.write("<font color='#CCCCCC'>" & formatdatetime(RS("addeddate"),2) & " kl. " & formatdatetime(RS("addeddate"),4) & "</font><br>" & nameStr)
nameStr = ""
response.write("</td>")
rowcounter = 0
end if
RS.movenext
loop
response.write("</tr>")
response.write("</table>")
end if
' Nyeste 4 kommenterede billeder
response.write("<div class='sitesubheader' style='margin-top:30px;'>Nyeste kommenterede billeder</div>")
response.write("<div style='margin-top:4px; margin-bottom: 5px;'><img src='gfx/gif/spacer.gif' border='0'></div>")
response.write("<div style='margin-bottom:15px;'><a href='?page=44' class='cat'>Se de 100 nyeste kommenterede billeder</a></div>")
'response.write("<font color='999999'>Midlertidig deaktiveret</font>")
'SQL = "SELECT photos.id, MAX(comments.id) AS lastcommentid FROM photos, comments WHERE photos.id = comments.photo AND category <> 15 AND category <> 32 GROUP BY photos.id ORDER BY lastcommentid DESC limit 0,4"
SQL = "SELECT photos.id, max(comments.id) AS lastcommentid FROM comments INNER JOIN photos ON photos.id = comments.photo WHERE photos.category <> 15 AND photos.category <> 32 GROUP BY photos.id ORDER BY lastcommentid DESC limit 0,4"
set RS = conn.execute(SQL)
if RS.EOF then
response.write("<font color='#CCCCCC'>Ingen billeder fundet i databasen</font>")
else
response.write("<table width='556' border='0' cellpadding='0' cellspacing='0'>")
response.write("<tr>")
do while not RS.EOF
'SQL = "SELECT name, path, comments.addeddate, category FROM photos,comments WHERE photos.id = comments.photo AND photos.id = " & RS("id") & " ORDER BY comments.id DESC;"
SQL = "SELECT photos.name,photos.path,comments.addeddate,photos.category FROM comments INNER JOIN photos ON photos.id = comments.photo WHERE photos.id = " & RS("id") & " ORDER BY comments.id DESC"
set RS1 = conn.execute(SQL)
nameStr = RS1("name")
if len(nameStr) > 20 then nameStr = left(nameStr,20) & "..."
response.write("<td width='139' align='center' valign='middle'>")
response.write("<table width='120' height='140' border='0' cellspacing='1' cellpadding='0' bgcolor='ECECEC'>")
response.write("<tr>")
response.write("<td align='center' valign='middle' bgcolor='F7F7F7'>")
response.write("<a href='?page=16&category=" & RS1("category") & "&id=" & RS("id") & "'><img src='../log/lowres_" & RS1("path") & "' border='0' alt='" & RS1("name") & "'></a>")
response.write("</td>")
response.write("</tr>")
response.write("</table>")
response.write("<font color='#CCCCCC'>" & formatdatetime(RS1("addeddate"),2) & " kl. " & formatdatetime(RS1("addeddate"),4) & "</font><br>")
response.write(nameStr)
nameStr = ""
response.write("</td>")
RS.movenext
loop
response.write("</tr>")
response.write("</table>")
end if
response.write("<table width='556' border='0' cellspacing='0' cellpadding='0' style='margin-top:30px;'>")
response.write("<tr>")
response.write("<td width='265' valign='top'>")
response.write("<div style='height:20px;padding:3px;margin-bottom:10px;border:1px solid #ECECEC;background:#F7F7F7;'>Nyeste afstemning</div><div style='padding-left:2px;'>")
if session("login") = "" then
response.write("<div style='color:#999999;'>Du skal være logget ind, for at se afstemninger.</div>")
else
SQL = "SELECT id, topic FROM votes WHERE TO_DAYS(now()) - TO_DAYS(enddate) < 0 AND active = 1 ORDER BY startdate DESC limit 0,1"
set RS = conn.execute(SQL)
if RS.EOF then
response.write("<div style='color:#CCCCCC;'>Ingen fundet</div>")
else
'SQL = "SELECT COUNT(*) AS found FROM vote_replys,vote_choices WHERE vote_replys.choice = vote_choices.id AND author = " & session("userid") & " AND vote = " & RS("id")
SQL = "SELECT COUNT(*) AS found FROM vote_replys INNER JOIN vote_choices ON vote_replys.choice = vote_choices.id WHERE vote_replys.author = " & session("userid") & " AND vote_choices.vote = " & RS("id")
set RS1 = conn.execute(SQL)
userfound = RS1("found")
'SQL = "SELECT COUNT(*) AS found FROM vote_replys,vote_choices WHERE vote_replys.choice = vote_choices.id AND vote = " & RS("id")
SQL = "SELECT COUNT(*) AS found FROM vote_replys INNER JOIN vote_choices ON vote_replys.choice = vote_choices.id WHERE vote_choices.vote = " & RS("id")
set RS1 = conn.execute(SQL)
totalvotes = RS1("found")
do while not RS.EOF
response.write("<div style='font-weight:bold;margin-bottom:10px;'>" & RS("topic") & "</div>")
'SQL = "SELECT vote_choices.id,vote_choices.topic FROM vote_choices,votes WHERE vote_choices.vote = votes.id AND votes.id = " & RS("id") & " ORDER BY vote_choices.id"
SQL = "SELECT vote_choices.id,vote_choices.topic FROM vote_choices INNER JOIN votes ON vote_choices.vote = votes.id WHERE votes.id = " & RS("id") & " ORDER BY vote_choices.id"
set RS1 = conn.execute(SQL)
do while not RS1.EOF
if userfound > 0 then
'SQL = "SELECT COUNT(*) AS found FROM vote_replys,vote_choices WHERE vote_replys.choice = vote_choices.id AND vote = " & RS("id") & " AND vote_replys.choice = " & RS1("id")
SQL = "SELECT COUNT(*) AS found FROM vote_replys INNER JOIN vote_choices ON vote_replys.choice = vote_choices.id WHERE vote_choices.vote = " & RS("id") & " AND vote_replys.choice = " & RS1("id")
set RScount = conn.execute(SQL)
graphwidth = RScount("found") * 100 / totalvotes
response.write("<div style='margin-bottom:3px;font-style:italic;'>" & RS1("topic") & "</div>")
response.write("<div style='height:6px;width:80px;border:1px solid #5F85A8;text-align:left;float:left;'><div style='width:" & round(graphwidth,0) & "%;background:#DAE4ED;height:4px;'></div></div>" & round(graphwidth,0) & "%")
else
response.write("- <a href='?page=46&mode=uservote&id=" & RS1("id") & "'>" & RS1("topic") & "</a>")
end if
RS1.movenext
if not RS1.EOF then response.write("<br><br>")
loop
RS.movenext
loop
response.write("<div style='margin-top:15px;color:#999999;'>" & totalvotes & " bruger(e) har stemt</div>")
end if
response.write("</div>")
response.write("<div style='text-align:right;margin-top:2px;'><a href='?page=46'>Se alle afstemninger</a></div>")
end if
response.write("</td>")
response.write("<td width='26'></td>")
response.write("<td width='265' valign='top'>")
response.write("<div style='height:20px;padding:3px;margin-bottom:10px;border:1px solid #ECECEC;background:#F7F7F7;'>Top 5 kommentatorer sidste 7 dage</div>")
SQL = "SELECT COUNT(*) AS found, comments.author,firstname,lastname,email FROM comments,users,photos WHERE comments.author = users.id AND photos.id = comments.photo AND comments.author <> photos.author AND TO_DAYS(now()) - TO_DAYS(comments.addeddate) <= 7 GROUP BY comments.author ORDER BY found DESC limit 0,5"
'SQL = "SELECT COUNT(*) AS found, comments.author,users.firstname,users.lastname,users.email FROM comments INNER JOIN users ON users.id = comments.author AND comments ON photos.id = comments.photo WHERE comments.author <> photos.author AND TO_DAYS(now()) - TO_DAYS(comments.addeddate) <= 7 GROUP BY comments.author ORDER BY found DESC limit 0,5"
set RS = conn.execute(SQL)
if RS.EOF then
response.write("<div style='color:#CCCCCC;'>Ingen fundet</div>")
end if
counter = 0
do while not RS.EOF
counter = counter + 1
response.write("<div style='padding-bottom:7px;'>" & counter & ": <a href='?page=3&mode=showmember&id=" & RS("author") & "'>" & convertname(RS("firstname")) & " " & convertname(RS("lastname")) & "</a> (" & RS("found") & ")</div>")
RS.movenext
loop
response.write("</td>")
response.write("</tr>")
response.write("</table>")