Skip to content

Commit af370c5

Browse files
committed
Auto merge of #593 - Mark-Simulacrum:logging, r=Mark-Simulacrum
Avoid expensive queries at startup Previously, the initial startup would synchronize() the configuration, and query the experiment assigned to each agent. Querying the assigned experiment could take upwards of ~80 seconds per agent, leading to a long time before it was able to respond to queries. I plan to see if we can restructure that query separately, but this seems like a good start.
2 parents 45c640b + 38b0b7b commit af370c5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/server/agents.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,19 @@ impl Agents {
8686
fn synchronize(&self, tokens: &Tokens) -> Fallible<()> {
8787
self.db.transaction(|trans| {
8888
let mut real = tokens.agents.values().collect::<HashSet<&String>>();
89-
for agent in &self.all()? {
90-
if !real.remove(&agent.name) {
91-
trans.execute("DELETE FROM agents WHERE name = ?1;", &[&agent.name])?;
89+
let current: Vec<String> = self
90+
.db
91+
.query("select name from agents;", [], |r| r.get(0))?;
92+
93+
// If the token is no longer configured, then drop this agent from
94+
// our list.
95+
for current_name in current {
96+
if !real.remove(&current_name) {
97+
trans.execute("DELETE FROM agents WHERE name = ?1;", &[&current_name])?;
9298
}
9399
}
94100

101+
// And any *new* agents need to be inserted.
95102
for missing in &real {
96103
trans.execute(
97104
"INSERT INTO agents (name) VALUES (?1);",

0 commit comments

Comments
 (0)