Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control order of projects in mirrors report #294

Merged
merged 2 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/MirrorCache/Schema/ResultSet/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ from (
group by server_id, project_id, name
) smry
join project_folder_count on project_folder_count.project_id = smry.project_id
join server s on smry.server_id = s.id
join server s on smry.server_id = s.id and s.enabled
order by region, country, score, url, project;
END_SQL
my $prep = $dbh->prepare($sql);
Expand Down
4 changes: 2 additions & 2 deletions lib/MirrorCache/WebAPI/Plugin/Project.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ sub _init_if_needed {
my ($c) = @_;
$initialized = 1;
eval { #the table may be missing - no big deal (only reports might be inaccurate if some other error occurred).
@projects = $c->schema->resultset('Project')->all;
@projects = $c->schema->resultset('Project')->search(undef, { order_by => { -desc => [qw/prio name/] } });
1;
} or $c->log->error(Dumper("Cannot load projects", @_));
} or $c->log->error(Dumper("Cannot load projects", $@));

for my $p (@projects) {
my $name = $p->name;
Expand Down
2 changes: 2 additions & 0 deletions lib/MirrorCache/resources/migrations/Pg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,6 @@ create table report_body (
create index if not exists report_content_dt_inx on report_body(report_id, dt);
-- 25 up
alter table project add column if not exists redirect varchar(512);
-- 26 up
alter table project add column if not exists prio int;

2 changes: 2 additions & 0 deletions lib/MirrorCache/resources/migrations/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,6 @@ create table report_body (
create index if not exists report_content_dt_inx on report_body(report_id, dt);
-- 25 up
alter table project add column if not exists redirect varchar(512);
-- 26 up
alter table project add column if not exists prio int;

14 changes: 12 additions & 2 deletions t/environ/14-project-report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ ap7=$(environ ap7)
ap6=$(environ ap6)
ap5=$(environ ap5)
ap4=$(environ ap4)
ap3=$(environ ap3)

for x in $mc $ap7 $ap8 $ap6 $ap5 $ap4; do
for x in $mc $ap7 $ap8 $ap6 $ap5 $ap4 $ap3; do
mkdir -p $x/dt/{folder1,folder2,folder3}
mkdir -p $x/dt/project1/{folder1,folder2,folder3}
mkdir -p $x/dt/project2/{folder1,folder2,folder3}
Expand All @@ -20,6 +21,7 @@ for x in $mc $ap7 $ap8 $ap6 $ap5 $ap4; do
echo $x/dt/project2/{folder1,folder2,folder3}/{file1.1,file2.1}.dat | xargs -n 1 touch
done

$ap3/start
$ap4/start
$ap5/start
$ap6/start
Expand All @@ -38,9 +40,10 @@ $mc/sql "insert into server(hostname,urldir,enabled,country,region) select '$($a
$mc/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap8/print_address)','','t','de','eu'"
$mc/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap5/print_address)','','t','cn','as'"
$mc/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap4/print_address)','','t','jp','as'"
$mc/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap3/print_address)','','f','jp','as'"

$mc/sql "insert into project(name,path,etalon) select 'proj1','/project1', 3"
$mc/sql "insert into project(name,path,etalon) select '2.0 1','/project2/folder1', 3"
$mc/sql "insert into project(name,path,etalon) select 'proj1','/project1', 3"
$mc/sql "insert into project(name,path,etalon) select '2.0 2','/project2/folder2', 3"

$mc/backstage/job -e folder_sync -a '["/project1/folder1"]'
Expand All @@ -64,3 +67,10 @@ $mc/curl /report/mirrors | tidy --drop-empty-elements no | \
grep -C3 '\b2\b' | \
grep -C3 -F '</a>'


rc=0
# no disabled mirror in the report
$mc/curl /report/mirrors | grep $($ap3/print_address) || rc=$?
test $rc -gt 0

echo success
1 change: 1 addition & 0 deletions t/lib/environ/mc/source/sql.sh.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
test "$MIRRORCACHE_DB_PROVIDER" != mariadb || {

sql=${1/"'t'"/"1"}
sql=${sql/"'f'"/"0"}
sql=${sql/"extract(epoch from now())"/"unix_timestamp()"}

re="(update|insert|select)(.*)\s([a-z_A-Z]*)((\([a-z_0-9]*\))?) - interval '([0-9]+) (month|day|hour|minute|second)'(.*)$"
Expand Down