mirror of
https://github.com/WCBROW01/zblock.git
synced 2025-12-11 20:18:07 -05:00
Move exists check to the add command instead of the database insert routine so it can run earlier
This commit is contained in:
13
feed_info.c
13
feed_info.c
@ -126,21 +126,10 @@ zblock_feed_info_err zblock_feed_info_exists(PGconn *conn, const char *url, u64s
|
||||
return ZBLOCK_FEED_INFO_OK;
|
||||
}
|
||||
|
||||
// Insert new feed into the database
|
||||
// Insert new feed into the database. This function assumes that you have already verified that it has not been added previously.
|
||||
zblock_feed_info_err zblock_feed_info_insert(PGconn *conn, zblock_feed_info *feed) {
|
||||
if (!conn || !feed) return ZBLOCK_FEED_INFO_INVALID_ARGS;
|
||||
|
||||
// check if the feed already exists
|
||||
{
|
||||
int feed_exists;
|
||||
zblock_feed_info_err exists_error = zblock_feed_info_exists(conn, feed->url, feed->channel_id, &feed_exists);
|
||||
if (exists_error) {
|
||||
return exists_error;
|
||||
} else if (feed_exists) {
|
||||
return ZBLOCK_FEED_INFO_EXISTS;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t channel_id_be = htobe64(feed->channel_id);
|
||||
uint64_t guild_id_be = htobe64(feed->guild_id);
|
||||
const char *const insert_params[] = {feed->url, feed->last_pubDate, (char *) &channel_id_be, feed->title, (char *) &guild_id_be};
|
||||
|
||||
Reference in New Issue
Block a user