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

TTO-276 Revise queueing order in CRMS #193

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions cgi/CRMS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1436,19 +1436,23 @@ 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');
moseshll marked this conversation as resolved.
Show resolved Hide resolved
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)'.
' AND b.id NOT IN (SELECT DISTINCT id FROM queue)'.
' 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");
Expand All @@ -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';
moseshll marked this conversation as resolved.
Show resolved Hide resolved
' ORDER BY ' . join(',', @orders);
my $ref2 = $self->SelectAll($sql, $project, $sysid);
foreach my $row2 (@$ref2) {
my $id = $row2->[0];
Expand Down
18 changes: 15 additions & 3 deletions cgi/Project.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this so we could create a Project instance without an id (primary key). Normally we never instantiate the Project class, just the subclasses, but this gives me a chance to test the default behavior without writing tests for all of the subclasses (definitely out of scope for this ticket).

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;
}

Expand Down Expand Up @@ -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 {
moseshll marked this conversation as resolved.
Show resolved Hide resolved
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.*).
Expand Down
10 changes: 10 additions & 0 deletions cgi/Project/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
9 changes: 9 additions & 0 deletions t/Project.t
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

35 changes: 35 additions & 0 deletions t/Project/Core.t
Original file line number Diff line number Diff line change
@@ -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();