I am working on a website written in **Yii framework** (version 1.1.14) that allows uploading and displaying news. The admin of the site can select three news to promote to homepage and specify the order in which they are displayed. I am using **Mysql** database. The **news** table has two fields: **isChecked** (0 or 1) and **homepagePos** (integer) in addition to the other fields. The **isChecked** field determines whether the news is selected for displaying in homepage and the **homepagePos** field determines the order in which the news are displayed. I have used jquery's sortable plugin to sort the news. When the user selects which news to display and clicks save button, the news ids are sent to php via ajax.

The javascript portion to send the values to news controller is as follows:

```
$(document).on('click', '#saveToHomepage', function() 
{
    var url = ajaxRequestSendUrl;   //ajaxRequestSendUrl contains url to news controller's promote to homepage method.
    $.ajax({
        method: "GET",
        url: url,
        data: {
            contentIds: contentIds, //contentIds contains an array of news Ids in certain order
            },
        success: function() {
        // Show success message
        },
        error: function() {
            alert('Some error occured. Please reload the page and try again.');
        }
    });
});

```

Here's the promote to homepage method in news controller:

```
public function actionHomepage()
{
    $allNews = News::model()->findAll();
    $value = $_GET['contentIds'];
    foreach ($allNews as $news) {
        if($news->id == $value[0] ||$news->id == $value[1] ||$news->id == $value[2])
        {
            $news->isChecked = 1;
            $news->homepagePos = array_search($news->id, $value); //Assign index of the array as the position
            $news->save();
        }
        else
        {
            $news->isChecked = 0;
            $news->homepagePos = -1;
            $news->save();
        }
    }
}

```

My problem is that the news table I have has over 2k data. So the ajax call takes really long time (over a minute) to complete. Is there any way I can optimize the code or is there other way I can approach this to reduce the time taken to complete this operation?
Thanks in advance