witten
/
luminotes
Archived
1
0
Fork 0

Called controller.Users.calculate_group_storage() from various places. Fixed model.User.sql_calculate_group_storage().

This commit is contained in:
Dan Helfman 2008-06-05 15:59:01 -07:00
parent d21bd38e87
commit 0faa06ea10
4 changed files with 27 additions and 18 deletions

View File

@ -638,6 +638,8 @@ class Files( object ):
if not user:
raise Access_error()
user.group_storage_bytes = self.__users.calculate_group_storage( user )
return dict(
filename = db_file.filename,
size_bytes = db_file.size_bytes,
@ -674,6 +676,7 @@ class Files( object ):
self.__database.execute( db_file.sql_delete(), commit = False )
user = self.__users.update_storage( user_id, commit = False )
self.__database.commit()
user.group_storage_bytes = self.__users.calculate_group_storage( user )
Upload_file.delete_file( file_id )

View File

@ -722,6 +722,7 @@ class Notebooks( object ):
user = self.__users.update_storage( user_id, commit = False )
self.__database.uncache_command( notebook.sql_count_notes() ) # cached note count is now invalid
self.__database.commit()
user.group_storage_bytes = self.__users.calculate_group_storage( user )
else:
user = None
@ -780,6 +781,7 @@ class Notebooks( object ):
user = self.__users.update_storage( user_id, commit = False )
self.__database.uncache_command( notebook.sql_count_notes() ) # cached note count is now invalid
self.__database.commit()
user.group_storage_bytes = self.__users.calculate_group_storage( user )
return dict( storage_bytes = user.storage_bytes )
else:
@ -837,6 +839,7 @@ class Notebooks( object ):
user = self.__users.update_storage( user_id, commit = False )
self.__database.uncache_command( notebook.sql_count_notes() ) # cached note count is now invalid
self.__database.commit()
user.group_storage_bytes = self.__users.calculate_group_storage( user )
return dict( storage_bytes = user.storage_bytes )
else:
@ -889,6 +892,7 @@ class Notebooks( object ):
user = self.__users.update_storage( user_id, commit = False )
self.__database.uncache_command( notebook.sql_count_notes() ) # cached note count is now invalid
self.__database.commit()
user.group_storage_bytes = self.__users.calculate_group_storage( user )
return dict(
storage_bytes = user.storage_bytes,
@ -1211,6 +1215,7 @@ class Notebooks( object ):
self.__database.execute( user.sql_remove_notebook( notebook_id ), commit = False )
user = self.__users.update_storage( user_id, commit = False )
self.__database.commit()
user.group_storage_bytes = self.__users.calculate_group_storage( user )
return dict( storage_bytes = user.storage_bytes )

View File

@ -510,6 +510,8 @@ class Users( object ):
if not user or not anonymous:
raise Access_error()
user.group_storage_bytes = self.calculate_group_storage( user )
# in addition to this user's own notebooks, add to that list the anonymous user's notebooks
login_url = None
anon_notebooks = self.__database.select_many( Notebook, anonymous.sql_load_notebooks( undeleted_only = True ) )
@ -557,7 +559,7 @@ class Users( object ):
@rtype: int
@return: total bytes used for group storage
"""
return self.__database.select_one( int, user.sql_calculate_group_storage() )
return sum( self.__database.select_one( tuple, user.sql_calculate_group_storage() ), 0 )
def update_storage( self, user_id, commit = True ):
"""
@ -575,7 +577,6 @@ class Users( object ):
if user:
user.storage_bytes = self.calculate_storage( user )
self.__database.save( user, commit )
user.group_storage_bytes = self.calculate_group_storage( user )
return user

View File

@ -331,22 +331,22 @@ class User( Persistent ):
"""
return \
"""
select
coalesce( sum( storage_bytes ), 0 )
from
user_group, luminotes_user_current
where
group_id in (
select
group_id
from
user_group
where
user_id = %s
) and
user_id = luminotes_user_current.id
group by
user_id, storage_bytes;
select coalesce( sum( storage_bytes ), 0 ) from (
select
distinct user_id, storage_bytes
from
user_group, luminotes_user_current
where
group_id in (
select
group_id
from
user_group
where
user_id = %s
) and
user_id = luminotes_user_current.id
) as sub;
""" % quote( self.object_id )
def to_dict( self ):