void DBUpdateThreadWorker::updateFeed (channels_container_t channels, QString url) { auto feedId = SB_->FindFeed (url); if (feedId == static_cast<decltype (feedId)> (-1)) { qWarning () << Q_FUNC_INFO << "skipping" << url << "cause seems like it's not in storage yet"; return; } const auto& feedSettings = GetFeedSettings (feedId); const auto ipc = feedSettings.NumItems_; const auto days = feedSettings.ItemAge_; for (const auto& channel : channels) { Channel_ptr ourChannel; try { const auto ourChannelID = SB_->FindChannel (channel->Title_, channel->Link_, feedId); ourChannel = SB_->GetChannel (ourChannelID, feedId); } catch (const StorageBackend::ChannelNotFoundError&) { AddChannel (channel, feedSettings); continue; } const auto& channelPart = GetItemMapChannelPart (ourChannel); int newItems = 0; int updatedItems = 0; for (const auto& item : channel->Items_) { Item_ptr ourItem; try { const auto ourItemID = SB_->FindItem (item->Title_, item->Link_, ourChannel->ChannelID_); ourItem = SB_->GetItem (ourItemID); } catch (const StorageBackend::ItemNotFoundError&) { if (AddItem (item, ourChannel, channelPart, feedSettings)) ++newItems; continue; } if (UpdateItem (item, ourItem)) ++updatedItems; } SB_->TrimChannel (ourChannel->ChannelID_, days, ipc); NotifyUpdates (newItems, updatedItems, channel); } }
void DBUpdateThreadWorker::updateFeed (channels_container_t channels, QString url) { auto feedId = SB_->FindFeed (url); if (feedId == static_cast<decltype (feedId)> (-1)) { qWarning () << Q_FUNC_INFO << "skipping" << url << "cause seems like it's not in storage yet"; return; } const auto& feedSettings = GetFeedSettings (feedId); const auto ipc = feedSettings.NumItems_; const auto days = feedSettings.ItemAge_; for (const auto& channel : channels) { Channel_ptr ourChannel; try { const auto ourChannelID = SB_->FindChannel (channel->Title_, channel->Link_, feedId); ourChannel = SB_->GetChannel (ourChannelID, feedId); } catch (const StorageBackend::ChannelNotFoundError&) { AddChannel (channel, feedSettings); continue; } int newItems = 0; int updatedItems = 0; for (const auto& item : channel->Items_) { auto mkLazy = [] (auto&& f) { return Util::MakeLazyF<boost::optional<IDType_t>> (f); }; const auto& ourItemID = Util::Msum ({ mkLazy ([&] { return SB_->FindItem (item->Title_, item->Link_, ourChannel->ChannelID_); }), mkLazy ([&] { return SB_->FindItemByLink (item->Link_, ourChannel->ChannelID_); }), mkLazy ([&] { if (!item->Link_.isEmpty ()) return boost::optional<IDType_t> {}; return SB_->FindItemByTitle (item->Title_, ourChannel->ChannelID_); }) }) (); if (ourItemID) { const auto& ourItem = SB_->GetItem (*ourItemID); if (UpdateItem (item, ourItem)) ++updatedItems; } else if (AddItem (item, ourChannel, feedSettings)) ++newItems; } SB_->TrimChannel (ourChannel->ChannelID_, days, ipc); NotifyUpdates (newItems, updatedItems, channel); } }