From 45c935fa185806635d0202e26ba52a0e75f8f2bc Mon Sep 17 00:00:00 2001 From: Brian Moses Hall Date: Tue, 5 Nov 2024 10:30:43 -0500 Subject: [PATCH 1/3] TTO-276 Revise queueing order in CRMS - Add a custom `PresentationOrder` to the Core project to prioritize mdp namespace. - Add a new `Project#queue_order` used the same way as `PresentationOrder` except: - It applies to the list of candidates being considered for addition to the Queue. - Like `PresentationOrder` the custom `ORDER BY` becomes the first order clause. --- cgi/CRMS.pm | 10 +++++++--- cgi/Project.pm | 18 +++++++++++++++--- cgi/Project/Core.pm | 10 ++++++++++ t/Project.t | 9 +++++++++ t/Project/Core.t | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 t/Project/Core.t diff --git a/cgi/CRMS.pm b/cgi/CRMS.pm index c029e2ad..3f11ba8b 100755 --- a/cgi/CRMS.pm +++ b/cgi/CRMS.pm @@ -1436,11 +1436,15 @@ sub LoadQueueForProject { my $project_name = $self->GetProjectRef($project)->name; my $sql = 'SELECT COUNT(*) FROM queue WHERE project=?'; my $queueSize = $self->SimpleSqlGet($sql, $project); - my $targetQueueSize = $self->GetProjectRef($project)->queue_size(); + my $project_ref = $self->GetProjectRef($project); + my $targetQueueSize = $project_ref->queue_size(); my $needed = $targetQueueSize - $queueSize; $self->ReportMsg("Project $project_name: $queueSize volumes -- need $needed"); return if $needed <= 0; my $count = 0; + my @orders = ('c.time DESC'); + my $project_order = $project_ref->queue_order; + unshift @orders, $project_order if defined $project_order; $sql = 'SELECT DISTINCT b.sysid FROM bibdata b'. ' INNER JOIN candidates c ON b.id = c.id'. ' WHERE b.id NOT IN (SELECT DISTINCT id FROM inherit)'. @@ -1448,7 +1452,7 @@ sub LoadQueueForProject { ' AND b.id NOT IN (SELECT DISTINCT id FROM reviews)'. ' AND b.id NOT IN (SELECT DISTINCT id FROM historicalreviews)'. ' AND c.time<=DATE_SUB(NOW(), INTERVAL 1 WEEK) AND c.project=?'. - ' ORDER BY c.time DESC'; + ' ORDER BY ' . join(',', @orders); my $ref = $self->SelectAll($sql, $project); my $potential = scalar @$ref; $self->ReportMsg("$potential qualifying catalog records for project $project queue"); @@ -1458,7 +1462,7 @@ sub LoadQueueForProject { $sql = 'SELECT c.id FROM candidates c'. ' INNER JOIN bibdata b ON c.id=b.id'. ' WHERE c.project=? AND b.sysid=?'. - ' ORDER BY c.time ASC'; + ' ORDER BY ' . join(',', @orders); my $ref2 = $self->SelectAll($sql, $project, $sysid); foreach my $row2 (@$ref2) { my $id = $row2->[0]; diff --git a/cgi/Project.pm b/cgi/Project.pm index 0bb0a9ca..9278145d 100644 --- a/cgi/Project.pm +++ b/cgi/Project.pm @@ -10,9 +10,11 @@ sub new $self->{$_} = $args{$_} for keys %args; my $id = $args{'id'}; die "No CRMS object passed to project" unless $args{'crms'}; - my $sql = 'SELECT * FROM projects WHERE id=?'; - my $ref = $self->{'crms'}->get('dbh')->selectall_hashref($sql, 'id', undef, $id); - $self->{$_} = $ref->{$id}->{$_} for keys %{$ref->{$id}}; + if (defined $id) { + my $sql = 'SELECT * FROM projects WHERE id=?'; + my $ref = $self->{'crms'}->get('dbh')->selectall_hashref($sql, 'id', undef, $id); + $self->{$_} = $ref->{$id}->{$_} for keys %{$ref->{$id}}; + } return $self; } @@ -93,6 +95,16 @@ sub EvaluateCandidacy } # ========== REVIEW INTERFACE ========== # +# Called by CRMS::LoadQueueForProject to prioritize candidates for the queue. +# Return undef for no additional order (the default), or +# a column name in bibdata (b.*) or candidates (c.*). +# Example: 'b.author DESC' +sub queue_order { + my $self = shift; + + return; +} + # Called by CRMS::GetNextItemForReview to order volumes. # Return undef for no additional order (the default), or # a column name in bibdata (b.*) or the queue (q.*). diff --git a/cgi/Project/Core.pm b/cgi/Project/Core.pm index 6c4da74a..dc706421 100644 --- a/cgi/Project/Core.pm +++ b/cgi/Project/Core.pm @@ -120,6 +120,16 @@ sub HasCCLicense } # ========== REVIEW ========== # +sub queue_order { + # Add mdp namespace to queue ahead of everything else. + return 'IF("mdp"=LEFT(c.id,LOCATE(".",c.id)-1),1,0) DESC'; +} + +sub PresentationOrder { + # Present mdp namespace ahead of everything else. + return 'IF("mdp"=LEFT(q.id,LOCATE(".",q.id)-1),1,0) DESC'; +} + sub ReviewPartials { return ['top', 'bibdata', 'authorities', diff --git a/t/Project.t b/t/Project.t index bbc40ad2..a3f3416a 100755 --- a/t/Project.t +++ b/t/Project.t @@ -6,6 +6,8 @@ BEGIN { unshift(@INC, $ENV{'SDRROOT'}. '/crms/cgi'); } use Test::More; +use CRMS; + my $dir = $ENV{'SDRROOT'}. '/crms/cgi/Project'; opendir(DIR, $dir) or die "Can't open $dir\n"; my @files = readdir(DIR); @@ -17,5 +19,12 @@ foreach my $file (sort @files) require_ok($path); } +my $crms = CRMS->new; + +my $project = Project->new(crms => $crms); +subtest '#queue_order' => sub { + is($project->queue_order, undef, 'default project has no queue_order'); +}; + done_testing(); diff --git a/t/Project/Core.t b/t/Project/Core.t new file mode 100644 index 00000000..d01feba7 --- /dev/null +++ b/t/Project/Core.t @@ -0,0 +1,35 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use utf8; + +use CGI; +use Data::Dumper; +use Test::More; + +use lib $ENV{'SDRROOT'} . '/crms/cgi'; +use lib $ENV{'SDRROOT'} . '/crms/t/support'; +use CRMS; +use FakeMetadata; + +require_ok($ENV{'SDRROOT'}. '/crms/cgi/Project/Core.pm'); + +my $crms = CRMS->new(); +# TODO: Project::for_name would be a much nicer way to do this. +my $sql = 'SELECT id FROM projects WHERE name="Core"'; +my $project_id = $crms->SimpleSqlGet($sql); +my $project = Core->new(crms => $crms, id => $project_id); +ok(defined $project); + +subtest '#queue_order' => sub { + ok(defined $project->queue_order, 'Core project defines a queue_order'); +}; + +subtest '#PresentationOrder' => sub { + ok(defined $project->PresentationOrder, 'Core project defines a PresentationOrder'); +}; + +done_testing(); + + From 9632799096c1ae2a6e702c8d360cdc8e5167a966 Mon Sep 17 00:00:00 2001 From: Brian Moses Hall Date: Thu, 7 Nov 2024 14:41:29 -0500 Subject: [PATCH 2/3] Respond to reviewer feedback. --- cgi/CRMS.pm | 3 +-- cgi/Project.pm | 12 ++---------- t/Project.t | 4 ++++ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/cgi/CRMS.pm b/cgi/CRMS.pm index 3f11ba8b..e52ed66b 100755 --- a/cgi/CRMS.pm +++ b/cgi/CRMS.pm @@ -1461,8 +1461,7 @@ sub LoadQueueForProject { my $record = $self->GetMetadata($sysid); $sql = 'SELECT c.id FROM candidates c'. ' INNER JOIN bibdata b ON c.id=b.id'. - ' WHERE c.project=? AND b.sysid=?'. - ' ORDER BY ' . join(',', @orders); + ' WHERE c.project=? AND b.sysid=?'; my $ref2 = $self->SelectAll($sql, $project, $sysid); foreach my $row2 (@$ref2) { my $id = $row2->[0]; diff --git a/cgi/Project.pm b/cgi/Project.pm index 9278145d..4c6ee4cf 100644 --- a/cgi/Project.pm +++ b/cgi/Project.pm @@ -99,22 +99,14 @@ sub EvaluateCandidacy # Return undef for no additional order (the default), or # a column name in bibdata (b.*) or candidates (c.*). # Example: 'b.author DESC' -sub queue_order { - my $self = shift; - - return; -} +sub queue_order { } # Called by CRMS::GetNextItemForReview to order volumes. # Return undef for no additional order (the default), or # a column name in bibdata (b.*) or the queue (q.*). # Example: 'b.author DESC' -sub PresentationOrder -{ - my $self = shift; +sub PresentationOrder { } - return; -} sub ReviewPartials { diff --git a/t/Project.t b/t/Project.t index a3f3416a..595102a6 100755 --- a/t/Project.t +++ b/t/Project.t @@ -26,5 +26,9 @@ subtest '#queue_order' => sub { is($project->queue_order, undef, 'default project has no queue_order'); }; +subtest '#PresentationOrder' => sub { + is($project->PresentationOrder, undef, 'default project has no PresentationOrder'); +}; + done_testing(); From 2df7c34e396ab2b6cbda4211b22e45832afb95e3 Mon Sep 17 00:00:00 2001 From: Brian Moses Hall Date: Thu, 7 Nov 2024 14:42:06 -0500 Subject: [PATCH 3/3] Update to latest post_zephir_processing submodule --- post_zephir_processing | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post_zephir_processing b/post_zephir_processing index ead75711..dab7740e 160000 --- a/post_zephir_processing +++ b/post_zephir_processing @@ -1 +1 @@ -Subproject commit ead75711f148a1a67ac5599072dba518b50e2408 +Subproject commit dab7740e421c6c6f4269832f37de9345f5443039