From: Chris Hofstaedtler Date: Mon, 10 May 2021 08:28:35 +0000 (+0200) Subject: auth-domaincache: use info-zone-query for inserted zone id X-Git-Tag: auth-4.5.0-alpha1~7^2~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fd9b6a9b98fab25c7eab1736e19421a372f90224;p=thirdparty%2Fpdns.git auth-domaincache: use info-zone-query for inserted zone id Also apply "RETURNING id" optimization for postgresql. --- diff --git a/modules/gpgsqlbackend/gpgsqlbackend.cc b/modules/gpgsqlbackend/gpgsqlbackend.cc index 500bab200a..2d1f992465 100644 --- a/modules/gpgsqlbackend/gpgsqlbackend.cc +++ b/modules/gpgsqlbackend/gpgsqlbackend.cc @@ -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)"); diff --git a/pdns/backends/gsql/gsqlbackend.cc b/pdns/backends/gsql/gsqlbackend.cc index 5ad65bd863..f30d71bf4f 100644 --- a/pdns/backends/gsql/gsqlbackend.cc +++ b/pdns/backends/gsql/gsqlbackend.cc @@ -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; }