@@ -600,6 +600,10 @@ func (db *Anonymiser) anonymisePerformers(ctx context.Context) error {
600
600
return err
601
601
}
602
602
603
+ if err := db .anonymiseCustomFields (ctx , goqu .T (performersCustomFieldsTable .GetTable ()), "performer_id" ); err != nil {
604
+ return err
605
+ }
606
+
603
607
return nil
604
608
}
605
609
@@ -1050,3 +1054,73 @@ func (db *Anonymiser) obfuscateString(in string, dict string) string {
1050
1054
1051
1055
return out .String ()
1052
1056
}
1057
+
1058
+ func (db * Anonymiser ) anonymiseCustomFields (ctx context.Context , table exp.IdentifierExpression , idColumn string ) error {
1059
+ lastID := 0
1060
+ lastField := ""
1061
+ total := 0
1062
+ const logEvery = 10000
1063
+
1064
+ for gotSome := true ; gotSome ; {
1065
+ if err := txn .WithTxn (ctx , db , func (ctx context.Context ) error {
1066
+ query := dialect .From (table ).Select (
1067
+ table .Col (idColumn ),
1068
+ table .Col ("field" ),
1069
+ table .Col ("value" ),
1070
+ ).Where (
1071
+ goqu .L ("(" + idColumn + ", field)" ).Gt (goqu .L ("(?, ?)" , lastID , lastField )),
1072
+ ).Order (
1073
+ table .Col (idColumn ).Asc (), table .Col ("field" ).Asc (),
1074
+ ).Limit (1000 )
1075
+
1076
+ gotSome = false
1077
+
1078
+ const single = false
1079
+ return queryFunc (ctx , query , single , func (rows * sqlx.Rows ) error {
1080
+ var (
1081
+ id int
1082
+ field string
1083
+ value string
1084
+ )
1085
+
1086
+ if err := rows .Scan (
1087
+ & id ,
1088
+ & field ,
1089
+ & value ,
1090
+ ); err != nil {
1091
+ return err
1092
+ }
1093
+
1094
+ set := goqu.Record {}
1095
+ set ["field" ] = db .obfuscateString (field , letters )
1096
+ set ["value" ] = db .obfuscateString (value , letters )
1097
+
1098
+ if len (set ) > 0 {
1099
+ stmt := dialect .Update (table ).Set (set ).Where (
1100
+ table .Col (idColumn ).Eq (id ),
1101
+ table .Col ("field" ).Eq (field ),
1102
+ )
1103
+
1104
+ if _ , err := exec (ctx , stmt ); err != nil {
1105
+ return fmt .Errorf ("anonymising %s: %w" , table .GetTable (), err )
1106
+ }
1107
+ }
1108
+
1109
+ lastID = id
1110
+ lastField = field
1111
+ gotSome = true
1112
+ total ++
1113
+
1114
+ if total % logEvery == 0 {
1115
+ logger .Infof ("Anonymised %d %s custom fields" , total , table .GetTable ())
1116
+ }
1117
+
1118
+ return nil
1119
+ })
1120
+ }); err != nil {
1121
+ return err
1122
+ }
1123
+ }
1124
+
1125
+ return nil
1126
+ }
0 commit comments