Skip to content

Commit

Permalink
Better fix for auto-add topics
Browse files Browse the repository at this point in the history
Still need to invalidate *all* Topics options after changing the
topic set.
  • Loading branch information
kohler committed Dec 1, 2024
1 parent 948817b commit d992cc2
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 67 deletions.
2 changes: 1 addition & 1 deletion batch/savepapers.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private function _run_main(&$jl) {

if ($this->add_topics) {
$this->conf->topic_set()->set_auto_add(true);
$this->conf->invalidate_topics();
$this->conf->options()->refresh_topics();
}
if ($this->silent) {
foreach ($this->conf->options()->form_fields() as $opt) {
Expand Down
89 changes: 40 additions & 49 deletions src/conference.php
Original file line number Diff line number Diff line change
Expand Up @@ -1290,11 +1290,6 @@ function topic_set() {
return $this->_topic_set;
}

function invalidate_topics() {
$this->_topic_set = null;
$this->_paper_opts->invalidate_intrinsic_option(PaperOption::TOPICSID);
}


/** @return Conflict */
function conflict_set() {
Expand Down Expand Up @@ -2979,51 +2974,47 @@ function update_schema_version($n) {
}
}

/** @param array<string,true> $caches */
/** @param array{all?:true,autosearch?:true,rf?:true,tags?:true,cdb?:true,pc?:true,users?:true,options?:true} $caches */
function invalidate_caches($caches) {
if (!self::$no_invalidate_caches) {
if (!$caches || isset($caches["pc"]) || isset($caches["users"])) {
$this->_pc_set = null;
$this->_pc_members_cache = $this->_pc_tags_cache = null;
$this->_user_cache = $this->_user_email_cache = null;
}
if (!$caches || isset($caches["users"]) || isset($caches["cdb"])) {
$this->_cdb_user_cache = null;
}
if (isset($caches["cdb"])) {
unset($this->opt["contactdbConfid"]);
self::$_cdb = false;
}
// NB All setting-related caches cleared here should also be cleared
// in refresh_settings().
if (!$caches || isset($caches["options"])) {
$this->_paper_opts->invalidate_options();
$this->_formatspec_cache = [];
$this->_abbrev_matcher = null;
}
if (!$caches || isset($caches["rf"])) {
$this->_review_form = null;
$this->_defined_rounds = null;
$this->_abbrev_matcher = null;
}
if (!$caches || isset($caches["tags"]) || isset($caches["tracks"])) {
$this->_tag_map = null;
}
if (!$caches || isset($caches["formulas"])) {
$this->_formula_functions = null;
}
if (!$caches || isset($caches["assigners"])) {
$this->_assignment_parsers = null;
}
if (!$caches || isset($caches["topics"])) {
$this->invalidate_topics();
}
if (!$caches || isset($caches["tracks"])) {
Contact::update_rights();
}
if (isset($caches["autosearch"])) {
$this->update_automatic_tags();
}
if (self::$no_invalidate_caches) {
return;
}
$all = empty($caches) || isset($caches["all"]);
if ($all || isset($caches["pc"]) || isset($caches["users"])) {
$this->_pc_set = null;
$this->_pc_members_cache = $this->_pc_tags_cache = null;
$this->_user_cache = $this->_user_email_cache = null;
}
if ($all || isset($caches["users"]) || isset($caches["cdb"])) {
$this->_cdb_user_cache = null;
}
if (isset($caches["cdb"])) {
unset($this->opt["contactdbConfid"]);
self::$_cdb = false;
}
// NB All setting-related caches cleared here should also be cleared
// in refresh_settings().
if ($all || isset($caches["options"])) {
$this->_paper_opts->invalidate_options();
$this->_formatspec_cache = [];
$this->_abbrev_matcher = null;
$this->_topic_set = null;
}
if ($all || isset($caches["rf"])) {
$this->_review_form = null;
$this->_defined_rounds = null;
$this->_abbrev_matcher = null;
}
if ($all || isset($caches["tags"])) {
$this->_tag_map = null;
}
if ($all) {
$this->_formula_functions = null;
$this->_assignment_parsers = null;
Contact::update_rights();
}
if (isset($caches["autosearch"])) {
$this->update_automatic_tags();
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/options/o_topics.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
class Topics_PaperOption extends CheckboxesBase_PaperOption {
function __construct(Conf $conf, $args) {
parent::__construct($conf, $args);
$topic_set = $this->conf->topic_set();
if ($topic_set->count() === 0 && !$topic_set->auto_add()) {
$this->override_exists_condition(false);
}
$this->refresh_topic_set();
}

function refresh_topic_set() {
$ts = $this->topic_set();
$empty = $ts->count() === 0 && !$ts->auto_add();
$this->override_exists_condition($empty ? false : null);
}

function topic_set() {
Expand Down
30 changes: 20 additions & 10 deletions src/paperoptionlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,17 @@ function option_by_id($id) {
$this->populate_intrinsic($id);
}
return $this->_imap[$id];
} else {
if (!array_key_exists($id, $this->_omap)) {
$opt = null;
if (($oj = ($this->option_json_map())[$id] ?? null)
&& Conf::xt_enabled($oj)
&& XtParams::static_allowed($oj, $this->conf, null)) {
$opt = PaperOption::make($this->conf, $oj);
}
$this->_omap[$id] = $opt;
}
if (!array_key_exists($id, $this->_omap)) {
$opt = null;
if (($oj = ($this->option_json_map())[$id] ?? null)
&& Conf::xt_enabled($oj)
&& XtParams::static_allowed($oj, $this->conf, null)) {
$opt = PaperOption::make($this->conf, $oj);
}
return $this->_omap[$id];
$this->_omap[$id] = $opt;
}
return $this->_omap[$id];
}

/** @param int $id
Expand Down Expand Up @@ -448,4 +447,15 @@ function find_nonpaper($name) {
reset($omap);
return count($omap) == 1 ? current($omap) : null;
}

function refresh_topics() {
foreach ($this->_imap as $opt) {
if ($opt && $opt instanceof Topics_PaperOption)
$opt->refresh_topic_set();
}
foreach ($this->_omap as $opt) {
if ($opt && $opt instanceof Topics_PaperOption)
$opt->refresh_topic_set();
}
}
}
5 changes: 2 additions & 3 deletions test/t_paperstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,7 @@ function test_save_collaborators_too_long() {

function test_save_topics() {
$this->conf->qe("insert into TopicArea (topicName) values ('Cloud computing'), ('Architecture'), ('Security'), ('Cloud networking')");
$this->conf->save_setting("has_topics", 1);
$this->conf->invalidate_topics();
$this->conf->save_refresh_setting("has_topics", 1);

$tset = $this->conf->topic_set();
xassert_eqq($tset[1], "Cloud computing");
Expand Down Expand Up @@ -807,8 +806,8 @@ function test_save_topics() {
$nprow1->invalidate_topics();
xassert_eqq($nprow1->topic_list(), []); // XXX should be unchanged

$this->conf->invalidate_topics();
$this->conf->topic_set()->set_auto_add(true);
$this->conf->options()->refresh_topics();
$ps = new PaperStatus($this->u_estrin);
$ps->save_paper_json((object) [
"id" => $this->pid2,
Expand Down

0 comments on commit d992cc2

Please sign in to comment.