perlsky is a Perl 5 implementation of an AT Protocol Personal Data Server.
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

Derive blob bind positions by name

alice 484cf0f1 217dbb66

+49 -13
+49 -13
lib/ATProto/PDS/Store/SQLite.pm
··· 142 142 $args{invites_disabled} ? 1 : 0, 143 143 $args{invite_note}, 144 144 ], 145 - { 7 => 1, 14 => 1, 15 => 1 }, 145 + _blob_bind_positions_for_names( 146 + [qw( 147 + id account_id did handle email password_hash password_salt 148 + created_at updated_at deactivated_at deleted_at email_confirmed_at 149 + did_doc_json private_key public_key public_key_multibase signing_key_did 150 + repo_commit_cid repo_root_cid repo_rev invites_disabled invite_note 151 + )], 152 + qw(password_salt private_key public_key), 153 + ), 146 154 ); 147 155 148 156 return $self->get_account_by_did($did); ··· 166 174 167 175 push @sets, 'updated_at = ?'; 168 176 push @bind, ($changes{updated_at} // time), $did; 169 - my %blob_positions = map { 170 - my $column = $sets[$_]; 171 - (($column =~ /^(?:password_salt|private_key|public_key) = \?$/) ? ($_ + 1 => 1) : ()) 172 - } 0 .. $#sets; 173 177 _execute_sql( 174 178 $self->dbh, 175 179 'UPDATE accounts SET ' . join(', ', @sets) . ' WHERE did = ?', 176 180 \@bind, 177 - \%blob_positions, 181 + _blob_bind_positions_for_names( 182 + [ map { /^(.+?) = \?$/ ? $1 : () } @sets ], 183 + qw(password_salt private_key public_key), 184 + ), 178 185 ); 179 186 return $self->get_account_by_did($did); 180 187 } ··· 623 630 $args{created_at} // $now, 624 631 $now, 625 632 ], 626 - { 6 => 1 }, 633 + _blob_bind_positions_for_names([qw( 634 + did collection rkey cid value_json record_bytes created_at updated_at 635 + )], qw(record_bytes)), 627 636 ); 628 637 629 638 return $self->get_record($did, $collection, $rkey); ··· 650 659 $record->{created_at} // time, 651 660 $record->{updated_at} // time, 652 661 ], 653 - { 6 => 1 }, 662 + _blob_bind_positions_for_names([qw( 663 + did collection rkey cid value_json record_bytes created_at updated_at 664 + )], qw(record_bytes)), 654 665 ); 655 666 } 656 667 return 1; ··· 759 770 $args{bytes}, 760 771 $now, 761 772 ], 762 - { 3 => 1 }, 773 + _blob_bind_positions_for_names([qw(cid codec bytes created_at)], qw(bytes)), 763 774 ); 764 775 return $self->get_block($cid); 765 776 } ··· 803 814 $args{car_bytes}, 804 815 $now, 805 816 ], 806 - { 6 => 1, 7 => 1 }, 817 + _blob_bind_positions_for_names( 818 + [qw(did rev cid root_cid prev_cid commit_bytes car_bytes created_at)], 819 + qw(commit_bytes car_bytes), 820 + ), 807 821 ); 808 822 $self->set_repo_head( 809 823 did => $did, ··· 935 949 $args{car_bytes}, 936 950 $now, 937 951 ], 938 - { 6 => 1 }, 952 + _blob_bind_positions_for_names( 953 + [qw(did type rev commit_cid payload_json car_bytes created_at)], 954 + qw(car_bytes), 955 + ), 939 956 ); 940 957 return $self->dbh->sqlite_last_insert_rowid; 941 958 }); ··· 1336 1353 $now, 1337 1354 $args{updated_at} // $now, 1338 1355 ], 1339 - { 7 => 1 }, 1356 + _blob_bind_positions_for_names( 1357 + [qw(subject_key src uri cid val exp sig created_at updated_at)], 1358 + qw(sig), 1359 + ), 1340 1360 ); 1341 1361 return $self->get_label( 1342 1362 subject_key => $subject_key, ··· 1442 1462 $now, 1443 1463 $args{claimed_at}, 1444 1464 ], 1445 - { 2 => 1, 3 => 1 }, 1465 + _blob_bind_positions_for_names( 1466 + [qw( 1467 + did private_key public_key public_key_multibase signing_key_did 1468 + created_at claimed_at 1469 + )], 1470 + qw(private_key public_key), 1471 + ), 1446 1472 ); 1447 1473 return $self->get_reserved_signing_key($did); 1448 1474 } ··· 2122 2148 } 2123 2149 $sth->execute; 2124 2150 return $sth; 2151 + } 2152 + 2153 + sub _blob_bind_positions_for_names ($bind_names, @blob_names) { 2154 + my %is_blob = map { $_ => 1 } @blob_names; 2155 + my %positions; 2156 + for my $index (0 .. $#$bind_names) { 2157 + next unless $is_blob{$bind_names->[$index]}; 2158 + $positions{$index + 1} = 1; 2159 + } 2160 + return \%positions; 2125 2161 } 2126 2162 2127 2163 sub _row_from_blob_columns ($row, @columns) {