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.

Share sync CAR generation

alice 13cae222 b71c204b

+22 -18
+1 -9
lib/ATProto/PDS/API/Server.pm
··· 318 318 ); 319 319 my $commit = $c->store->get_latest_commit($account->{did}); 320 320 if ($commit) { 321 - my $sync_car = $commit->{commit_bytes} 322 - ? ATProto::PDS::Repo::CAR::write_car( 323 - ATProto::PDS::Repo::CID->from_string($commit->{cid}), 324 - [{ 325 - cid => ATProto::PDS::Repo::CID->from_string($commit->{cid}), 326 - bytes => $commit->{commit_bytes}, 327 - }], 328 - ) 329 - : undef; 321 + my $sync_car = $c->repo_manager->sync_car_for_commit($commit); 330 322 $c->append_event( 331 323 did => $account->{did}, 332 324 type => 'sync',
+21 -9
lib/ATProto/PDS/Repo/Manager.pm
··· 34 34 return generate_keypair(); 35 35 } 36 36 37 + sub sync_car_for_commit ($self, $commit) { 38 + return undef unless $commit && defined($commit->{commit_bytes}); 39 + return write_car( 40 + ATProto::PDS::Repo::CID->from_string($commit->{cid}), 41 + [{ 42 + cid => ATProto::PDS::Repo::CID->from_string($commit->{cid}), 43 + bytes => $commit->{commit_bytes}, 44 + }], 45 + ); 46 + } 47 + 37 48 sub initialize_repo ($self, $account) { 38 49 return $self->apply_writes($account, [], emit_event => 0); 39 50 } ··· 127 138 }; 128 139 } 129 140 130 - my $artifacts = _build_commit_artifacts( 141 + my $artifacts = $self->_build_commit_artifacts( 131 142 $account, 132 143 $records, 133 144 rev => next_tid($latest ? $latest->{rev} : undef), ··· 248 259 my %records_by_path = map { 249 260 $_->{collection} . '/' . $_->{rkey} => $_ 250 261 } @$records; 251 - my $artifacts = _build_commit_artifacts( 262 + my $artifacts = $self->_build_commit_artifacts( 252 263 $account, 253 264 \%records_by_path, 254 265 rev => next_tid($latest ? $latest->{rev} : undef), ··· 323 334 imported => undef, 324 335 } unless $needs_repair; 325 336 326 - my $snapshot_car = _build_snapshot_car( 337 + my $snapshot_car = $self->_build_snapshot_car( 327 338 $account, 328 339 $repaired->{records}, 329 340 $latest ? (repair_tid($latest->{rev}) // $latest->{rev}) : undef, ··· 450 461 return $value; 451 462 } 452 463 453 - sub _build_snapshot_car ($account, $records, $rev = undef) { 464 + sub _build_snapshot_car ($self, $account, $records, $rev = undef) { 454 465 my %records_by_path = map { 455 466 $_->{collection} . '/' . $_->{rkey} => $_ 456 467 } @$records; 457 - my $artifacts = _build_commit_artifacts( 468 + my $artifacts = $self->_build_commit_artifacts( 458 469 $account, 459 470 \%records_by_path, 460 471 rev => $rev // next_tid(), ··· 464 475 return $artifacts->{snapshot_car_bytes}; 465 476 } 466 477 467 - sub _build_commit_artifacts ($account, $records_by_path, %opts) { 478 + sub _build_commit_artifacts ($self, $account, $records_by_path, %opts) { 468 479 my %mst_input = map { 469 480 $_ => ATProto::PDS::Repo::CID->from_string($records_by_path->{$_}{cid}) 470 481 } sort keys %$records_by_path; ··· 520 531 ); 521 532 $artifacts{firehose_car_bytes} = write_car($commit_cid, \@firehose_blocks); 522 533 } 523 - $artifacts{sync_car_bytes} = write_car($commit_cid, [ 524 - { cid => $commit_cid, bytes => $commit_bytes }, 525 - ]) if $cars{sync}; 534 + $artifacts{sync_car_bytes} = $self->sync_car_for_commit({ 535 + cid => $commit_cid->to_string, 536 + commit_bytes => $commit_bytes, 537 + }) if $cars{sync}; 526 538 return \%artifacts; 527 539 } 528 540