fix(postgres): use INT instead of BIGINT for simple counts

This commit is contained in:
trisua 2025-04-03 15:56:44 -04:00
parent 27d7c2f4b5
commit 9f4e8a4d25
13 changed files with 55 additions and 56 deletions

View file

@ -32,15 +32,15 @@ impl DataManager {
salt: get!(x->4(String)), salt: get!(x->4(String)),
settings: serde_json::from_str(&get!(x->5(String)).to_string()).unwrap(), settings: serde_json::from_str(&get!(x->5(String)).to_string()).unwrap(),
tokens: serde_json::from_str(&get!(x->6(String)).to_string()).unwrap(), tokens: serde_json::from_str(&get!(x->6(String)).to_string()).unwrap(),
permissions: FinePermission::from_bits(get!(x->7(i64)) as u32).unwrap(), permissions: FinePermission::from_bits(get!(x->7(i32)) as u32).unwrap(),
is_verified: if get!(x->8(i64)) as i8 == 1 { is_verified: if get!(x->8(i32)) as i8 == 1 {
true true
} else { } else {
false false
}, },
notification_count: get!(x->9(i64)) as usize, notification_count: get!(x->9(i32)) as usize,
follower_count: get!(x->10(i64)) as usize, follower_count: get!(x->10(i32)) as usize,
following_count: get!(x->11(i64)) as usize, following_count: get!(x->11(i32)) as usize,
last_seen: get!(x->12(i64)) as usize, last_seen: get!(x->12(i64)) as usize,
} }
} }
@ -118,11 +118,11 @@ impl DataManager {
&data.salt, &data.salt,
&serde_json::to_string(&data.settings).unwrap(), &serde_json::to_string(&data.settings).unwrap(),
&serde_json::to_string(&data.tokens).unwrap(), &serde_json::to_string(&data.tokens).unwrap(),
&(FinePermission::DEFAULT.bits() as i64), &(FinePermission::DEFAULT.bits() as i32),
&(if data.is_verified { 1 as i64 } else { 0 as i64 }), &(if data.is_verified { 1 as i32 } else { 0 as i32 }),
&(0 as i64), &(0 as i32),
&(0 as i64), &(0 as i32),
&(0 as i64), &(0 as i32),
&(data.last_seen as i64), &(data.last_seen as i64),
] ]
); );
@ -253,7 +253,7 @@ impl DataManager {
let res = execute!( let res = execute!(
&conn, &conn,
"UPDATE users SET verified = $1 WHERE id = $2", "UPDATE users SET verified = $1 WHERE id = $2",
params![&(if x { 1 } else { 0 } as i64), &(id as i64)] params![&(if x { 1 } else { 0 } as i32), &(id as i64)]
); );
if let Err(e) = res { if let Err(e) = res {
@ -367,7 +367,7 @@ impl DataManager {
let res = execute!( let res = execute!(
&conn, &conn,
"UPDATE users SET permissions = $1 WHERE id = $2", "UPDATE users SET permissions = $1 WHERE id = $2",
params![&(role.bits() as i64), &(id as i64)] params![&(role.bits() as i32), &(id as i64)]
); );
if let Err(e) = res { if let Err(e) = res {

View file

@ -35,10 +35,10 @@ impl DataManager {
write_access: serde_json::from_str(&get!(x->6(String))).unwrap(), write_access: serde_json::from_str(&get!(x->6(String))).unwrap(),
join_access: serde_json::from_str(&get!(x->7(String))).unwrap(), join_access: serde_json::from_str(&get!(x->7(String))).unwrap(),
// likes // likes
likes: get!(x->8(i64)) as isize, likes: get!(x->8(i32)) as isize,
dislikes: get!(x->9(i64)) as isize, dislikes: get!(x->9(i32)) as isize,
// counts // counts
member_count: get!(x->10(i64)) as usize, member_count: get!(x->10(i32)) as usize,
} }
} }
@ -211,9 +211,9 @@ impl DataManager {
&serde_json::to_string(&data.read_access).unwrap().as_str(), &serde_json::to_string(&data.read_access).unwrap().as_str(),
&serde_json::to_string(&data.write_access).unwrap().as_str(), &serde_json::to_string(&data.write_access).unwrap().as_str(),
&serde_json::to_string(&data.join_access).unwrap().as_str(), &serde_json::to_string(&data.join_access).unwrap().as_str(),
&(0 as i64), &(0 as i32),
&(0 as i64), &(0 as i32),
&(1 as i64) &(1 as i32)
] ]
); );

View file

@ -35,18 +35,17 @@ impl DataManager {
/// Create a new [`DataManager`] (and init database). /// Create a new [`DataManager`] (and init database).
pub async fn new(config: Config) -> Result<Self> { pub async fn new(config: Config) -> Result<Self> {
let manager = PostgresConnectionManager::new( let con_url = &format!(
PgConfig::from_str(&format!(
"postgresql://{}:{}@{}/{}?target_session_attrs=read-write", "postgresql://{}:{}@{}/{}?target_session_attrs=read-write",
config.database.user, config.database.user,
config.database.password, config.database.password,
config.database.url, config.database.url,
config.database.name config.database.name
))
.unwrap(),
NoTls,
); );
println!("attempting connection on: {con_url}");
let manager = PostgresConnectionManager::new(PgConfig::from_str(con_url).unwrap(), NoTls);
let pool = Pool::builder().max_size(15).build(manager).await.unwrap(); let pool = Pool::builder().max_size(15).build(manager).await.unwrap();
Ok(Self( Ok(Self(
config.clone(), config.clone(),

View file

@ -8,8 +8,8 @@ CREATE TABLE IF NOT EXISTS communities (
write_access TEXT NOT NULL, write_access TEXT NOT NULL,
join_access TEXT NOT NULL, join_access TEXT NOT NULL,
-- likes -- likes
likes BIGINT NOT NULL, likes INT NOT NULL,
dislikes BIGINT NOT NULL, dislikes INT NOT NULL,
-- counts -- counts
member_count BIGINT NOT NULL member_count INT NOT NULL
) )

View file

@ -3,5 +3,5 @@ CREATE TABLE IF NOT EXISTS memberships (
created BIGINT NOT NULL, created BIGINT NOT NULL,
owner BIGINT NOT NULL, owner BIGINT NOT NULL,
community BIGINT NOT NULL, community BIGINT NOT NULL,
role BIGINT NOT NULL role INT NOT NULL
) )

View file

@ -4,5 +4,5 @@ CREATE TABLE IF NOT EXISTS notifications (
title TEXT NOT NULL, title TEXT NOT NULL,
content TEXT NOT NULL, content TEXT NOT NULL,
owner BIGINT NOT NULL, owner BIGINT NOT NULL,
read BIGINT NOT NULL read INT NOT NULL
) )

View file

@ -5,10 +5,10 @@ CREATE TABLE IF NOT EXISTS posts (
owner BIGINT NOT NULL, owner BIGINT NOT NULL,
community BIGINT NOT NULL, community BIGINT NOT NULL,
context TEXT NOT NULL, context TEXT NOT NULL,
replying_to BIGINT, -- the ID of the post this is a comment on... NULL means it isn't a reply replying_to BIGINT, -- the ID of the post this is a comment on... 0 means it isn't a reply
-- likes -- likes
likes BIGINT NOT NULL, likes INT NOT NULL,
dislikes BIGINT NOT NULL, dislikes INT NOT NULL,
-- other counts -- other counts
comment_count BIGINT NOT NULL comment_count INT NOT NULL
) )

View file

@ -4,5 +4,5 @@ CREATE TABLE IF NOT EXISTS reactions (
owner BIGINT NOT NULL, owner BIGINT NOT NULL,
asset BIGINT NOT NULL, asset BIGINT NOT NULL,
asset_type TEXT NOT NULL, asset_type TEXT NOT NULL,
is_like BIGINT NOT NULL is_like INT NOT NULL
) )

View file

@ -6,10 +6,10 @@ CREATE TABLE IF NOT EXISTS users (
salt TEXT NOT NULL, salt TEXT NOT NULL,
settings TEXT NOT NULL, settings TEXT NOT NULL,
tokens TEXT NOT NULL, tokens TEXT NOT NULL,
permissions BIGINT NOT NULL, permissions INT NOT NULL,
verified BIGINT NOT NULL, verified INT NOT NULL,
notification_count BIGINT NOT NULL, notification_count INT NOT NULL,
follower_count BIGINT NOT NULL, follower_count INT NOT NULL,
following_count BIGINT NOT NULL, following_count INT NOT NULL,
last_seen BIGINT NOT NULL last_seen BIGINT NOT NULL
) )

View file

@ -28,7 +28,7 @@ impl DataManager {
created: get!(x->1(i64)) as usize, created: get!(x->1(i64)) as usize,
owner: get!(x->2(i64)) as usize, owner: get!(x->2(i64)) as usize,
community: get!(x->3(i64)) as usize, community: get!(x->3(i64)) as usize,
role: CommunityPermission::from_bits(get!(x->4(i64)) as u32).unwrap(), role: CommunityPermission::from_bits(get!(x->4(i32)) as u32).unwrap(),
} }
} }
@ -147,7 +147,7 @@ impl DataManager {
&(data.created as i64), &(data.created as i64),
&(data.owner as i64), &(data.owner as i64),
&(data.community as i64), &(data.community as i64),
&(data.role.bits() as i64), &(data.role.bits() as i32),
] ]
); );

View file

@ -21,7 +21,7 @@ impl DataManager {
title: get!(x->2(String)), title: get!(x->2(String)),
content: get!(x->3(String)), content: get!(x->3(String)),
owner: get!(x->4(i64)) as usize, owner: get!(x->4(i64)) as usize,
read: if get!(x->5(i64)) as i8 == 1 { read: if get!(x->5(i32)) as i8 == 1 {
true true
} else { } else {
false false
@ -71,7 +71,7 @@ impl DataManager {
&data.title, &data.title,
&data.content, &data.content,
&(data.owner as i64), &(data.owner as i64),
&(if data.read { 1 } else { 0 } as i64) &(if data.read { 1 } else { 0 } as i32)
] ]
); );
@ -162,7 +162,7 @@ impl DataManager {
let res = execute!( let res = execute!(
&conn, &conn,
"UPDATE notifications SET read = $1 WHERE id = $2", "UPDATE notifications SET read = $1 WHERE id = $2",
params![&(if new_read { 1 } else { 0 } as i64), &(id as i64)] params![&(if new_read { 1 } else { 0 } as i32), &(id as i64)]
); );
if let Err(e) = res { if let Err(e) = res {

View file

@ -38,10 +38,10 @@ impl DataManager {
None None
}, },
// likes // likes
likes: get!(x->7(i64)) as isize, likes: get!(x->7(i32)) as isize,
dislikes: get!(x->8(i64)) as isize, dislikes: get!(x->8(i32)) as isize,
// other counts // other counts
comment_count: get!(x->9(i64)) as usize, comment_count: get!(x->9(i32)) as usize,
} }
} }
@ -407,9 +407,9 @@ impl DataManager {
} else { } else {
0 as i64 0 as i64
}, },
&(0 as i64), &(0 as i32),
&(0 as i64), &(0 as i32),
&(0 as i64) &(0 as i32)
] ]
); );

View file

@ -26,7 +26,7 @@ impl DataManager {
owner: get!(x->2(i64)) as usize, owner: get!(x->2(i64)) as usize,
asset: get!(x->3(i64)) as usize, asset: get!(x->3(i64)) as usize,
asset_type: serde_json::from_str(&get!(x->4(String))).unwrap(), asset_type: serde_json::from_str(&get!(x->4(String))).unwrap(),
is_like: if get!(x->5(i64)) as i8 == 1 { is_like: if get!(x->5(i32)) as i8 == 1 {
true true
} else { } else {
false false
@ -80,7 +80,7 @@ impl DataManager {
&(data.owner as i64), &(data.owner as i64),
&(data.asset as i64), &(data.asset as i64),
&serde_json::to_string(&data.asset_type).unwrap().as_str(), &serde_json::to_string(&data.asset_type).unwrap().as_str(),
&(if data.is_like { 1 } else { 0 } as i64) &(if data.is_like { 1 } else { 0 } as i32)
] ]
); );