diff --git a/crates/crawler/src/main.rs b/crates/crawler/src/main.rs index 62ecd8d..cb6b8d2 100644 --- a/crates/crawler/src/main.rs +++ b/crates/crawler/src/main.rs @@ -201,12 +201,12 @@ fn crawl(tx: &mut mysql::Transaction, channel_config: &config::Channel) -> Resul image_id } }; - let content_image_id = - tx.insert_content_image(channel_item_content_id, image_id)?; - debug!("Add content image relationship #{content_image_id}"); + let channel_item_content_image_id = + tx.insert_channel_item_content_image(channel_item_content_id, image_id)?; + debug!("Add content image relationship #{channel_item_content_image_id}"); let uri = format!("/image/{image_id}"); tx.replace_channel_item_content_description( - channel_item_content_id, + channel_item_content_description_id, src, &uri, )?; diff --git a/crates/mysql/database/0.1.0.sql b/crates/mysql/database/0.1.0.sql index 2f1e5f6..443595f 100644 --- a/crates/mysql/database/0.1.0.sql +++ b/crates/mysql/database/0.1.0.sql @@ -1,5 +1,5 @@ -- MySQL Script generated by MySQL Workbench --- нд, 11-січ-2026 20:33:40 +0200 +-- нд, 11-січ-2026 21:01:10 +0200 -- Model: New Model Version: 1.0 -- MySQL Workbench Forward Engineering @@ -101,13 +101,13 @@ ENGINE = InnoDB; -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `rssto`.`channel_item_content_image` ( `channel_item_content_image_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, - `content_channel_item_content_id` BIGINT UNSIGNED NOT NULL, + `channel_item_content_id` BIGINT UNSIGNED NOT NULL, `image_id` BIGINT UNSIGNED NOT NULL, PRIMARY KEY (`channel_item_content_image_id`), - INDEX `fk_channel_item_content_image_channel_item_content_idx` (`content_channel_item_content_id` ASC) VISIBLE, + INDEX `fk_channel_item_content_image_channel_item_content_idx` (`channel_item_content_id` ASC) VISIBLE, INDEX `fk_channel_item_content_image_image_idx` (`image_id` ASC) VISIBLE, CONSTRAINT `fk_channel_item_content_image_channel_item_content` - FOREIGN KEY (`content_channel_item_content_id`) + FOREIGN KEY (`channel_item_content_id`) REFERENCES `rssto`.`channel_item_content` (`channel_item_content_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, diff --git a/crates/mysql/src/connection.rs b/crates/mysql/src/connection.rs index 22ce0cf..35c3469 100644 --- a/crates/mysql/src/connection.rs +++ b/crates/mysql/src/connection.rs @@ -114,22 +114,10 @@ impl Connection { } } - pub fn content_image(&mut self, content_image_id: u64) -> Result, Error> { - self.conn.exec_first( - "SELECT `content_image_id`, - `content_id`, - `image_id`, - `data`, - `source` FROM `content_image` - JOIN `image` ON (`image`.`image_id` = `content_image`.`image_id`) - WHERE `content_image_id` = ? LIMIT 1", - (content_image_id,), - ) - } - pub fn image(&mut self, image_id: u64) -> Result, Error> { self.conn.exec_first( "SELECT `image_id`, + `provider_id`, `sha256`, `src`, `url`, diff --git a/crates/mysql/src/table.rs b/crates/mysql/src/table.rs index 867abb8..2c9218d 100644 --- a/crates/mysql/src/table.rs +++ b/crates/mysql/src/table.rs @@ -59,17 +59,6 @@ pub struct Image { pub data: Vec, } -/// Includes joined `image` table members -#[derive(Debug, PartialEq, Eq, FromRow)] -pub struct ContentImage { - pub content_image_id: u64, - pub content_id: u64, - pub image_id: u64, - // Image members (JOIN) - pub data: Vec, - pub source: String, -} - pub enum Sort { Asc, Desc, diff --git a/crates/mysql/src/transaction.rs b/crates/mysql/src/transaction.rs index 970aaef..a087ece 100644 --- a/crates/mysql/src/transaction.rs +++ b/crates/mysql/src/transaction.rs @@ -106,20 +106,20 @@ impl Transaction { provider_id: u64, ) -> Result, Error> { self.tx.exec( - "SELECT `t1`.`content_id`, - `t1`.`channel_item_id`, + "SELECT `t1`.`channel_item_content_description_id`, + `t1`.`channel_item_content_id`, `t1`.`provider_id`, `t1`.`title`, `t1`.`description` FROM `channel_item_content_description` AS `t1` WHERE `t1`.`provider_id` IS NULL AND NOT EXISTS ( SELECT NULL FROM `channel_item_content_description` AS `t2` - WHERE `t2`.`channel_item_id` = `t1`.`channel_item_id` + WHERE `t2`.`channel_item_content_description_id` = `t1`.`channel_item_content_description_id` AND `t2`.`provider_id` = ? LIMIT 1 )", (provider_id,), ) - } + } // @TODO upgrade to the latest version pub fn insert_channel_item_content(&mut self, channel_item_id: u64) -> Result { self.tx.exec_drop( @@ -148,21 +148,26 @@ impl Transaction { pub fn replace_channel_item_content_description( &mut self, - content_id: u64, + channel_item_content_description_id: u64, from: &str, to: &str, ) -> Result<(), Error> { self.tx.exec_drop( "UPDATE `channel_item_content_description` - SET `description` = REPLACE(`description`, ?, ?) WHERE`content_id` = ?", - (from, to, content_id), + SET `description` = REPLACE(`description`, ?, ?) + WHERE `channel_item_content_description_id` = ?", + (from, to, channel_item_content_description_id), ) } - pub fn insert_content_image(&mut self, content_id: u64, image_id: u64) -> Result { + pub fn insert_channel_item_content_image( + &mut self, + channel_item_content_id: u64, + image_id: u64, + ) -> Result { self.tx.exec_drop( - "INSERT INTO `content_image` SET `content_id` = ?, `image_id` = ?", - (content_id, image_id), + "INSERT INTO `channel_item_content_image` SET `channel_item_content_id` = ?, `image_id` = ?", + (channel_item_content_id, image_id), )?; Ok(self.tx.last_insert_id().unwrap()) }