]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth-domaincache: use info-zone-query for inserted zone id
authorChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Mon, 10 May 2021 08:28:35 +0000 (10:28 +0200)
committerChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Sat, 15 May 2021 22:45:45 +0000 (00:45 +0200)
Also apply "RETURNING id" optimization for postgresql.

modules/gpgsqlbackend/gpgsqlbackend.cc
pdns/backends/gsql/gsqlbackend.cc

index 500bab200aabf83354b1969291efc049848098fa..2d1f9924656ade27f2faea26a66c375f919fa01d 100644 (file)
@@ -115,7 +115,7 @@ public:
     declare(suffix, "supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver=$1 and account=$2");
     declare(suffix, "supermaster-add", "", "insert into supermasters (ip, nameserver, account) values ($1,$2,$3)");
 
-    declare(suffix, "insert-zone-query", "", "insert into domains (type,name,master,account,last_check, notified_serial) values($1,$2,$3,$4,null,null)");
+    declare(suffix, "insert-zone-query", "", "insert into domains (type,name,master,account,last_check, notified_serial) values($1,$2,$3,$4,null,null) returning id");
 
     declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,ordername,auth) values ($1,$2,$3,$4,$5,$6,$7,$8,$9)");
     declare(suffix, "insert-empty-non-terminal-order-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,ordername,auth,ttl,prio,content) values (null,$1,false,$2,$3,$4,null,null,null)");
index 5ad65bd863e9d717773d18c745b9f5ff7b45022a..f30d71bf4f1a4563d07306d6fc53ebf5d23c07a2 100644 (file)
@@ -1305,20 +1305,33 @@ bool GSQLBackend::createDomain(const DNSName &domain, const DomainInfo::DomainKi
       bind("domain", domain)->
       bind("masters", boost::join(masters_s, ", "))->
       bind("account", account)->
-      execute()->
-      reset();
+      execute();
 
     if (zoneId != nullptr) {
-      // XXX: needs its own stmt as godbc has a table name in it
-      d_GetLastInsertedKeyIdQuery_stmt->execute();
-      if (!d_GetLastInsertedKeyIdQuery_stmt->hasNextRow()) {
+      if (d_InsertZoneQuery_stmt->hasNextRow()) {
+        SSqlStatement::row_t row;
+        d_InsertZoneQuery_stmt->nextRow(row);
+        *zoneId = std::stoi(row[0]);
+        d_InsertZoneQuery_stmt->reset();
+        return true;
+      } else {
+        d_InsertZoneQuery_stmt->reset();
+      }
+
+      d_InfoOfDomainsZoneQuery_stmt->
+        bind("domain", domain)->
+        execute();
+      if (!d_InfoOfDomainsZoneQuery_stmt->hasNextRow()) {
+        d_InfoOfDomainsZoneQuery_stmt->reset();
         return false;
       }
       SSqlStatement::row_t row;
-      d_GetLastInsertedKeyIdQuery_stmt->nextRow(row);
-      ASSERT_ROW_COLUMNS("get-last-inserted-key-id-query", row, 1);
+      d_InfoOfDomainsZoneQuery_stmt->nextRow(row);
+      ASSERT_ROW_COLUMNS("info-zone-query", row, 7);
       *zoneId = std::stoi(row[0]);
-      d_GetLastInsertedKeyIdQuery_stmt->reset();
+      d_InfoOfDomainsZoneQuery_stmt->reset();
+    } else {
+      d_InsertZoneQuery_stmt->reset();
     }
     return true;
   }