|
@@ -139,39 +139,54 @@ func (u *DDNSUpdater) run() {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- allOK := true
|
|
|
|
|
|
|
+ type zoneKey struct {
|
|
|
|
|
+ apiKey string
|
|
|
|
|
+ zoneID string
|
|
|
|
|
+ }
|
|
|
|
|
+ byZone := make(map[zoneKey][]queries.ListNonStaticRecordsRow)
|
|
|
for _, rec := range records {
|
|
for _, rec := range records {
|
|
|
- err := cf.UpdateDNSRecord(ctx, rec.ZoneApiKey, rec.CfZoneID, rec.CfRecordID, cf.DNSRecord{
|
|
|
|
|
- Type: rec.Type,
|
|
|
|
|
- Name: rec.Name,
|
|
|
|
|
- Content: ip,
|
|
|
|
|
- Proxied: rec.Proxied == 1,
|
|
|
|
|
- TTL: 1, // auto
|
|
|
|
|
- })
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- slog.Error("failed to update DNS record",
|
|
|
|
|
- "record", rec.Name,
|
|
|
|
|
- "zone", rec.CfZoneID,
|
|
|
|
|
- "error", err,
|
|
|
|
|
- )
|
|
|
|
|
- allOK = false
|
|
|
|
|
- continue
|
|
|
|
|
|
|
+ k := zoneKey{apiKey: rec.ZoneApiKey, zoneID: rec.CfZoneID}
|
|
|
|
|
+ byZone[k] = append(byZone[k], rec)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ allOK := true
|
|
|
|
|
+ for k, zoneRecs := range byZone {
|
|
|
|
|
+ cfRecords := make([]cf.DNSRecord, len(zoneRecs))
|
|
|
|
|
+ for i, rec := range zoneRecs {
|
|
|
|
|
+ cfRecords[i] = cf.DNSRecord{
|
|
|
|
|
+ ID: rec.CfRecordID,
|
|
|
|
|
+ Type: rec.Type,
|
|
|
|
|
+ Name: rec.Name,
|
|
|
|
|
+ Content: ip,
|
|
|
|
|
+ Proxied: rec.Proxied == 1,
|
|
|
|
|
+ TTL: 1, // auto
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- err = u.q.UpdateRecordContent(ctx, queries.UpdateRecordContentParams{
|
|
|
|
|
- ID: rec.ID,
|
|
|
|
|
- Content: ip,
|
|
|
|
|
- })
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- slog.Error("failed to update local record content",
|
|
|
|
|
- "record", rec.Name,
|
|
|
|
|
|
|
+ if err := cf.BatchUpdateDNSRecords(ctx, k.apiKey, k.zoneID, cfRecords); err != nil {
|
|
|
|
|
+ slog.Error("failed to batch update DNS records",
|
|
|
|
|
+ "zone", k.zoneID,
|
|
|
|
|
+ "count", len(zoneRecs),
|
|
|
"error", err,
|
|
"error", err,
|
|
|
)
|
|
)
|
|
|
allOK = false
|
|
allOK = false
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- slog.Info("updated DNS record", "record", rec.Name, "ip", ip)
|
|
|
|
|
|
|
+ for _, rec := range zoneRecs {
|
|
|
|
|
+ if err := u.q.UpdateRecordContent(ctx, queries.UpdateRecordContentParams{
|
|
|
|
|
+ ID: rec.ID,
|
|
|
|
|
+ Content: ip,
|
|
|
|
|
+ }); err != nil {
|
|
|
|
|
+ slog.Error("failed to update local record content",
|
|
|
|
|
+ "record", rec.Name,
|
|
|
|
|
+ "error", err,
|
|
|
|
|
+ )
|
|
|
|
|
+ allOK = false
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ slog.Info("updated DNS record", "record", rec.Name, "ip", ip)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if allOK {
|
|
if allOK {
|