Skip to content

Commit 50ff487

Browse files
authored
Minor fixes (#776)
* `IsXxx` helpers were returning an `Oid` instead of a `bool` * simplify secrets invalidation
1 parent 52432b9 commit 50ff487

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

include/pgduckdb/pgduckdb_duckdb.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ class DuckDBManager {
2424
return manager_instance;
2525
}
2626

27-
static inline DuckDBManager *
28-
FindIfInitialized() {
29-
return manager_instance.database ? &manager_instance : nullptr;
27+
static void
28+
InvalidateDuckDBSecretsIfInitialized() {
29+
// Only invalidate the secrets if the database is initialized.
30+
if (IsInitialized()) {
31+
manager_instance.InvalidateDuckDBSecrets();
32+
}
3033
}
3134

3235
static duckdb::unique_ptr<duckdb::Connection> CreateConnection();

include/pgduckdb/pgduckdb_metadata_cache.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ Oid DuckdbUnionOid();
1515
Oid DuckdbMapOid();
1616
Oid DuckdbJsonOid();
1717
Oid DuckdbTableAmOid();
18-
Oid IsDuckdbTable(Form_pg_class relation);
19-
Oid IsDuckdbTable(Relation relation);
20-
Oid IsMotherDuckTable(Form_pg_class relation);
21-
Oid IsMotherDuckTable(Relation relation);
22-
Oid IsDuckdbExecutionAllowed();
18+
bool IsDuckdbTable(Form_pg_class relation);
19+
bool IsDuckdbTable(Relation relation);
20+
bool IsMotherDuckTable(Form_pg_class relation);
21+
bool IsMotherDuckTable(Relation relation);
22+
bool IsDuckdbExecutionAllowed();
2323
void RequireDuckdbExecution();
2424
} // namespace pgduckdb

src/pgduckdb_metadata_cache.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -355,31 +355,31 @@ DuckdbTableAmOid() {
355355
return cache.table_am_oid;
356356
}
357357

358-
Oid
358+
bool
359359
IsDuckdbTable(Form_pg_class relation) {
360360
Assert(cache.valid);
361361
return relation->relam == pgduckdb::DuckdbTableAmOid();
362362
}
363363

364-
Oid
364+
bool
365365
IsDuckdbTable(Relation relation) {
366366
Assert(cache.valid);
367367
return IsDuckdbTable(relation->rd_rel);
368368
}
369369

370-
Oid
370+
bool
371371
IsMotherDuckTable(Form_pg_class relation) {
372372
Assert(cache.valid);
373373
return IsDuckdbTable(relation) && relation->relpersistence == RELPERSISTENCE_PERMANENT;
374374
}
375375

376-
Oid
376+
bool
377377
IsMotherDuckTable(Relation relation) {
378378
Assert(cache.valid);
379379
return IsMotherDuckTable(relation->rd_rel);
380380
}
381381

382-
Oid
382+
bool
383383
IsDuckdbExecutionAllowed() {
384384
Assert(cache.valid);
385385
Assert(cache.postgres_role_oid != InvalidOid);

src/pgduckdb_userdata_cache.cpp

+1-9
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,10 @@ struct {
4242

4343
bool callback_is_configured = false;
4444

45-
void
46-
InvalidateDuckDBSecrets() {
47-
auto manager = pgduckdb::DuckDBManager::FindIfInitialized();
48-
if (manager) {
49-
manager->InvalidateDuckDBSecrets();
50-
}
51-
}
52-
5345
void
5446
InvalidateCache(Datum, int, uint32) {
5547
InvalidateUserDataCache();
56-
InvokeCPPFunc(InvalidateDuckDBSecrets);
48+
InvokeCPPFunc(pgduckdb::DuckDBManager::InvalidateDuckDBSecretsIfInitialized);
5749
}
5850

5951
} // namespace

0 commit comments

Comments
 (0)