witten
/
luminotes
Archived
1
0
Fork 0

Fixed a bug where, after you highlighted a link and clicked the link button

to unlink it, the link info box popped up.
Actually checking in cache changes that were supposed to be in previous
release.
This commit is contained in:
Dan Helfman 2008-03-10 23:15:33 +00:00
parent 0bbd3d19a2
commit 2d55455120
3 changed files with 55 additions and 25 deletions

6
NEWS
View File

@ -1,3 +1,9 @@
1.2.7: March ??, 2008
* Fixed a bug where, after you highlighted a link and clicked the link button
to unlink it, the link info box popped up.
* Actually checking in cache changes that were supposed to be in previous
release.
1.2.6: March 10, 2008 1.2.6: March 10, 2008
* Now creating a new cache connection for each usage of the cache. This will * Now creating a new cache connection for each usage of the cache. This will
prevent crashes that arose when multiple threads tried to share a single prevent crashes that arose when multiple threads tried to share a single

View File

@ -56,13 +56,12 @@ class Database( object ):
) )
self.__cache = cache self.__cache = cache
if not cache:
try: try:
import cmemcache import cmemcache
self.__cache = cmemcache.Client( [ "127.0.0.1:11211" ], debug = 0 ) print "using memcached"
print "using memcached" except ImportError:
except ImportError: return None
pass
def __get_connection( self ): def __get_connection( self ):
if self.__connection: if self.__connection:
@ -70,6 +69,16 @@ class Database( object ):
else: else:
return self.__pool.getconn() return self.__pool.getconn()
def __get_cache_connection( self ):
if self.__cache is not None:
return self.__cache
try:
import cmemcache
return cmemcache.Client( [ "127.0.0.1:11211" ], debug = 0 )
except ImportError:
return None
def save( self, obj, commit = True ): def save( self, obj, commit = True ):
""" """
Save the given object to the database. Save the given object to the database.
@ -88,11 +97,13 @@ class Database( object ):
else: else:
cursor.execute( obj.sql_create() ) cursor.execute( obj.sql_create() )
cache = self.__get_cache_connection()
if commit: if commit:
connection.commit() connection.commit()
if self.__cache: if cache:
self.__cache.set( obj.cache_key, obj ) cache.set( obj.cache_key, obj )
else: elif cache:
# no commit yet, so don't touch the cache # no commit yet, so don't touch the cache
connection.pending_saves.append( obj ) connection.pending_saves.append( obj )
@ -101,11 +112,13 @@ class Database( object ):
connection.commit() connection.commit()
# save any pending saves to the cache # save any pending saves to the cache
if self.__cache: cache = self.__get_cache_connection()
for obj in connection.pending_saves:
self.__cache.set( obj.cache_key, obj )
connection.pending_saves = [] if cache:
for obj in connection.pending_saves:
cache.set( obj.cache_key, obj )
connection.pending_saves = []
def load( self, Object_type, object_id, revision = None ): def load( self, Object_type, object_id, revision = None ):
""" """
@ -122,14 +135,19 @@ class Database( object ):
@rtype: Object_type or NoneType @rtype: Object_type or NoneType
@return: loaded object, or None if no match @return: loaded object, or None if no match
""" """
if revision is None and self.__cache: # don't bother caching old revisions if revision is None:
obj = self.__cache.get( Persistent.make_cache_key( Object_type, object_id ) ) cache = self.__get_cache_connection()
else:
cache = None
if cache: # don't bother caching old revisions
obj = cache.get( Persistent.make_cache_key( Object_type, object_id ) )
if obj: if obj:
return obj return obj
obj = self.select_one( Object_type, Object_type.sql_load( object_id, revision ) ) obj = self.select_one( Object_type, Object_type.sql_load( object_id, revision ) )
if obj and revision is None and self.__cache: if obj and cache:
self.__cache.set( obj.cache_key, obj ) cache.set( obj.cache_key, obj )
return obj return obj
@ -147,9 +165,14 @@ class Database( object ):
@rtype: Object_type or NoneType @rtype: Object_type or NoneType
@return: loaded object, or None if no match @return: loaded object, or None if no match
""" """
if use_cache and self.__cache: if use_cache:
cache = self.__get_cache_connection()
else:
cache = None
if cache:
cache_key = sha.new( sql_command ).hexdigest() cache_key = sha.new( sql_command ).hexdigest()
obj = self.__cache.get( cache_key ) obj = cache.get( cache_key )
if obj: if obj:
return obj return obj
@ -167,8 +190,8 @@ class Database( object ):
else: else:
obj = Object_type( *row ) obj = Object_type( *row )
if obj and use_cache and self.__cache: if obj and cache:
self.__cache.set( cache_key, obj ) cache.set( cache_key, obj )
return obj return obj
@ -227,10 +250,11 @@ class Database( object ):
connection.commit() connection.commit()
def uncache_command( self, sql_command ): def uncache_command( self, sql_command ):
if not self.__cache: return cache = self.__get_cache_connection()
if not cache: return
cache_key = sha.new( sql_command ).hexdigest() cache_key = sha.new( sql_command ).hexdigest()
self.__cache.delete( cache_key ) cache.delete( cache_key )
@staticmethod @staticmethod
def generate_id(): def generate_id():

View File

@ -980,7 +980,7 @@ Wiki.prototype.toggle_link_button = function ( event ) {
else else
link = this.focused_editor.end_link(); link = this.focused_editor.end_link();
if ( link ) { if ( link && link.parentNode != null ) {
var self = this; var self = this;
this.resolve_link( link_title( link ), link, function ( summary ) { this.resolve_link( link_title( link ), link, function ( summary ) {
self.display_link_pulldown( self.focused_editor, link ); self.display_link_pulldown( self.focused_editor, link );