Skip to content

Commit

Permalink
Deduplicate open requests to simplify bot logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 9, 2025
1 parent dddb4b8 commit 602bf45
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/Cavil/Model/Requests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ use Mojo::Base -base, -signatures;
has 'pg';

sub add ($self, $link, $pkg) {
my $req = {external_link => $link, package => $pkg};
return $self->pg->db->insert('bot_requests', $req, {returning => 'id'})->hash->{id};
my $db = $self->pg->db;
$db->query('INSERT INTO bot_requests (external_link, package) VALUES (?, ?) ON CONFLICT DO NOTHING', $link, $pkg);
return $db->query('SELECT id FROM bot_requests WHERE external_link = ? AND package = ?', $link, $pkg)->hash->{id};
}

sub all ($self) {
Expand Down
3 changes: 3 additions & 0 deletions migrations/cavil.sql
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,6 @@ ALTER TABLE snippets ADD COLUMN package int REFERENCES bot_packages(id) ON DELET

-- 25 up
ALTER TABLE bot_sources ADD COLUMN type text DEFAULT 'obs' NOT NULL;

-- 26 up
CREATE UNIQUE INDEX ON bot_requests(external_link, package);

0 comments on commit 602bf45

Please sign in to comment.