Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#16336 closed enhancement (invalid)

wpdb::get_row never uses the cache

Reported by: lacrymology's profile Lacrymology Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Database Keywords: close
Focuses: Cc:

Description (last modified by scribu)

wpdb::get_row never uses the cached results, look at this

	function get_row( $query = null, $output = OBJECT, $y = 0 ) {
		$this->func_call = "\$db->get_row(\"$query\",$output,$y)";
		if ( $query )
			$this->query( $query );
		else
			return null;
                // more code

and then

	function query( $query ) {
		if ( ! $this->ready )
			return false;

		// some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
		if ( function_exists( 'apply_filters' ) )
			$query = apply_filters( 'query', $query );

		$return_val = 0;
		$this->flush();

See how the cache never gets called? if you write a query, the old one gets flushed without checking if it was the same as before, if you use null, null gets returned, an if($this->last_query != $query) needs to be put in ::query or the return null removed from ::get_row, I'd prefer the first solution.

Change History (3)

#1 @scribu
13 years ago

  • Component changed from General to Database
  • Description modified (diff)
  • Keywords close added

The caching is done on top of WPDB, not through it.

Also, what about DML queries? (INSERT, DELETE etc.)

#2 @Lacrymology
13 years ago

well, then why does wpdb::last_results exist? and why does ::query call mysql_release_results before it returns? there's something either in the API or the implementation that's not coherent

#3 @nacin
13 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

It's only last_result, and it's used when iterating over cells and columns in get_col() and get_var(), among other things.

Note: See TracTickets for help on using tickets.