Following is my code :
error_log('before query'.date("H:i:s:ms"));
$response = $client->query(array(
"TableName" => "user",
"KeyConditions" => array(
"userId" => array( "ComparisonOperator" => ComparisonOperator::EQ,
"AttributeValueList" => array(
array(Type::NUMBER => 2)
))),
));
error_log('after query'.date("H:i:s:ms"));
print_r($response);
My tables Read capacity is 6 reads/sec
Output of Error logs
before query 16:05:29:0229
after query 16:05:32:0232
Question: Why it took 3 secs to read the user for first time? If I add one more query after my first query then it take less than 1 sec to respond.
Any light on the path would be helpful
-Thanks
This can happen if you are executing this query from different region than database's instance or from local.
If you haven't uploaded file with this query to the same region as your dynamoDb then it will take some time to build connection with your DB instance. Try to upload this script on the same region's server as your DB and then try again.
Related
I am trying to find ways to switch between a Master and Slave database (Postgresql). If the Master is not available then SilverStripe will pick it up and switch databases to the Slave (read-only) database.
I was reading through Sam Minnee's post about it and am wondering if there has been any work done on this? Ideally, this would be an automated action.
you could place code in your _config.php like...
global $databaseConfig;
$conn = new mysqli($databaseConfig['server'], $$databaseConfig['username'], $$databaseConfig['password']);
if ($conn->connect_error)
$otherDB = array(
"type" => 'MySQLDatabase',
"server" => 'localhost',
"username" => 'read_only_user',
"password" => 'some_password',
"path" => '',
"database" => 'other_database'
);
My code is as below..
Please note that I am trying to retrive all the accounts whose where the Accounts.name='bhagya'.
The same query workes for me in SugarCRM Version 6.5 (Community edition) but in case of SugarCRM 7 it is not working when I mention query parameter. If I mention 'query'=>'' then I get all the records from the sugarcrm 7 server. It fails when I specify any filter for query parameter. I am using RestAPI - 4.1
$get_entry_list_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => 'Accounts',
//The SQL WHERE clause without the word "where".
//'query' => "Accounts.billing_address_postalcode='60329'",
// 'query' => "Accounts.name='Ingrid Rofalsky'",
'query'=>'',
//The SQL ORDER BY clause without the phrase "order by".
'order_by' => "",
//The record offset from which to start.
'offset' => 0,
//A list of fields to include in the results.
'select_fields' => array(
'id',
'name',
),
//A list of link names and the fields to be returned for each link name.
'link_name_to_fields_array' => array(),
//The maximum number of results to return.
'max_results' => 10,
//If deleted records should be included in results.
'deleted' => 0,
//If only records marked as favorites should be returned.
'favorites' => false,
);
print_r($get_entry_list_parameters);
$get_entry_list_result = call('get_entry_list', $get_entry_list_parameters, $url);
echo '<pre>';
print_r($get_entry_list_result);
echo '</pre>';
Can some one help me on this..
Thank you.
Regards
- Bhagya
The Rest API has changed a lot in Sugar7.
The URL for the invokation should look like
http://servname.com/pro720/rest/v10/Accounts?filter[0][name][$starts]=B&filter[0][email_addresses.email_address]=burgers#example.com&fields=name,account_type,description,email
Where you are filtering the accounts with a name that starts with B, the mail address is burgers#example.com and where you retrieve only the fields name,account_type,description and email
Changing the module name to lowercase in query option solved this problem.
I got the answer for my query from below link.
https://community.sugarcrm.com/sugarcrm/topics/get_entry_list_method_with_query_parameter_on_sugar_crm_7_does_not_work?topic-reply-list%5Bsettings%5D%5Bfilter_by%5D=all&topic-reply-list%5Bsettings%5D%5Bpage%5D=1#reply_14588280
Thanks again
Regards
- Bhagya
I am having a problem with mongo db when used in yii framework. I tried both yii extensions yii mong suite and direct mongo suite. I have trouble implementing or operations in mongo with these extension. I used this code in yii mongo suite but its returning all the values.
$userDetail = $user->findAll(
array(
'$or' => array(
"first_name" => "akash",
"first_name" => "anoop"
)
)
); var_dump($userDetail);die;
I dont know how to use or operation with direct mongo suite. Please help me as soon as possible. Thank You.
With the direct MongoDBSuite, providing it implements MongoDB directly, your $or should look like:
$userDetail = $user->findAll(
array(
'$or' => array(
array("first_name" => "akash"),
array("first_name" => "anoop")
)
)
);
I know this is pretty late but let me know if this helps. I'm using YiiMongoDbSuite. You could check to see if the name is in an array.
$criteria = new EMongoCriteria;
$criteria->addCond("first_name","in",array("akash", "anoop"));
Read more here about using the EMongoCriteria Object: http://bit.ly/1oOFPBJ
I am trying to optimize zend for performance.
I used as much cache as possible and got to the code of this page
where do i have to write it ? i tried putting it in bootstrap __initAutoload() but the profiler shows no change whatsover
$classFileIncCache = APPLICATION_PATH . '/../data/pluginLoaderCache.php';
if (file_exists($classFileIncCache)) {
include_once $classFileIncCache;
}
Zend_Loader_PluginLoader::setIncludeFileCache($classFileIncCache);
Can someone explain how to use it pluginloader and if it has a performance increase?
here is part of my bootstrap
protected function _initSessionAfterDb()
{
//http://stackoverflow.com/questions/1100562/zend-error-via-my-ini-file
$this->bootstrap('db');
$this->bootstrap('session');
}
protected function _initSession()
{
$this->bootstrap('cache');//http://stackoverflow.com/questions/5271018/zend-how-to-enable-cachemetadata-on-session-table
//NOTE: this config is also passed to Zend_Db_Table so anything specific
//to the table can be put in the config as well
$config = array(
'name' => 'session', //table name as per Zend_Db_Table
'primary' => array(
'session_id', //the sessionID given by PHP
'save_path', //session.save_path
'name', //session name
//'cols' => array('session_id', 'save_path', 'name', 'modified', 'lifetime', 'session_data')
),
'primaryAssignment' => array(
//you must tell the save handler which columns you
//are using as the primary key. ORDER IS IMPORTANT
'sessionId', //first column of the primary key is of the sessionID
'sessionSavePath', //second column of the primary key is the save path
'sessionName', //third column of the primary key is the session name
),
'modifiedColumn' => 'modified', //time the session should expire
'dataColumn' => 'session_data', //serialized data
'lifetimeColumn' => 'lifetime', //end of life for a specific record
'user_id' => 'user_id'
);
//Tell Zend_Session to use your Save Handler
$savehandler = new Zend_Session_SaveHandler_DbTable($config);
//http://framework.zend.com/wiki/display/ZFPROP/Zend_Session_SaveHandler_DbTable
//cookie persist for 30 min
$config = Zend_Registry::get('config');
$seconds = $config->session->seconds_life;
//make the session persist for 30 min
$savehandler->setLifetime($seconds)
->setOverrideLifetime(true);
Zend_Session::setSaveHandler($savehandler);
Zend_Session::start();
}
I think you are not starting on the good foot, early optimization is the root of all evil. First I think you should investigate which part of your application is the slowest and try to fix it, xdebug should be able to help to get some performance data.
The plugin loader cache would increase the performance but not by a great deal, the framework search in the filesystem the plugins you are using. Enabling the cache would skip the searching process but I doubt it would make your application 50% faster all suddendly.
Also to answer where you should write it, like you mentioned the bootstrap is probably the best place.
I have two problem : How can I get affected rows by php mongodb driver ,and how about the last insert id ? thanks .
You can get number of results right from the cursor using count function:
$collection->find()->count();
You can even get number of all records in collection using:
$collection->count();
Using insert method, _id is added to input array automatically.
$a = array('x' => 1);
$collection->insert($a,array('safe'=>true));
var_dump($a);
array(2) {
["x"]=>
int(1)
["_id"]=>
object(MongoId)#4 (0) {
}
}
I don't believe that there is any type of affected_rows() method at your disposal with mongodb. As for the last insert _id You can generate them in your application code and include them in your insert, so there's really no need for any mysql like insert_id() method.
$id = new MongoId();
$collection->insert(array('
'_id' => $id,
'username' => 'username',
'email' => 'johndoe#gmail.com'
'));
Now you can use the object stored in $id however you wish.
Maybe MongoDB::lastError is what you are looking for:
(http://php.net/manual/en/mongodb.lasterror.php)
It calls the getLastError command:
(http://www.mongodb.org/display/DOCS/getLastError+Command)
which returns, among other things:
n - if an update was done, this is the number of documents updated.
For number of affected rows:
$status = $collection->update( $criteria, array( '$set' => $data ) );
$status['n']; // 'n' is the number of affected rows
If you have the output of your action, you can call relative function:
// $m hold mongo library object
$output = $m->myCollection->updateOne([
'_id' => myMongoCreateID('56ce2e90c9c037dba19c3ce1')], [
'$set' => ['column' => 'value']
]);
// get number of modified records
$count = $output->getModifiedCount();
$output is of of type MongoDB\UpdateResult. Relatively check following files to figure out the best function to find inserted, deleted, matched or whatever result you need:
https://github.com/mongodb/mongo-php-library/blob/master/src/InsertManyResult.php
https://github.com/mongodb/mongo-php-library/blob/master/src/DeleteResult.php
https://github.com/mongodb/mongo-php-library/blob/master/src/InsertOneResult.php
https://github.com/mongodb/mongo-php-library/blob/master/src/UpdateResult.php