Skip to content

Commit

Permalink
release user mapping tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
rebasedming authored and kysshsy committed Jan 12, 2025
1 parent 5c2f281 commit 0ff117f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions supabase-wrappers/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,29 @@ pub unsafe fn options_to_hashmap(

pub unsafe fn user_mapping_options(fserver: *mut pg_sys::ForeignServer) -> HashMap<String, String> {
let user_id = pg_sys::GetUserId();
let user_mapping_exists = !pg_sys::SearchSysCache2(

let user_mapping_tup = pg_sys::SearchSysCache2(
pg_sys::SysCacheIdentifier_USERMAPPINGUSERSERVER as i32,
pg_sys::Datum::from(user_id),
pg_sys::Datum::from((*fserver).serverid),
)
.is_null();
let public_mapping_exists = !pg_sys::SearchSysCache2(
);

let public_mapping_tup = pg_sys::SearchSysCache2(
pg_sys::SysCacheIdentifier_USERMAPPINGUSERSERVER as i32,
pg_sys::Datum::from(pg_sys::InvalidOid),
pg_sys::Datum::from((*fserver).serverid),
)
.is_null();
);

match user_mapping_exists || public_mapping_exists {
let options = match !user_mapping_tup.is_null() || !public_mapping_tup.is_null() {
true => {
let user_mapping = pg_sys::GetUserMapping(user_id, (*fserver).serverid);
options_to_hashmap((*user_mapping).options).report_unwrap()
}
false => HashMap::new(),
}
};

pg_sys::ReleaseSysCache(user_mapping_tup);
pg_sys::ReleaseSysCache(public_mapping_tup);

options
}

0 comments on commit 0ff117f

Please sign in to comment.