Skip to content

Commit

Permalink
Save memory in representation of review preferences.
Browse files Browse the repository at this point in the history
SEC is having memory problems.
  • Loading branch information
kohler committed Oct 25, 2023
1 parent 6f10196 commit b92670c
Show file tree
Hide file tree
Showing 18 changed files with 163 additions and 126 deletions.
12 changes: 6 additions & 6 deletions src/api/api_preference.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ static function pref_api(Contact $user, Qrequest $qreq, PaperInfo $prow = null)
$prow->load_preferences();
}

$pref = $prow->preference($u, true);
$value = unparse_preference($pref);
$jr = new JsonResult(["ok" => true, "value" => $value === "0" ? "" : $value, "pref" => $pref[0]]);
if ($pref[1] !== null) {
$jr->content["prefexp"] = unparse_expertise($pref[1]);
$pf = $prow->preference($u);
$value = $pf->unparse();
$jr = new JsonResult(["ok" => true, "value" => $value === "0" ? "" : $value, "pref" => $pf->preference]);
if ($pf->expertise !== null) {
$jr->content["prefexp"] = unparse_expertise($pf->expertise);
}
if ($user->conf->has_topics()) {
$jr->content["topic_score"] = $pref[2];
$jr->content["topic_score"] = $prow->topic_interest_score($u);
}
if ($qreq->method() === "POST" && $prow->timeWithdrawn > 0) {
foreach ($prow->make_whynot(["withdrawn" => 1])->message_list(null, 1) as $mi) {
Expand Down
30 changes: 15 additions & 15 deletions src/assigners/a_preference.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,46 +156,46 @@ static function make(AssignmentItem $item, AssignmentState $state) {
function unparse_description() {
return "preference";
}
/** @return ?array{int,?int} */
/** @return ?PaperReviewPreference */
private function preference_data($before) {
$p = [$this->item->get($before, "_pref"),
$this->item->get($before, "_exp")];
if ($p[1] === "N") {
$p[1] = null;
$pref = $this->item->get($before, "_pref");
$exp = $this->item->get($before, "_exp");
if ($exp === "N") {
$exp = null;
}
return $p[0] || $p[1] !== null ? $p : null;
return $pref || $exp !== null ? new PaperReviewPreference($pref, $exp) : null;
}
function unparse_display(AssignmentSet $aset) {
if (!$this->cid) {
return "remove all preferences";
}
$t = $aset->user->reviewer_html_for($this->contact);
if (($p = $this->preference_data(true))) {
$t .= " <del>" . unparse_preference_span($p, true) . "</del>";
if (($pf = $this->preference_data(true))) {
$t .= " <del>" . $pf->unparse_span() . "</del>";
}
if (($p = $this->preference_data(false))) {
$t .= " <ins>" . unparse_preference_span($p, true) . "</ins>";
if (($pf = $this->preference_data(false))) {
$t .= " <ins>" . $pf->unparse_span() . "</ins>";
}
return $t;
}
function unparse_csv(AssignmentSet $aset, AssignmentCsv $acsv) {
$p = $this->preference_data(false);
$pref = $p ? unparse_preference($p) : "none";
$pf = $this->preference_data(false);
$acsv->add([
"pid" => $this->pid, "action" => "preference",
"email" => $this->contact->email, "name" => $this->contact->name(),
"preference" => $pref
"preference" => $pf ? $pf->unparse() : "none"
]);
}
function add_locks(AssignmentSet $aset, &$locks) {
$locks["PaperReviewPreference"] = "write";
}
function execute(AssignmentSet $aset) {
if (($p = $this->preference_data(false))) {
if (($pf = $this->preference_data(false))) {
$aset->stage_qe("insert into PaperReviewPreference
set paperId=?, contactId=?, preference=?, expertise=?
on duplicate key update preference=?, expertise=?",
$this->pid, $this->cid, $p[0], $p[1], $p[0], $p[1]);
$this->pid, $this->cid, $pf->preference, $pf->expertise,
$pf->preference, $pf->expertise);
} else {
$aset->stage_qe("delete from PaperReviewPreference where paperId=? and contactId=?", $this->pid, $this->cid);
}
Expand Down
11 changes: 9 additions & 2 deletions src/assigners/a_review.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ static function make(AssignmentItem $item, AssignmentState $state) {
function unparse_description() {
return "review";
}
/** @return string */
private function unparse_preference_span(AssignmentSet $aset) {
$prow = $aset->prow($this->pid);
$pf = $prow->preference($this->cid);
$tv = $pf->preference ? null : $prow->topic_interest_score($this->cid);
return $pf->exists() || $tv ? " " . $pf->unparse_span($tv) : "";
}
private function unparse_item(AssignmentSet $aset, $before) {
if (!$this->item->get($before, "_rtype")) {
return "";
Expand All @@ -297,7 +304,7 @@ private function unparse_item(AssignmentSet $aset, $before) {
$t .= '<span class="revround" title="Review round">'
. htmlspecialchars($aset->conf->round_name($round)) . '</span>';
}
return $t . unparse_preference_span($aset->prow($this->pid)->preference($this->cid, true));
return $t . $this->unparse_preference_span($aset);
}
private function icon($before) {
return review_type_icon($this->item->get($before, "_rtype"),
Expand Down Expand Up @@ -329,7 +336,7 @@ function unparse_display(AssignmentSet $aset) {
$t .= '<span class="revround" title="Review round">' . htmlspecialchars($aset->conf->round_name($round)) . '</span>';
}
if (!$this->item->existed()) {
$t .= unparse_preference_span($aset->prow($this->pid)->preference($this->cid, true));
$t .= $this->unparse_preference_span($aset);
}
return $t;
}
Expand Down
5 changes: 4 additions & 1 deletion src/autoassigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,10 @@ protected function load_review_preferences($reviewtype) {
// process conflicts and preferences
foreach ($this->acs as $ac) {
$a = $this->ainfo[$ac->cid][$pid];
list($a->pref, $a->exp, $a->topicscore) = $row->preference($ac->user, true);
$pf = $row->preference($ac->user);
$a->pref = $pf->preference;
$a->exp = $pf->expertise;
$a->topicscore = $row->topic_interest_score($ac->user);
if ($a->eass < self::ENOASSIGN
&& ($row->has_conflict($ac->user)
|| !$ac->user->can_accept_review_assignment($row))) {
Expand Down
10 changes: 6 additions & 4 deletions src/formulas/f_pref.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ function compile(FormulaCompiler $state) {
return "null";
}
$state->queryOptions["allReviewerPreference"] = true;
$e = "((" . $state->_add_preferences() . "[" . $state->loop_cid(true) . "] ?? [])"
. "[" . ($this->is_expertise ? 1 : 0) . "] ?? null)";
$pref = $state->_add_preferences();
$cid = $state->loop_cid(!$this->cids);
$condition = "isset({$pref}[{$cid}])";
if ($this->cids) {
$e = "(in_array(" . $state->loop_cid() . ", [" . join(",", $this->cids) . "]) ? {$e} : null)";
$condition .= " && in_array({$cid}, [" . join(",", $this->cids) . "])";
}
return $e;
$property = $this->is_expertise ? "expertise" : "preference";
return "({$condition} ? {$pref}[{$cid}]->{$property} : null)";
}
}
30 changes: 2 additions & 28 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,8 @@ function unparse_expertise($expertise) {
}

/** @param array{int,?int} $preference
* @return string */
* @return string
* @deprecated */
function unparse_preference($preference) {
assert(is_array($preference)); // XXX remove
$pv = $preference[0];
Expand All @@ -557,33 +558,6 @@ function unparse_preference($preference) {
return $pv . unparse_expertise($ev);
}

/** @param array{int,?int} $preference
* @return string */
function unparse_preference_span($preference, $always = false) {
assert(is_array($preference)); // XXX remove
$pv = (int) $preference[0];
$ev = $preference[1];
$tv = (int) ($preference[2] ?? null);
if ($pv > 0 || (!$pv && $tv > 0)) {
$type = 1;
} else if ($pv < 0 || $tv < 0) {
$type = -1;
} else {
$type = 0;
}
$t = "";
if ($pv || $ev !== null || $always) {
$t .= "P" . unparse_number_pm_html($pv) . unparse_expertise($ev);
}
if ($tv && !$pv) {
$t .= ($t ? " " : "") . "T" . unparse_number_pm_html($tv);
}
if ($t !== "") {
$t = " <span class=\"asspref$type\">$t</span>";
}
return $t;
}

/** @param int $revtype
* @param bool $unfinished
* @param ?string $classes
Expand Down
11 changes: 7 additions & 4 deletions src/listactions/la_getallrevpref.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,23 @@ function run(Contact $user, Qrequest $qreq, SearchSelection $ssel) {
}
$ctypes = $prow->conflict_types();
foreach ($pcm as $uid => $p) {
$pref = $prow->preference($p);
$pf = $prow->preference($p);
$ctype = $ctypes[$uid] ?? 0;
$is_cflt = Conflict::is_conflicted($ctype);
$ts = $prow->topic_interest_score($p);
if ($pref[0] === 0 && $pref[1] === null && $ts === 0 && !$is_cflt) {
if ($pf->preference === 0
&& $pf->expertise === null
&& $ts === 0
&& !$is_cflt) {
continue;
}
$l = [
$prow->paperId, $prow->title,
$p->firstName, $p->lastName, $p->email,
$is_cflt ? "conflict" : "", $pref[0] ? : ""
$is_cflt ? "conflict" : "", $pf->preference ? : ""
];
if ($has_expertise) {
$l[] = unparse_expertise($pref[1]);
$l[] = unparse_expertise($pf->expertise);
}
if ($has_interest) {
$l[] = $ts ? : "";
Expand Down
2 changes: 1 addition & 1 deletion src/listactions/la_revpref.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function run_get(Contact $user, Qrequest $qreq, SearchSelection $ssel,
if ($not_me) {
$item["email"] = $reviewer->email;
}
$item["preference"] = unparse_preference($prow->preference($reviewer));
$item["preference"] = $prow->preference($reviewer)->unparse();
if ($prow->has_conflict($reviewer)) {
$item["notes"] = "conflict";
$fields["notes"] = true;
Expand Down
6 changes: 5 additions & 1 deletion src/pages/p_assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,11 @@ private function print_pc_assignment($pc, $acs) {
$rrow ? $rrow->round_h() : "";
}
if ($revtype >= 0) {
echo unparse_preference_span($this->prow->preference($pc, true));
$pf = $this->prow->preference($pc);
$tv = $pf->preference ? null : $this->prow->topic_interest_score($pc);
if ($pf->exists() || $tv) {
echo " ", $pf->unparse_span($tv);
}
}
echo '</div>'; // .pctbname
if ($potconf) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/p_conflictassign.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static function go($user, $qreq) {
return $all && Conflict::is_conflicted($ct);
} else {
return !Conflict::is_conflicted($ct)
&& ($row->preference($user)[0] <= -100
&& ($row->preference($user)->preference <= -100
|| $row->potential_conflict($user));
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/papercolumns/pc_conflictmatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ function content_empty(PaperList $pl, PaperInfo $row) {
return !$pl->user->allow_administer($row);
}
function content(PaperList $pl, PaperInfo $row) {
$pref = $row->preference($this->contact);
$pf = $row->preference($this->contact);
$potconf = $row->potential_conflict_html($this->contact, true);
if ($pref[0] <= -100) {
if ($pf->preference <= -100) {
$potconf = $potconf ?? new PaperInfoPotentialConflictHTML;
$potconf->messages[] = ["<em>reviewer preference</em> " . unparse_preference($pref)];
$potconf->messages[] = ["<em>reviewer preference</em> " . $pf->unparse()];
}
$this->nonempty = !$row->has_author($this->contact) || $potconf;
if (!$potconf || empty($potconf->messages)) {
Expand Down
32 changes: 16 additions & 16 deletions src/papercolumns/pc_preference.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function prepare(PaperList $pl, $visible) {
}
$this->prefix = "";
if ($this->as_row) {
$this->prefix = $this->viewer->reviewer_html_for($this->user);
$this->prefix = $this->viewer->reviewer_html_for($this->user) . " ";
}
return true;
}
Expand All @@ -71,7 +71,7 @@ private function sortable_preference(PaperInfo $row) {
: !$this->viewer->can_view_preference($row))) {
return [-PHP_INT_MAX, null];
} else {
$pv = $row->preference($this->user);
$pv = $row->preference($this->user)->as_list();
if ($pv[0] === 0 && $pv[1] === null) {
if (!$this->viewer->can_edit_preference_for($this->user, $row)) {
$pv[0] = -PHP_INT_MAX;
Expand Down Expand Up @@ -129,29 +129,29 @@ function content_empty(PaperList $pl, PaperInfo $row) {
return $this->not_me && !$this->viewer->allow_view_preference($row);
}
function content(PaperList $pl, PaperInfo $row) {
$pv = $row->preference($this->user);
$pv_exists = $pv[0] !== 0 || $pv[1] !== null;
$pf = $row->preference($this->user);
$pf_exists = $pf->exists();
$editable = $this->editable && $this->viewer->can_edit_preference_for($this->user, $row, true);
$has_conflict = $row->has_conflict($this->user);

// compute HTML
$t = "";
if ($this->as_row) {
if ($pv_exists) {
$t = $this->prefix . unparse_preference_span($pv, true);
if ($pf_exists) {
$t = $this->prefix . " " . $pf->unparse_span();
}
} else if ($editable) {
$iname = "revpref" . $row->paperId;
if ($this->not_me) {
$iname .= "u" . $this->user->contactId;
}
$pvt = $pv_exists ? unparse_preference($pv) : "";
$t = "<input name=\"{$iname}\" class=\"uikd uich revpref\" value=\"{$pvt}\" type=\"text\" size=\"4\" tabindex=\"2\" placeholder=\"0\">";
$pft = $pf_exists ? $pf->unparse() : "";
$t = "<input name=\"{$iname}\" class=\"uikd uich revpref\" value=\"{$pft}\" type=\"text\" size=\"4\" tabindex=\"2\" placeholder=\"0\">";
if ($has_conflict && $this->show_conflict) {
$t .= " " . review_type_icon(-1);
}
} else if (!$has_conflict || $pv_exists) {
$t = str_replace("-", "" /* U+2212 */, unparse_preference($pv));
} else if (!$has_conflict || $pf_exists) {
$t = str_replace("-", "" /* U+2212 */, $pf->unparse());
} else if ($this->show_conflict) {
$t = review_type_icon(-1);
}
Expand All @@ -166,21 +166,21 @@ function content(PaperList $pl, PaperInfo $row) {
if (!$this->override_statistics) {
$this->override_statistics = clone $this->statistics;
}
if ($pv_exists) {
$this->override_statistics->add($pv[0]);
if ($pf_exists) {
$this->override_statistics->add($pf->preference);
}
} else if ($pv_exists) {
$this->statistics->add($pv[0]);
} else if ($pf_exists) {
$this->statistics->add($pf->preference);
if ($this->override_statistics) {
$this->override_statistics->add($pv[0]);
$this->override_statistics->add($pf->preference);
}
}

return $t;
}
function text(PaperList $pl, PaperInfo $row) {
if (!$this->not_me || $this->viewer->can_view_preference($row)) {
return unparse_preference($row->preference($this->user));
return $row->preference($this->user)->unparse();
} else {
return "";
}
Expand Down
11 changes: 5 additions & 6 deletions src/papercolumns/pc_preferencelist.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ function content(PaperList $pl, PaperInfo $row) {
$ts = [];
if ($this->topics || $row->preferences()) {
foreach ($row->conf->pc_members() as $pcid => $pc) {
if (($pref = $row->preference($pcid, $this->topics))) {
if ($pref[0] !== 0 || $pref[1] !== null) {
$ts[] = $pcid . "P" . $pref[0] . ($pref[1] !== null ? unparse_expertise($pref[1]) : "");
} else if ($this->topics && $pref[2]) {
$ts[] = $pcid . "T" . $pref[2];
}
$pf = $row->preference($pc);
if ($pf->exists()) {
$ts[] = "{$pcid}P{$pf->preference}" . unparse_expertise($pf->expertise);
} else if ($this->topics && ($tv = $row->topic_interest_score($pc))) {
$ts[] = "{$pcid}T{$tv}";
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/papercolumns/pc_reviewerlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ function content(PaperList $pl, PaperInfo $prow) {
$ranal = $pl->make_review_analysis($xrow, $prow);
$t = $pl->user->reviewer_html_for($xrow) . " " . $ranal->icon_html(false);
if ($pref) {
$t .= unparse_preference_span($prow->preference($xrow->contactId, $this->topics), true);
$pf = $prow->preference($xrow->contactId);
$tv = $this->topics ? $prow->topic_interest_score($xrow->contactId) : null;
$t .= " " . $pf->unparse_span($tv);
}
$k = $this->hlterm && $this->hlterm->test($prow, $xrow) ? " highlightmark taghh" : "";
$x[] = "<span class=\"nb{$k}\">{$t}";
Expand All @@ -90,10 +92,12 @@ function text(PaperList $pl, PaperInfo $prow) {
&& (!$this->rsm || $this->rsm->test_review($pl->user, $prow, $xrow))) {
$t = $pl->user->reviewer_text_for($xrow);
if ($pref) {
$pf = $prow->preference($xrow->contactId, $this->topics);
$t .= " P" . unparse_number_pm_text($pf[0]) . unparse_expertise($pf[1]);
if ($this->topics && $pf[2] && !$pf[0]) {
$t .= " T" . unparse_number_pm_text($pf[2]);
$pf = $prow->preference($xrow->contactId);
$t .= " P" . unparse_number_pm_text($pf->preference) . unparse_expertise($pf->expertise);
if ($this->topics
&& $pf->preference === 0
&& ($tv = $prow->topic_interest_score($xrow->contactId))) {
$t .= " T" . unparse_number_pm_text($tv);
}
}
$x[] = $t;
Expand Down
Loading

0 comments on commit b92670c

Please sign in to comment.