···10441044 return nil, err
10451045 }
1046104610471047- if peering.Blocked {
10481048- return nil, fmt.Errorf("refusing to create user with blocked PDS")
10491049- }
10501050-10511051- if peering.RepoCount >= peering.RepoLimit {
10521052- return nil, fmt.Errorf("refusing to create user on PDS at max repo limit")
10531053- }
10541054-10551055- // Increment the repo count for the PDS
10561056- res := s.db.Model(&models.PDS{}).Where("id = ? AND repo_count < repo_limit", peering.ID).Update("repo_count", gorm.Expr("repo_count + 1"))
10571057- if res.Error != nil {
10581058- return nil, fmt.Errorf("failed to increment repo count for pds: %w", res.Error)
10591059- }
10601060-10611061- if res.RowsAffected == 0 {
10621062- return nil, fmt.Errorf("refusing to create user on PDS at max repo limit")
10631063- }
10641064-10651065- successfullyCreated := false
10661066-10671067- // Release the count if we fail to create the user
10681068- defer func() {
10691069- if !successfullyCreated {
10701070- if err := s.db.Model(&models.PDS{}).Where("id = ?", peering.ID).Update("repo_count", gorm.Expr("repo_count - 1")).Error; err != nil {
10711071- log.Errorf("failed to decrement repo count for pds: %s", err)
10721072- }
10731073- }
10741074- }()
10751075-10761047 ban, err := s.domainIsBanned(ctx, durl.Host)
10771048 if err != nil {
10781049 return nil, fmt.Errorf("failed to check pds ban status: %w", err)
···11121083 if peering.ID == 0 {
11131084 panic("somehow failed to create a pds entry?")
11141085 }
10861086+10871087+ if peering.Blocked {
10881088+ return nil, fmt.Errorf("refusing to create user with blocked PDS")
10891089+ }
10901090+10911091+ if peering.RepoCount >= peering.RepoLimit {
10921092+ return nil, fmt.Errorf("refusing to create user on PDS at max repo limit for pds %q", peering.Host)
10931093+ }
10941094+10951095+ // Increment the repo count for the PDS
10961096+ res := s.db.Model(&models.PDS{}).Where("id = ? AND repo_count < repo_limit", peering.ID).Update("repo_count", gorm.Expr("repo_count + 1"))
10971097+ if res.Error != nil {
10981098+ return nil, fmt.Errorf("failed to increment repo count for pds %q: %w", peering.Host, res.Error)
10991099+ }
11001100+11011101+ if res.RowsAffected == 0 {
11021102+ return nil, fmt.Errorf("refusing to create user on PDS at max repo limit for pds %q", peering.Host)
11031103+ }
11041104+11051105+ successfullyCreated := false
11061106+11071107+ // Release the count if we fail to create the user
11081108+ defer func() {
11091109+ if !successfullyCreated {
11101110+ if err := s.db.Model(&models.PDS{}).Where("id = ?", peering.ID).Update("repo_count", gorm.Expr("repo_count - 1")).Error; err != nil {
11111111+ log.Errorf("failed to decrement repo count for pds: %s", err)
11121112+ }
11131113+ }
11141114+ }()
1115111511161116 if len(doc.AlsoKnownAs) == 0 {
11171117 return nil, fmt.Errorf("user has no 'known as' field in their DID document")