In-Portal Issue Tracker

Welcome to the In-Portal Open Source CMS Issue Tracker! This is a central management / tracking tool for all types of tasks / issues / bugs for the In-Portal Project. Before reporting any issues, please make sure to read the Guide into Issue Tracker and How to Properly Test and Report Bugs!

Viewing Issue Simple Details Jump to Notes ] Wiki ]  Related Changesets ] View Advanced ] Issue History ] Print ]
ID Category Type Reproducibility Date Submitted Last Update
0001234 [In-Portal CMS] Database feature request N/A 2012-03-26 12:54 2012-07-25 05:31
Reporter alex View Status public Project Name In-Portal CMS
Assigned To alex Developer
Priority normal Resolution fixed Fixed in Version 5.2.0-B3
Status closed Product Version 5.2.0-B2 Target Version 5.2.0
Time EstimateNo estimate
Summary 0001234: Improvements to kDBConnection class (iterator, kDBConnectionDebug class)
Description In-Portal has nice kDBConnection class, that we use in every day operations that require database interaction.

Among all it has following most important methods, that you can use:
* Query - runs sql statement and returns 2-dimensional array with a results
* GetRow - runs sql statement and returns first row only as 1-dimensional array
* GetCol - runs sql statement and returns first field from each resulting row
* GetOne - runs sql statement and returns first column from first row as a string
All of above functions work very well when you don't have thousands rows in database tables you operate.

In case if you have big tables, then idea to create an array of all selected rows inside kDBConnection::Query method (memory allocation #1) and then returning it to calling function (memory allocation #2) isn't a good idea since you get 2x memory allocation as you would normally get when using code from PHP documentation:

$rs = mysql_query($sql);

while ( $row = mysql_fetch_array($rs) ) {
...
}

mysql_free_result($rs);

To solve this problem I created kDBConnection::GetIterator method, that allocates memory only where you actually iterate the data you get from Query method:

$rows = $this->Conn->GetIterator($sql);
$row_count = count($rows);

foreach ($rows as $index => $row) {
...
}



I also created kDBConnectionDebug class, which is kDBConnection class descendant with Query & GetIterator methods overridden to collect additional statistics while in debug mode. Before kDBConnectionDebug class Query method always called _debugQuery method in first lines of Query method, which was slowing whole DB querying process a bit.
Additional Information
Tags No tags attached.
Reference https://groups.google.com/d/topic/in-portal-dev/DqcpnhBb8Ro/discussion
Change Log Message Adds ability to iterate database results using Iterator interface descendant class
Estimate Points 1
Attached Files patch file icon db_connection_iterator.patch [^] (22,354 bytes) 2012-03-26 12:54 [Show Content]
patch file icon db_loadbalancer_iterator.patch [^] (1,032 bytes) 2012-03-26 13:10 [Show Content]
patch file icon db_connection_iterator_getcol_and_fetch_assoc.patch [^] (1,966 bytes) 2012-03-27 05:08 [Show Content]

- Relationships Relation Graph ] Dependency Graph ]

-  Notes
User avatar (0004521)
alex (manager)
2012-03-26 12:56

TODO: need to look through Query and GetCol methods for ability to replace with GetIterator class instead.
User avatar (0004522)
alex (manager)
2012-03-26 12:57

Will test all together later.
User avatar (0004523)
alex (manager)
2012-03-26 12:58

Fix committed to 5.2.x branch. Commit Message:

Fixes 0001234: Improvements to kDBConnection class (iterator, kDBConnectionDebug class)
User avatar (0004524)
alex (manager)
2012-03-26 13:11

Patch "db_loadbalancer_iterator.patch" ensures, that slave connection will be used for every GetIterator call.
User avatar (0004527)
alex (manager)
2012-03-27 05:08

Patch "db_connection_iterator_getcol_and_fetch_assoc.patch" adds GetColIterator method and replaces mysql_fetch_array to mysql_fetch_assoc method call inside iterators.
User avatar (0004948)
alex (manager)
2012-07-25 05:31

Since 5.2.0 version was released.

- Related Changesets
In-Portal CMS: 5.2.x r15242
Timestamp: 2012-03-27 05:09:34
Author: alex
Details ] Diff ]
Bug 0001234: Improvements to kDBConnection class (iterator, kDBConnectionDebug class)
1. adds GetColIterator method
2. replaces mysql_fetch_array to mysql_fetch_assoc method call inside iterators
mod - /in-portal/branches/5.2.x/core/kernel/db/db_connection.php Diff ] File ]
mod - /in-portal/branches/5.2.x/core/kernel/db/db_load_balancer.php Diff ] File ]
In-Portal CMS: 5.2.x r15240
Timestamp: 2012-03-26 13:11:54
Author: alex
Details ] Diff ]
Bug 0001234: Improvements to kDBConnection class (iterator, kDBConnectionDebug class)
1. ensures, that GetIterator method would be called on slave connections only
mod - /in-portal/branches/5.2.x/core/kernel/db/db_load_balancer.php Diff ] File ]
In-Portal CMS: 5.2.x r15239
Timestamp: 2012-03-26 12:58:13
Author: alex
Details ] Diff ]
Fixes 0001234: Improvements to kDBConnection class (iterator, kDBConnectionDebug class)
mod - /in-portal/branches/5.2.x/core/kernel/application.php Diff ] File ]
mod - /in-portal/branches/5.2.x/core/kernel/db/db_connection.php Diff ] File ]
mod - /in-portal/branches/5.2.x/core/kernel/db/db_load_balancer.php Diff ] File ]
mod - /in-portal/branches/5.2.x/core/units/helpers/language_import_helper.php Diff ] File ]

- Issue History
Date Modified Username Field Change
2012-07-25 05:31 alex Note Added: 0004948
2012-07-25 05:31 alex Status resolved => closed
2012-03-27 05:09 alex Changeset attached 5.2.x r15242
2012-03-27 05:08 alex Note Added: 0004527
2012-03-27 05:08 alex File Added: db_connection_iterator_getcol_and_fetch_assoc.patch
2012-03-26 13:11 alex Changeset attached 5.2.x r15240
2012-03-26 13:11 alex Note Added: 0004524
2012-03-26 13:10 alex File Added: db_loadbalancer_iterator.patch
2012-03-26 12:58 alex Note Added: 0004523
2012-03-26 12:58 alex Status reviewed and tested => resolved
2012-03-26 12:58 alex Fixed in Version => 5.2.0-B3
2012-03-26 12:58 alex Resolution open => fixed
2012-03-26 12:58 alex Assigned To !COMMUNITY => alex
2012-03-26 12:58 alex Changeset attached 5.2.x r15239
2012-03-26 12:57 alex Note Added: 0004522
2012-03-26 12:57 alex Status needs testing => reviewed and tested
2012-03-26 12:56 alex Note Added: 0004521
2012-03-26 12:56 alex Assigned To => !COMMUNITY
2012-03-26 12:56 alex Developer => alex
2012-03-26 12:56 alex Status active => needs testing
2012-03-26 12:55 alex Reference => https://groups.google.com/d/topic/in-portal-dev/DqcpnhBb8Ro/discussion
2012-03-26 12:54 alex New Issue
2012-03-26 12:54 alex File Added: db_connection_iterator.patch
2012-03-26 12:54 alex Change Log Message => Adds ability to iterate database results using Iterator interface descendant class
2012-03-26 12:54 alex Estimate Points => 1



Web Development by Intechnic
In-Portal Open Source CMS
In-Portal Open Source CMS
Copyright © 2000 - 2009 MantisBT Group

Powered by Mantis Bugtracker