improved speed by significantly reducing mysql queries on each request and optimized xml generation

git-svn-id: http://yolanda.mister-muffin.de/svn@155 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2007-10-29 15:00:40 +00:00
parent 0c9f74a312
commit 9a1de07513
16 changed files with 72 additions and 279 deletions

View file

@ -7,18 +7,11 @@ CGI::Session->name($session_name);
$query = new CGI;
$session = new CGI::Session;
$username = get_username_from_sid($session->id);
@userinfo = get_userinfo_from_sid($session->id);
%page = ();
@page = get_page_array(@userinfo);
$page->{'username'} = $username;
$page->{'locale'} = $locale;
$page->{'stylesheet'} = $stylesheet;
$page->{'xmlns:dc'} = $xmlns_dc;
$page->{'xmlns:cc'} = $xmlns_cc;
$page->{'xmlns:rdf'} = $xmlns_rdf;
if($username)
if($userinfo->{'username'})
{
if($query->param('show') eq 'settings')
{
@ -113,7 +106,7 @@ if($username)
'thumbnail' => $duration == 0 ? "/images/tango/video-x-generic.png" : "/video-stills/$id",
'duration' => $duration,
'viewcount' => $viewcount,
'edit' => $username eq $publisher ? "true" : "false",
'edit' => $userinfo->{'username'} eq $publisher ? "true" : "false",
'rdf:RDF' =>
{
'cc:Work' =>

View file

@ -67,15 +67,9 @@ if($query->param('id'))
}
else
{
#there is no video with this id
%page = ();
@userinfo = get_userinfo_from_sid($session->id);
$page->{'username'} = get_username_from_sid($session->id);
$page->{'locale'} = $locale;
$page->{'stylesheet'} = $stylesheet;
$page->{'xmlns:dc'} = $xmlns_dc;
$page->{'xmlns:cc'} = $xmlns_cc;
$page->{'xmlns:rdf'} = $xmlns_rdf;
@page = get_page_array(@userinfo);
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_202c";
@ -92,15 +86,9 @@ if($query->param('id'))
}
else
{
%page = ();
@userinfo = get_userinfo_from_sid($session->id);
#if a username is associated with session id, username is nonempty
$page->{'username'} = get_username_from_sid($session->id);
$page->{'locale'} = $locale;
$page->{'stylesheet'} = $stylesheet;
$page->{'xmlns:dc'} = $xmlns_dc;
$page->{'xmlns:cc'} = $xmlns_cc;
$page->{'xmlns:rdf'} = $xmlns_rdf;
@page = get_page_array(@userinfo);
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_202c";

View file

@ -27,8 +27,7 @@ sub fill_tagcloud
$dbh->disconnect() or die $dbh->errstr;
}
#return a username from passed session id
sub get_username_from_sid
sub get_userinfo_from_sid
{
#get parameters
my ($sid) = @_;
@ -37,13 +36,13 @@ sub get_username_from_sid
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
#prepare query
my $sth = $dbh->prepare(qq{select username from users where sid = ?}) or die $dbh->errstr;
my $sth = $dbh->prepare(qq{select id, username, locale, pagesize, cortado from users where sid = ?}) or die $dbh->errstr;
#execute it
$sth->execute($sid) or die $dbh->errstr;
#save the resulting username
my ($username) = $sth->fetchrow_array();
($userinfo->{'id'}, $userinfo->{'username'}, $userinfo->{'locale'}, $userinfo->{'pagesize'}, $userinfo->{'cortado'}) = $sth->fetchrow_array();
#finish query
$sth->finish() or die $dbh->errstr;
@ -52,33 +51,27 @@ sub get_username_from_sid
$dbh->disconnect() or die $dbh->errstr;
#return
return $username;
return @userinfo;
}
#return a username from passed session id
sub get_userid_from_sid
sub get_page_array
{
#get parameters
my ($sid) = @_;
my (@userinfo) = @_;
#connect to db
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
#prepare query
my $sth = $dbh->prepare(qq{select id from users where sid = ?}) or die $dbh->errstr;
#execute it
$sth->execute($sid) or die $dbh->errstr;
#save the resulting username
my ($username) = $sth->fetchrow_array();
#finish query
$sth->finish() or die $dbh->errstr;
#close db
$dbh->disconnect() or die $dbh->errstr;
#return
return $username;
$page->{'username'} = $userinfo->{'username'};
#if user is logged in, use his locale setting
if($userinfo->{'locale'})
{
$page->{'locale'} = $userinfo->{'locale'};
}
#else get the locale from the http server variable
else
{
($page->{'locale'}) = $query->http('HTTP_ACCEPT_LANGUAGE') =~ /^([^,]+),.*$/;
}
$page->{stylesheet} = $stylesheet;
$page->{'xmlns:dc'} = $xmlns_dc;
$page->{'xmlns:cc'} = $xmlns_cc;
$page->{'xmlns:rdf'} = $xmlns_rdf;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View file

@ -176,7 +176,9 @@
x="452.15411"
y="450.49475"
id="text7102"
transform="scale(1.0438982,0.9579479)"><tspan
transform="scale(1.0438982,0.9579479)"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90"><tspan
sodipodi:role="line"
id="tspan7104"
x="452.15411"

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View file

@ -7,12 +7,10 @@ CGI::Session->name($session_name);
$query = new CGI;
my $session = new CGI::Session;
%page = ();
@userinfo = get_userinfo_from_sid($session->id);
@page = get_page_array(@userinfo);
#if a username is associated with session id, username is nonempty
$page->{username} = get_username_from_sid($session->id);
$page->{locale} = $locale;
$page->{stylesheet} = $stylesheet;
$page->{frontpage} = [''];
if($query->param('information'))

View file

@ -1,129 +0,0 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<strings>
<str id="separator">|</str>
<!-- header -->
<str id="login_to_upload">to upload videos, log in first.</str>
<str id="register">register</str>
<str id="login">login</str>
<str id="login_openid">login with OpenID</str>
<str id="upload_video">upload video</str>
<str id="bookmarks">bookmarks</str>
<str id="account_details">account details</str>
<str id="logged_in_as">logged in as</str>
<str id="logout">logout</str>
<!-- footer -->
<str id="gnutube_authors">&#169; 2007 GNUtube team</str>
<str id="gnutube_license">license</str>
<str id="gnutube_source_code">download source code</str>
<!-- front page -->
<str id="button_find">Find</str>
<str id="button_lucky">Instant Access</str>
<str id="query_latestadditions">latest additions</str>
<str id="query_mostdownloads">most downloads</str>
<str id="query_bestrated">best rated</str>
<!-- errors -->
<str id="error_202c">Error 202c - Access forbidden by government.</str>
<str id="error_missing_file">You did not supply a file.</str>
<str id="error_missing_DC.Title">You did not supply a title.</str>
<str id="error_missing_DC.Creator">You did not supply a creator.</str>
<str id="error_missing_DC.Subject">You did not supply any keywords.</str>
<str id="error_missing_DC.Description">You did not supply a description.</str>
<str id="error_missing_DC.Publisher">You did not supply a publisher.</str>
<str id="error_missing_DC.Title">You did not supply a title.</str>
<str id="error_missing_DC.Source">You did not supply a source.</str>
<str id="error_missing_DC.Language">You did not supply a language.</str>
<str id="error_missing_DC.Coverage">You did not supply a coverage.</str>
<str id="error_missing_DC.Rights">You did not supply a rights holder.</str>
<str id="error_already_registered">You seem to be already registered. Please log out to create a new account.</str>
<str id="error_already_logged_in">You seem to be already logged in. Please log out to log in again.</str>
<str id="error_username_password_do_not_match">Username and password do not match.</str>
<str id=""></str>
<str id=""></str>
<str id=""></str>
<!-- information -->
<str id="information_logged_in">You are now logged in.</str>
<str id="information_logged_out">You are now logged out.</str>
<str id="information_metainformation_needed">To put the video into context, additional metainformation is needed.</str>
<str id="information_metainformation_rights"></str>
<str id="information_comment_created">Your comment has been created.</str>
<str id="information_registered">You successfully created yourself an account</str>
<str id="information_uploaded">You succcessfully uploaded your file</str>
<!-- warnings -->
<!-- results page-->
<str id="results_for_query">results for query</str>
<str id="ordered_by">ordered by</str>
<str id="ascending">ascending</str>
<str id="descending">descending</str>
<str id="results_on">results on</str>
<str id="pages">pages</str>
<str id="relevance">relevance</str>
<str id="duration">duration</str>
<str id="filesize">filesize</str>
<str id="viewcount">viewcount</str>
<str id="downloadcount">downloadcount</str>
<str id="timestamp">timestamp</str>
<!-- search bar-->
<str id="search">search</str>
<!-- login / register page -->
<str id="username">username</str>
<str id="password">password</str>
<str id="button_register">register</str>
<str id="button_login">login</str>
<!-- upload page -->
<str id="file">file</str>
<str id="button_next_page">next page</str>
<str id="button_upload">upload</str>
<str id="instruction_file">Specify the file you want to upload.</str>
<str id="instruction_title">State the title of the video.</str>
<str id="instruction_creator">Specify the creator of the video.</str>
<str id="instruction_subject">State some keywords, separated by commas.</str>
<str id="instruction_description">Describe the video in natural language.</str>
<str id="instruction_source">Specify the source, preferably by URL.</str>
<str id="instruction_language">State the language of the video.</str>
<str id="instruction_coverage">Specify the time and location covered.</str>
<str id="this_is_page_1">This is page 1 of 3.</str>
<str id="this_is_page_2">This is page 2 of 3.</str>
<str id="this_is_page_2">This is page 3 of 3.</str>
<!-- video page -->
<str id="download_video">download video</str>
<str id="license_conditions">license conditions</str>
<str id="comment_on_video">Flamewar area below. Proceed with Caution.</str>
<str id="comment_post">post comment</str>
<!-- dublin core entities -->
<str id="DC.Title">title</str>
<str id="DC.Creator">author</str>
<str id="DC.Subject">subject</str>
<str id="DC.Description">description</str>
<str id="DC.Publisher">uploader</str>
<str id="DC.Contributor">contributor</str>
<str id="DC.Date">date</str>
<str id="DC.Source">source</str>
<str id="DC.Language">language</str>
<str id="DC.Coverage">coverage</str>
<str id="DC.Rights">righs holder</str>
<str id="duration">duration</str>
<str id="viewcount">viewcount</str>
</strings>
</xsl:stylesheet>

View file

@ -7,16 +7,9 @@ CGI::Session->name($session_name);
$query = new CGI;
$session = new CGI::Session;
$username = get_username_from_sid($session->id);
@userinfo = get_userinfo_from_sid($session->id);
%page = ();
$page->{'username'} = $username;
$page->{'locale'} = $locale;
$page->{'stylesheet'} = $stylesheet;
$page->{'xmlns:dc'} = $xmlns_dc;
$page->{'xmlns:cc'} = $xmlns_cc;
$page->{'xmlns:rdf'} = $xmlns_rdf;
@page = get_page_array(@userinfo);
#check if action is set
if($query->param('action'))
@ -28,12 +21,12 @@ if($query->param('action'))
{
#if logout is requested
#remove sid from database
$dbh->do(qq{update users set sid = '' where username = ?}, undef, get_username_from_sid($session->id)) or die $dbh->errstr;
$dbh->do(qq{update users set sid = '' where id = ?}, undef, $userinfo->{'id'}) or die $dbh->errstr;
$session->delete();
print $query->redirect("index.pl?information=information_logged_out");
}
#check if user is logged in
elsif($username)
elsif($userinfo->{'username'})
{
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_already_logged_in";
@ -169,7 +162,7 @@ if($query->param('action'))
$dbh->disconnect();
}
#check if user is logged in
elsif($username)
elsif($userinfo->{'username'})
{
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_already_logged_in";

View file

@ -7,16 +7,9 @@ CGI::Session->name($session_name);
$query = new CGI;
$session = new CGI::Session;
$username = get_username_from_sid($session->id);
@userinfo = get_userinfo_from_sid($session->id);
%page = ();
$page->{'username'} = $username;
($page->{'locale'}) = $query->http('HTTP_ACCEPT_LANGUAGE') =~ /^([^,]+),.*$/;
$page->{'stylesheet'} = $stylesheet;
$page->{'xmlns:dc'} = $xmlns_dc;
$page->{'xmlns:cc'} = $xmlns_cc;
$page->{'xmlns:rdf'} = $xmlns_rdf;
@page = get_page_array(@userinfo);
#check if user is logged in
if($username)
@ -50,19 +43,19 @@ elsif($query->param('user') and $query->param('pass') and $query->param('pass_re
$page->{'message'}->{'text'} = "error_passwords_do_not_match";
}
}
elsif(not $query->param('user'))
elsif(not $query->param('user') and ($query->param('pass') or $query->param('pass_repeat')))
{
$page->{'registerform'} = [''];
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_insert_username";
}
elsif(not $query->param('pass'))
elsif(not $query->param('pass') and ($query->param('user') or $query->param('pass_repeat')))
{
$page->{'registerform'} = [''];
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_insert_password";
}
elsif(not $query->param('pass_repeat'))
elsif(not $query->param('pass_repeat') and ($query->param('user') or $query->param('pass')))
{
$page->{'registerform'} = [''];
$page->{'message'}->{'type'} = "error";

View file

@ -6,16 +6,9 @@ CGI::Session->name($session_name);
$query = new CGI;
$session = new CGI::Session;
$username = get_username_from_sid($session->id);
@userinfo = get_userinfo_from_sid($session->id);
%page = ();
$page->{'username'} = $username;
$page->{'locale'} = $locale;
$page->{'stylesheet'} = $stylesheet;
$page->{'xmlns:dc'} = $xmlns_dc;
$page->{'xmlns:cc'} = $xmlns_cc;
$page->{'xmlns:rdf'} = $xmlns_rdf;
@page = get_page_array(@userinfo);
#check if query is set
if($query->param('query') or $query->param('orderby'))
@ -111,7 +104,7 @@ if($query->param('query') or $query->param('orderby'))
$page->{'results'}->{'lastpage'} = $lastpage;
$page->{'results'}->{'currentpage'} = $currentpage;
$page->{'results'}->{'resultcount'} = $resultcount;
$page->{'results'}->{'resultcount'} = $resultcount eq '0E0' ? 0 : $resultcount;
$page->{'results'}->{'pagesize'} = $pagesize;
#get every returned value
@ -123,7 +116,7 @@ if($query->param('query') or $query->param('orderby'))
'thumbnail' => "./video-stills/$id",
'duration' => $duration,
'viewcount' => $viewcount,
'edit' => $username eq $publisher ? "true" : "false",
'edit' => $userinfo->{'username'} eq $publisher ? "true" : "false",
'rdf:RDF' =>
{
'cc:Work' =>

View file

@ -6,21 +6,13 @@ require "functions.pl";
CGI::Session->name($session_name);
my $session = new CGI::Session;
my $username = get_username_from_sid($session->id);
@userinfo = get_userinfo_from_sid($session->id);
%page = ();
@page = get_page_array(@userinfo);
#if a username is associated with session id, username is nonempty
$page->{'username'} = $username;
$page->{'locale'} = $locale;
$page->{'stylesheet'} = $stylesheet;
$page->{'xmlns:dc'} = $xmlns_dc;
$page->{'xmlns:cc'} = $xmlns_cc;
$page->{'xmlns:rdf'} = $xmlns_rdf;
if($username)
if($userinfo->{'username'})
{
$page->{uploadform} = {'page' => '2'};
$page->{uploadform} = {'page' => '1'};
}
else
{

View file

@ -18,19 +18,11 @@ sub hook
#close TEMP;
}
my $userid = get_userid_from_sid($session->id);
@userinfo = get_userinfo_from_sid($session->id);
%page = ();
@page = get_page_array(@userinfo);
#if a username is associated with session id, username is nonempty
$page->{'username'} = get_username_from_sid($session->id);
$page->{'locale'} = $locale;
$page->{'stylesheet'} = $stylesheet;
$page->{'xmlns:dc'} = $xmlns_dc;
$page->{'xmlns:cc'} = $xmlns_cc;
$page->{'xmlns:rdf'} = $xmlns_rdf;
if($userid)
if($userinfo->{'id'})
{
#connect to db
my $dbh = DBI->connect("DBI:mysql:$database:$host", $dbuser, $dbpass) or die $dbh->errstr;
@ -40,7 +32,7 @@ if($userid)
$dbh->do(qq{insert into uploaded (title, description, userid, timestamp,
creator, subject, contributor, source, language, coverage, rights)
values ( ?, ?, ?, unix_timestamp(), ?, ?, ?, ?, ?, ?, ? )}, undef,
$query->param("DC.Title"), $query->param("DC.Description"), $userid,
$query->param("DC.Title"), $query->param("DC.Description"), $userinfo->{'id'},
$query->param("DC.Creator"), $query->param("DC.Subject"), '', $query->param("DC.Source"),
$query->param("DC.Language"), $query->param("DC.Coverage"), '') or die $dbh->errstr;

View file

@ -6,15 +6,9 @@ CGI::Session->name($session_name);
$query = new CGI;
$session = new CGI::Session;
%page = ();
@userinfo = get_userinfo_from_sid($session->id);
#if a username is associated with session id, username is nonempty
$page->{'username'} = get_username_from_sid($session->id);
$page->{'locale'} = $locale;
$page->{'stylesheet'} = $stylesheet;
$page->{'xmlns:dc'} = $xmlns_dc;
$page->{'xmlns:cc'} = $xmlns_cc;
$page->{'xmlns:rdf'} = $xmlns_rdf;
@page = get_page_array(@userinfo);
if($query->url_param('edit') eq 'true' and $query->url_param('id'))
{
@ -79,7 +73,7 @@ elsif($query->url_param('title') or $query->url_param('id'))
$sth->finish() or die $dbh->errstr;
#if user is logged in
if($userid = get_userid_from_sid($session->id))
if($userinfo->{'username'})
{
#check if a comment is about to be created
if($query->param('comment'))
@ -89,7 +83,8 @@ elsif($query->url_param('title') or $query->url_param('id'))
$page->{'message'}->{'text'} = "information_comment_created";
#add to database
$dbh->do(qq{insert into comments (userid, videoid, text, timestamp) values (?, ?, ?, unix_timestamp())}, undef, $userid, $id, $query->param('comment')) or die $dbh->errstr;
$dbh->do(qq{insert into comments (userid, videoid, text, timestamp) values (?, ?, ?, unix_timestamp())}, undef,
$userinfo->{'id'}, $id, $query->param('comment')) or die $dbh->errstr;
}
}

View file

@ -145,6 +145,10 @@
<hr />
<xsl:if test="not(//frontpage)">
<xsl:call-template name="searchbar"/>
</xsl:if>
<xsl:if test="//message">
<xsl:call-template name="message"/>
</xsl:if>
@ -323,9 +327,6 @@
</xsl:template>
<xsl:template name="registerform">
<xsl:call-template name="searchbar"/>
<div class="registerform">
<form method="post">
@ -358,9 +359,6 @@
</xsl:template>
<xsl:template name="loginform">
<xsl:call-template name="searchbar"/>
<div class="loginform">
<xsl:choose>
<xsl:when test="//loginform/@action='openid'">
@ -427,13 +425,10 @@
</xsl:template>
<xsl:template name="uploadform">
<xsl:call-template name="searchbar"/>
<div class="uploadform">
<xsl:choose>
<xsl:when test="@page=1">
<xsl:when test="//uploadform/@page=1">
<form method="post" enctype="multipart/form-data">
<xsl:attribute name="action">
<xsl:value-of select="$site_strings[@id='page_uploader']" />
@ -464,7 +459,7 @@
</form>
</xsl:when>
<xsl:when test="@page=2">
<xsl:when test="//uploadform/@page=2">
<form method="post" enctype="multipart/form-data">
<xsl:attribute name="action">
<xsl:value-of select="$site_strings[@id='page_uploader']" />

View file

@ -7,8 +7,6 @@
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
<xsl:template name="results">
<xsl:call-template name="searchbar"/>
<div>
<xsl:choose>
<xsl:when test="//results/@query!=''">

View file

@ -8,9 +8,6 @@
>
<xsl:template name="video">
<xsl:call-template name="searchbar"/>
<div class="video">
<xsl:choose>
<xsl:when test="//video/@cortado='true'">