Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6859799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:19:41+00:00 2026-05-27T02:19:41+00:00

So basically I have just benchmarked my update_feeds controller and found that the amount

  • 0

So basically I have just benchmarked my update_feeds controller and found that the amount of sql queries that are run are shocking. I am looking for a way to optimise the process of fectching multiple feeds and then insert the data into a table (title and url)

Currently there are 193 Feeds in the DB that I fetch the URL’s for and then I process these one by one checking and insert data of them into another table. The problem is simplepie goes through and inserts every item.

So I am ending up with QUERIES: 3297
Total Execution Time 202.8051

I am looking for a way to optimise this process does anyone have any tips? I will post some code. Thanks.

Controller for fetching the feeds

          $this->output->set_profiler_sections($sections);
        $this->load->library('simplepie');
        //$this->simplepie->cache_location = BASEPATH .'cache';
        $this->load->model('FeedModel');
        $this->load->model('FeedItemModel');
        $feeds = $this->FeedModel->get_feed_update_urls();
        foreach ($feeds as $feed_id => $feed_url) {
            $this->simplepie->set_feed_url($feed_url);
            //$this->simplepie->set_cache_duration(0);
$this->simplepie->set_timeout(0);
            $this->simplepie->init();
            $items = $this->simplepie->get_items();
            foreach ($items as $item) {
                $this->FeedItemModel->load($feed_id, md5($item->get_id()));
                $this->FeedItemModel->link = $item->get_permalink();
                $this->FeedItemModel->title = $item->get_title();
                $this->FeedItemModel->created_time = $item->get_date('Y-m-d H:i:s');
                $this->FeedItemModel->save();
            }
        }

Model for inserting feeds

function save() {
        if ($this->_id !== false) {
            $this->db->query('UPDATE feed_items SET link=?, title=?, created_time=? WHERE id=?', array($this->link, $this->title, $this->created_time, $this->_id));
        } else {
            $this->db->query('INSERT INTO feed_items(feed_id, remote_id, link, title, created_time, updated_time) VALUES (?, ?, ?, ?, ?, NOW()) ON DUPLICATE KEY UPDATE remote_id=remote_id', array($this->feed_id, $this->remote_id, $this->link, $this->title, $this->created_time, $this->remote_id));
            $this->_id = $this->db->insert_id();
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:19:42+00:00Added an answer on May 27, 2026 at 2:19 am

    Instead of loading every single time and then saving, you should instead do an update (and then insert when update doesn’t find rows). That will reduce by a single query per feed item.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have site list on certain pages that basically just have links to
I have just made my first proper little desktop GUI application that basically wraps
I have just optimised some Ruby code that was in a controller method, replacing
I would just like your feedback on something. Basically I have a value called
Hey all, basically i have an empty AS3 fla file with just the following
I have an MFC application. It is basically just copying files from one drive
I have just a simple question ! Basically, I want to make a website
basically have two questions. 1. Is there a c++ library that would do full
I have just started using OutputCache on some of my controller actions and I
I have just gotten started with an Eclipse RCP application, it is basically just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.