···8989 my $rkey = $write->{rkey} // next_tid();
9090 my $path = $collection . '/' . $rkey;
9191 my $previous = $previous_records{$path};
9292+ my $current_cid = $previous ? $previous->{cid} : undef;
9393+9494+ if ($write->{swap_record_present}) {
9595+ my $swap_record = $write->{swap_record};
9696+ die {
9797+ status => 400,
9898+ error => 'InvalidSwap',
9999+ message => 'swapRecord did not match the current record',
100100+ } if $action eq 'create' && defined $swap_record;
101101+ die {
102102+ status => 400,
103103+ error => 'InvalidSwap',
104104+ message => 'swapRecord did not match the current record',
105105+ } if ($action eq 'update' || $action eq 'delete') && !defined $swap_record;
106106+ my $mismatch = (defined($current_cid) || defined($swap_record))
107107+ && (!defined($current_cid) || !defined($swap_record) || $current_cid ne $swap_record);
108108+ die {
109109+ status => 400,
110110+ error => 'InvalidSwap',
111111+ message => 'swapRecord did not match the current record',
112112+ } if $mismatch;
113113+ }
9211493115 if ($action eq 'delete') {
94116 xrpc_error(400, 'InvalidRequest', 'Could not locate record: at://' . $did . '/' . $path)
+12-8
lib/ATProto/PDS/Store/SQLite.pm
···895895 return 1;
896896}
897897898898-sub get_record ($self, $did, $collection, $rkey) {
898898+sub get_record ($self, $did, $collection, $rkey, $cid = undef) {
899899+ my @bind = ($did, $collection, $rkey);
900900+ my $sql = q{
901901+ SELECT * FROM records
902902+ WHERE did = ? AND collection = ? AND rkey = ?
903903+ };
904904+ if (defined $cid && length $cid) {
905905+ $sql .= q{ AND cid = ?};
906906+ push @bind, $cid;
907907+ }
899908 my $row = $self->dbh->selectrow_hashref(
900900- q{
901901- SELECT * FROM records
902902- WHERE did = ? AND collection = ? AND rkey = ?
903903- },
909909+ $sql,
904910 undef,
905905- $did,
906906- $collection,
907907- $rkey,
911911+ @bind,
908912 );
909913 return _row_to_record($row);
910914}