Skip to content

Commit

Permalink
Redo completely how we do non-port commit lists
Browse files Browse the repository at this point in the history
Don't show the commit details (i.e. all items in the commit).
That approach became query-intensive and heavy.

This also aligns the non-port list with the port list of commits.

Fixes #494
  • Loading branch information
dlangille committed Nov 14, 2023
1 parent 0338f8e commit 0820f3c
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 137 deletions.
163 changes: 70 additions & 93 deletions classes/commits_by_tree_location.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,111 +183,88 @@ function FetchPortCommits() {
# neither of these arguments are used in this function
# they are present to be compatible with the parent class
function Fetch($date = null, $UserID = null) {
$params = array();
$sql = "-- " . __FILE__ . '::' . __FUNCTION__ . "
SELECT DISTINCT
CL.commit_date - SystemTimeAdjust() AS commit_date_raw,
CL.id AS commit_log_id,
CL.encoding_losses AS encoding_losses,
CL.message_id AS message_id,
CL.commit_hash_short AS commit_hash_short,
CL.committer AS committer,
CL.committer_name AS committer_name,
CL.committer_email AS committer_email,
CL.author_name AS author_name,
CL.author_email AS author_email,
CL.description AS commit_description,
to_char(CL.commit_date - SystemTimeAdjust(), 'DD Mon YYYY') AS commit_date,
to_char(CL.commit_date - SystemTimeAdjust(), 'HH24:MI') AS commit_time,
element.name AS port,
element_pathname(element.id) AS pathname,
element.status AS status,
element_pathname.pathname AS element_pathname,
CL.message_subject,
CL.svn_revision AS svn_revision,
NULL AS port_id,
0 AS needs_refresh,
NULL AS forbidden,
NULL AS broken,
NULL AS deprecated,
NULL AS ignore,
commit_log_elements.element_id,
NULL AS version,
NULL AS epoch,
NULL as date_added,
NULL AS short_description,
NULL AS category_id,
NULL AS category,
NULL AS watch,
NULL AS vulnerable_current,
NULL AS vulnerable_past,
NULL AS restricted,
NULL AS no_cdrom,
NULL AS expiration_date,
NULL AS is_interactive,
NULL AS only_for_archs,
NULL AS not_for_archs,
NULL AS stf_message,
commit_log_elements.revision_name as revision,
R.name AS repo_name,
R.repository AS repository,
R.repo_hostname AS repo_hostname,
R.path_to_repo AS path_to_repo ";
if ($this->UserID) {
$sql .= ",
onwatchlist ";
} else {
$sql .= ",
null AS onwatchlist ";
}
with mycommits as (
SELECT tmp.ID as commit_log_id FROM (SELECT DISTINCT CL.id, CL.commit_date
FROM element_pathname EP, commit_log_elements CLE, commit_log CL
WHERE " . $this->TreePathCondition . "
AND EP.element_id = CLE.element_ID
AND CL.id = CLE.commit_log_id
ORDER BY CL.commit_date DESC\n";

$sql .= "
FROM commit_log_elements, commit_log CL LEFT OUTER JOIN repo R on CL.repo_id = R.id, element_pathname, element ";
if ($this->Limit) {
$params[] = $this->Limit;
$sql .= "\nLIMIT $" . count($params);
}

if ($this->UserID) {
$params[] = $this->UserID;
$sql .= "
LEFT OUTER JOIN
(SELECT element_id as wle_element_id, COUNT(watch_list_id) as onwatchlist
FROM watch_list JOIN watch_list_element
ON watch_list.id = watch_list_element.watch_list_id
AND watch_list.user_id = $" . count($params) . "
AND watch_list.in_service
GROUP BY wle_element_id) AS TEMP
ON TEMP.wle_element_id = element.id";
if ($this->Offset) {
$params[] = $this->Offset;
$sql .= "\nOFFSET $" . count($params) ;
}

$sql .= "
) as tmp)
SELECT DISTINCT
CL.commit_date - SystemTimeAdjust() AS commit_date_raw,
CL.id AS commit_log_id,
CL.encoding_losses AS encoding_losses,
CL.message_id AS message_id,
CL.commit_hash_short AS commit_hash_short,
CL.committer AS committer,
CL.committer_name AS committer_name,
CL.committer_email AS committer_email,
CL.author_name AS author_name,
CL.author_email AS author_email,
CL.description AS commit_description,
to_char(CL.commit_date - SystemTimeAdjust(), 'DD Mon YYYY') AS commit_date,
to_char(CL.commit_date - SystemTimeAdjust(), 'HH24:MI') AS commit_time,
null AS port,
null AS pathname,
null AS status,
null AS element_pathname,
CL.message_subject,
CL.svn_revision AS svn_revision,
NULL AS port_id,
0 AS needs_refresh,
NULL AS forbidden,
NULL AS broken,
NULL AS deprecated,
NULL AS ignore,
null as element_id,
NULL AS version,
NULL AS epoch,
NULL as date_added,
NULL AS short_description,
NULL AS category_id,
NULL AS category,
NULL AS watch,
NULL AS vulnerable_current,
NULL AS vulnerable_past,
NULL AS restricted,
NULL AS no_cdrom,
NULL AS expiration_date,
NULL AS is_interactive,
NULL AS only_for_archs,
NULL AS not_for_archs,
NULL AS stf_message,
null as revision,
R.name AS repo_name,
R.repository AS repository,
R.repo_hostname AS repo_hostname,
R.path_to_repo AS path_to_repo,
null AS onwatchlist ";

# I tried to make '$this->TreePathCondition' a parameter. I was blocked by this error:
# Warning: pg_query_params(): Query failed: ERROR: invalid input syntax for type boolean: ""EP.pathname = '/ports/head/MOVED'"" in /usr/local/www/freshports/classes/commits_by_tree_location.php on line 291
# pg_query_params failed:

$sql .= "
WHERE CL.id IN (SELECT tmp.ID FROM (SELECT DISTINCT CL.id, CL.commit_date
FROM element_pathname EP, commit_log_elements CLE, commit_log CL
WHERE $this->TreePathCondition
AND EP.element_id = CLE.element_ID
AND CL.id = CLE.commit_log_id
ORDER BY CL.commit_date DESC ";

if ($this->Limit) {
$sql .= "\nLIMIT $" . count($params) + 1;
$params[] = $this->Limit;
}

if ($this->Offset) {
$sql .= "\nOFFSET $" . count($params) + 1;
$params[] = $this->Offset;
}

$sql .= ") AS tmp)
AND commit_log_elements.commit_log_id = CL.id
AND commit_log_elements.element_id = element.id
AND element_pathname.element_id = element.id
ORDER BY 1 desc,
commit_log_id, element_pathname";

FROM mycommits MC join commit_log CL on MC.commit_log_id = CL.id
LEFT OUTER JOIN repo R on CL.repo_id = R.id ";


$sql .= "
ORDER BY 1 desc, commit_log_id, element_pathname";

if ($this->Debug) echo '<pre>' . $sql . '</pre>';

Expand Down
74 changes: 35 additions & 39 deletions classes/display_commit.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ function CreateHTML() {
$mycommit = new Commit_Ports($this->dbh);
$mycommit->PopulateValues($myrow);

# echo '<pre>'; var_dump($mycommit); echo '</pre>';

if ($mycommit->branch && $mycommit->branch != BRANCH_HEAD) {
$QueryArgs= '?branch=' . $mycommit->branch;
} else {
Expand All @@ -135,22 +133,14 @@ function CreateHTML() {
if ($mycommit->commit_log_id != $PreviousCommit->commit_log_id) {
if ($Debug) echo 'This commit_log_id is different<br>';
if (($NumberOfPortsInThisCommit > $MaxNumberPortsToShow) && !$this->ShowAllPorts) {
$this->HTML .= '</ul>' . freshports_MorePortsToShow($PreviousCommit->message_id, $NumberOfPortsInThisCommit, $MaxNumberPortsToShow);
} else if ($i > 0) {
if ($DetailsWillBePresented) {
$this->HTML .= '</ul>';
}
$this->HTML .= freshports_MorePortsToShow($PreviousCommit->message_id, $NumberOfPortsInThisCommit, $MaxNumberPortsToShow);
} else if ($i > 0 && $DetailsWillBePresented) {
$this->HTML .= '</ul>';
}
$TooManyPorts = false;
# if ($i > 0) {
# $this->HTML .= "\n<blockquote class=\"description\">";
# $this->HTML .= 'The commit message goes here';
# $this->HTML .= freshports_CommitDescriptionPrint(
# $PreviousCommit->commit_description,
# $PreviousCommit->encoding_losses,
# $Lines,
# freshports_MoreCommitMsgToShow($PreviousCommit->message_id, $Lines));
# # close off the previous commit first
# $this->HTML .= "\n</blockquote>\n</td></tr>\n\n\n";
# }
# count the number of ports in this commit.
# first time into the loop, this will be executed.
$NumberOfPortsInThisCommit = 0;
Expand Down Expand Up @@ -197,9 +187,6 @@ function CreateHTML() {
}
$this->HTML .= '</span>';

# $this->HTML .= '<br>next is the commit message';



$this->HTML .= "\n<blockquote class=\"description\">";
$this->HTML .= freshports_CommitDescriptionPrint(
Expand Down Expand Up @@ -239,8 +226,6 @@ function CreateHTML() {
$this->HTML .= '&nbsp;' . freshports_SanityTestFailure_Link($mycommit->message_id);
}

# echo '<pre>' . print_r($mycommit, true) . '</pre>';

if ($mycommit->svn_revision != '') {
if ($this->IsGitCommit($mycommit->message_id)) {
$this->HTML .= freshports_git_commit_Link_freebsd ($mycommit->svn_revision, $mycommit->repo_hostname, $mycommit->path_to_repo) . '&nbsp;';
Expand All @@ -257,13 +242,16 @@ function CreateHTML() {
if (!empty($mycommit->branch) && $this->BranchName != $mycommit->branch || $this->BranchName != BRANCH_HEAD) {
$this->HTML .= ' <span class="commit-branch">' . $mycommit->branch . '</span>';
}

$this->HTML .= '</span>';

# $this->HTML .= "</td></tr>\n\n\n";
# $this->HTML .= '<tr><td class="commit-details">';
$this->HTML .= '<p>Details:</p>';
# $this->HTML .= '</span>';
$DetailsWillBePresented = !empty($mycommit->element_pathname);

if ($DetailsWillBePresented) {
$this->HTML .= '<p>Details:</p>';

$this->HTML .= "<ul class=\"element-list\">\n";
$this->HTML .= '<ul class="element-list">' . "\n";
}

}

Expand All @@ -275,7 +263,9 @@ function CreateHTML() {
if ($Debug) echo 'at too many<br>';

if (!$TooManyPorts) {
$this->HTML .= '<li>';
if ($DetailsWillBePresented) {
$this->HTML .= '<li>';
}
#
# XXX This 0 is in the if beacuse I'm testing the ELSE portion for all purposes
#
Expand All @@ -296,7 +286,6 @@ function CreateHTML() {
}

$this->HTML .= '<span class="element-details">';
# $this->HTML .= '<a href="/' . $mycommit->category . '/' . $mycommit->port . '/' . $URLBranchSuffix;
$this->HTML .= '<a href="/' . $mycommit->category . '/' . $mycommit->port . '/';

$this->HTML .= $QueryArgs . '">';
Expand Down Expand Up @@ -377,8 +366,15 @@ function CreateHTML() {

$this->HTML.= freshports_Fallout_Link($mycommit->category, $mycommit->port) . '&nbsp;';
} else {
if (!$DetailsWillBePresented) {
# we do nothing
# this is a non-port. All the rest of the stuff is not displayed
} else {
syslog(LOG_NOTICE, 'We have non-port where element_pathname is not empty');

# This is a non-port element...
$this->HTML .= '<span class="element-details">';

$PathName = preg_replace('|^/?ports/|', '', $mycommit->element_pathname);
if ($Debug) echo "PathName='$PathName' " . " reponame='" . $mycommit->repo_name . "'<br>";
switch ($mycommit->repo_name)
Expand Down Expand Up @@ -475,9 +471,12 @@ function CreateHTML() {

$this->HTML.= freshports_Fallout_Link($mycommit->category, $mycommit->port) . '&nbsp;';
}
} # else !empty($mycommit->element_pathname)
}

if ($DetailsWillBePresented) {
$this->HTML .= "</li>\n";
}
# $this->HTML .= htmlify(_forDisplay($mycommit->short_description));
$this->HTML .= "</li>\n";

GLOBAL $freshports_CommitMsgMaxNumOfLinesToShow;
if ($this->ShowEntireCommit) {
Expand All @@ -492,18 +491,15 @@ function CreateHTML() {
}

if (($NumberOfPortsInThisCommit > $MaxNumberPortsToShow) && !$this->ShowAllPorts) {
$this->HTML .= '</ul>' . freshports_MorePortsToShow($PreviousCommit->message_id, $NumberOfPortsInThisCommit, $MaxNumberPortsToShow);
if ($DetailsWillBePresented) {
$this->HTML .= '</ul>';
}
$this->HTML .= freshports_MorePortsToShow($PreviousCommit->message_id, $NumberOfPortsInThisCommit, $MaxNumberPortsToShow);
} else {
$this->HTML .= '</ul>';
if ($DetailsWillBePresented) {
$this->HTML .= '</ul>';
}
}
# $this->HTML .= "\n<blockquote class=\"description\">";
# $this->HTML .= freshports_CommitDescriptionPrint(
# $PreviousCommit->commit_description,
# $PreviousCommit->encoding_losses,
# $Lines,
# freshports_MoreCommitMsgToShow($PreviousCommit->message_id, $Lines));
# # close off the last commit
# $this->HTML .= "\n</blockquote>\n</td></tr>\n\n\n";

unset($mycommit);

Expand Down
9 changes: 4 additions & 5 deletions include/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,10 @@
const SQL_WITH_PACKAGES = '
with packages as
(with package_names as
(select P.id as port_id, P.package_name as package_name
FROM ports P where P.package_name ilike $1
UNION
select PV.port_id as port_id, PV.name as package_name
FROM package_flavors PV where name ilike $1
(select distinct port_id, package_name
from packages
where package_set = \'latest\'
and package_name ilike $1
)
select distinct port_id, array_agg(package_name) as package_names from package_names
group by port_id
Expand Down

0 comments on commit 0820f3c

Please sign in to comment.