this repo has no description
0
fork

Configure Feed

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

Move PDS occupancy check until after we're sure we've got a PDS in the DB

+35 -30
+29 -29
bgs/bgs.go
··· 1044 1044 return nil, err 1045 1045 } 1046 1046 1047 - if peering.Blocked { 1048 - return nil, fmt.Errorf("refusing to create user with blocked PDS") 1049 - } 1050 - 1051 - if peering.RepoCount >= peering.RepoLimit { 1052 - return nil, fmt.Errorf("refusing to create user on PDS at max repo limit") 1053 - } 1054 - 1055 - // Increment the repo count for the PDS 1056 - res := s.db.Model(&models.PDS{}).Where("id = ? AND repo_count < repo_limit", peering.ID).Update("repo_count", gorm.Expr("repo_count + 1")) 1057 - if res.Error != nil { 1058 - return nil, fmt.Errorf("failed to increment repo count for pds: %w", res.Error) 1059 - } 1060 - 1061 - if res.RowsAffected == 0 { 1062 - return nil, fmt.Errorf("refusing to create user on PDS at max repo limit") 1063 - } 1064 - 1065 - successfullyCreated := false 1066 - 1067 - // Release the count if we fail to create the user 1068 - defer func() { 1069 - if !successfullyCreated { 1070 - if err := s.db.Model(&models.PDS{}).Where("id = ?", peering.ID).Update("repo_count", gorm.Expr("repo_count - 1")).Error; err != nil { 1071 - log.Errorf("failed to decrement repo count for pds: %s", err) 1072 - } 1073 - } 1074 - }() 1075 - 1076 1047 ban, err := s.domainIsBanned(ctx, durl.Host) 1077 1048 if err != nil { 1078 1049 return nil, fmt.Errorf("failed to check pds ban status: %w", err) ··· 1112 1083 if peering.ID == 0 { 1113 1084 panic("somehow failed to create a pds entry?") 1114 1085 } 1086 + 1087 + if peering.Blocked { 1088 + return nil, fmt.Errorf("refusing to create user with blocked PDS") 1089 + } 1090 + 1091 + if peering.RepoCount >= peering.RepoLimit { 1092 + return nil, fmt.Errorf("refusing to create user on PDS at max repo limit for pds %q", peering.Host) 1093 + } 1094 + 1095 + // Increment the repo count for the PDS 1096 + res := s.db.Model(&models.PDS{}).Where("id = ? AND repo_count < repo_limit", peering.ID).Update("repo_count", gorm.Expr("repo_count + 1")) 1097 + if res.Error != nil { 1098 + return nil, fmt.Errorf("failed to increment repo count for pds %q: %w", peering.Host, res.Error) 1099 + } 1100 + 1101 + if res.RowsAffected == 0 { 1102 + return nil, fmt.Errorf("refusing to create user on PDS at max repo limit for pds %q", peering.Host) 1103 + } 1104 + 1105 + successfullyCreated := false 1106 + 1107 + // Release the count if we fail to create the user 1108 + defer func() { 1109 + if !successfullyCreated { 1110 + if err := s.db.Model(&models.PDS{}).Where("id = ?", peering.ID).Update("repo_count", gorm.Expr("repo_count - 1")).Error; err != nil { 1111 + log.Errorf("failed to decrement repo count for pds: %s", err) 1112 + } 1113 + } 1114 + }() 1115 1115 1116 1116 if len(doc.AlsoKnownAs) == 0 { 1117 1117 return nil, fmt.Errorf("user has no 'known as' field in their DID document")
+6 -1
testing/utils.go
··· 181 181 t.Fatal(err) 182 182 } 183 183 184 + u, err := url.Parse(tp.HTTPHost()) 185 + if err != nil { 186 + t.Fatal(err) 187 + } 188 + 184 189 limReqBody := bgs.RateLimitChangeRequest{ 185 - Host: tp.RawHost(), 190 + Host: u.Host, 186 191 PerSecond: 5_000, 187 192 PerHour: 100_000, 188 193 PerDay: 1_000_000,