Re: Fix for PEAR Cache_Container_db.php

From: Date: Fri, 08 Nov 2002 10:08:02 +0000
Subject: Re: Fix for PEAR Cache_Container_db.php
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-10611@lists.php.net to get a copy of this message
On Fri, 2002-11-08 at 10:19, Lorenzo Alberton wrote: > 08/11/2002 9.53.08 > > > > Hi Lorenzo > > > > > > Can you make a unified diff patch file out of this and not sending > > > the whole code. It makes it much easier to see, what you changed > > > and i don't have to do copy&paste and fighting with some funny > > > whitespacehandling of my mailclients :) > > Of course, if only could I understand how to make a diff in the format > used here with cygwin... My Linux box is dead at the moment, so I have > to do everyth with cygwin until I find some time to set Linux up again.. > Could you tell me what syntax I'm supposed to use with diff? Tnx diff -u old.php new.php at least it works this way on linux :) > To sum up the changes I made: why did you remove all sprintf ? I have no opinion in which is better, but you shouldn't mix stylechanges (which this is) and code-changes in one patch. Therefore I copied your stuff into our stuff and didn't just do a copy&paste :) > - I moved the last $res = $this->db->query($query); > a level up because it was mis-placed, outside the right parenthesis I don't see that error, you just moved *** if (DB::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); } *** into the if, but it's needed outside of the if, because it also checks, if something bad happened at the first DELETE > - I substituted mysql's NOW() function with a simple time(), so it's > more portable between different dbms. > - I changed the $entry assignment in the while loop because last time > it was called, it overwrote the value otherwise needed in the query > just after the while loop ( $entry is set to "null" in the last > loop, making the later use of $entry[changed] senseless...). this is ok. > > Attached: a txt with the replacement, waiting for the diff... So you > can start playing with it without worring about whitespacehandling :-) next time (unless you changed a lot in the other functions), please just send me your whole new db.php file, then I can make the diff by myself :) Attached is my new patch, maybe you can check it shorty and then I will commit it. > Actually I think Lukas answered for me... I really don't see what > differences should be done between db_container and mdb_container > wrt dependencies... they both need sth else, so why a different > treatment for the two? If db needs a dependency, so mdb would also do, > otherwise don't set any dependency for either of them... > However I think that "soft dependencies", as introduced by Stig, > are the way to go... It was more a general question :) I had in mind the "suggests" feature of debian's apt-get, so I wondered if pear has something similar to offer. chregu > > > > > Thanks > > > > > > chregu > > Tnx to you! > Lorenzo > ---- > > function garbageCollection($maxlifetime) > { > $this->flushPreload(); > > $query = 'DELETE FROM ' . $this->cache_table > .' WHERE (expires <= ' . time() > .' AND expires > 0) OR changed <= '. time() - $maxlifetime; > > $res = $this->db->query($query); > > $query = 'SELECT sum(length(cachedata)) as CacheSize FROM ' > . $this->cache_table; > > $cachesize = $this->db->GetOne($query); > //if cache is to big. > if ($cachesize > $this->highwater) > { > //find the lowwater mark. > $query = 'SELECT length(cachedata) as size, changed FROM ' > . $this->cache_table .' ORDER BY changed DESC'; > > $res = $this->db->query($query); > $numrows = $this->db->numRows($res); > $keep_size = 0; > while ($keep_size < $this->lowwater && $numrows--) { > $entry = $res->fetchRow(DB_FETCHMODE_ASSOC); > $keep_size += $entry['size']; > } > > //delete all entries, which were changed before the "lowwwater mark" > $query = 'DELETE FROM ' . $this->cache_table > .' WHERE changed<='.($entry['changed'] ? > $entry['changed'] : 0); > > $res = $this->db->query($query); > if (DB::isError($res)) { > return new Cache_Error('DB::query failed: ' > . DB::errorMessage($res), __FILE__, __LINE__); > } > } > }

Attachment: [text/x-patch] db.php.patch
« previous php.pear.dev (#10611) next »