witten
/
luminotes
Archived
1
0
Fork 0

Returning storage usage to the client whenever usage changes.

This commit is contained in:
Dan Helfman 2007-09-20 22:16:52 +00:00
parent 4d736d4821
commit ae329d771a
2 changed files with 54 additions and 13 deletions

View File

@ -303,6 +303,7 @@ class Notebooks( object ):
@return: {
'new_revision': new revision of saved note, or None if nothing was saved,
'previous_revision': revision immediately before new_revision, or None if the note is new
'storage_bytes': current storage usage by user,
}
@raise Access_error: the current user doesn't have access to the given notebook
@raise Validation_error: one of the arguments is invalid
@ -371,10 +372,13 @@ class Notebooks( object ):
self.__users.update_storage( user_id, self.__scheduler.thread )
user = ( yield Scheduler.SLEEP )
self.__database.save( user )
else:
user = None
yield dict(
new_revision = new_revision,
previous_revision = previous_revision,
storage_bytes = user and user.storage_bytes or 0,
)
@expose( view = Json )
@ -399,7 +403,7 @@ class Notebooks( object ):
@type user_id: unicode or NoneType
@param user_id: id of current logged-in user (if any), determined by @grab_user_id
@rtype: json dict
@return: {}
@return: { 'storage_bytes': current storage usage by user }
@raise Access_error: the current user doesn't have access to the given notebook
@raise Validation_error: one of the arguments is invalid
"""
@ -424,7 +428,9 @@ class Notebooks( object ):
user = ( yield Scheduler.SLEEP )
self.__database.save( user )
yield dict()
yield dict( storage_bytes = user.storage_bytes )
else:
yield dict( storage_bytes = 0 )
@expose( view = Json )
@wait_for_update
@ -448,7 +454,7 @@ class Notebooks( object ):
@type user_id: unicode or NoneType
@param user_id: id of current logged-in user (if any), determined by @grab_user_id
@rtype: json dict
@return: {}
@return: { 'storage_bytes': current storage usage by user }
@raise Access_error: the current user doesn't have access to the given notebook
@raise Validation_error: one of the arguments is invalid
"""
@ -473,7 +479,9 @@ class Notebooks( object ):
user = ( yield Scheduler.SLEEP )
self.__database.save( user )
yield dict()
yield dict( storage_bytes = user.storage_bytes )
else:
yield dict( storage_bytes = 0 )
@expose( view = Json )
@wait_for_update
@ -498,7 +506,7 @@ class Notebooks( object ):
@type user_id: unicode or NoneType
@param user_id: id of current logged-in user (if any), determined by @grab_user_id
@rtype: json dict
@return: {}
@return: { 'storage_bytes': current storage usage by user }
@raise Access_error: the current user doesn't have access to the given notebook
@raise Validation_error: one of the arguments is invalid
"""
@ -529,7 +537,9 @@ class Notebooks( object ):
user = ( yield Scheduler.SLEEP )
self.__database.save( user )
yield dict()
yield dict( storage_bytes = user.storage_bytes )
else:
yield dict( storage_bytes = 0 )
@expose( view = Json )
@wait_for_update
@ -553,7 +563,7 @@ class Notebooks( object ):
@type user_id: unicode or NoneType
@param user_id: id of current logged-in user (if any), determined by @grab_user_id
@rtype: json dict
@return: {}
@return: { 'storage_bytes': current storage usage by user }
@raise Access_error: the current user doesn't have access to the given notebook
@raise Validation_error: one of the arguments is invalid
"""
@ -573,7 +583,7 @@ class Notebooks( object ):
if note and notebook.trash:
# if the note isn't deleted, and it's already in this notebook, just return
if note.deleted_from is None and notebook.lookup_note( note.object_id ):
yield dict()
yield dict( storage_bytes = 0 )
return
# if the note was deleted from a different notebook than the notebook given, raise
@ -592,7 +602,9 @@ class Notebooks( object ):
user = ( yield Scheduler.SLEEP )
self.__database.save( user )
yield dict()
yield dict( storage_bytes = user.storage_bytes )
else:
yield dict( storage_bytes = 0 )
@expose( view = Json )
@wait_for_update
@ -614,7 +626,7 @@ class Notebooks( object ):
@type user_id: unicode or NoneType
@param user_id: id of current logged-in user (if any), determined by @grab_user_id
@rtype: json dict
@return: {}
@return: { 'storage_bytes': current storage usage by user }
@raise Access_error: the current user doesn't have access to the given notebook
@raise Validation_error: one of the arguments is invalid
"""
@ -642,7 +654,9 @@ class Notebooks( object ):
user = ( yield Scheduler.SLEEP )
self.__database.save( user )
yield dict()
yield dict(
storage_bytes = user.storage_bytes,
)
@expose( view = Json )
@strongly_expire

View File

@ -346,6 +346,7 @@ class Test_notebooks( Test_controller ):
assert result[ "new_revision" ] and result[ "new_revision" ] != previous_revision
assert result[ "previous_revision" ] == previous_revision
assert self.user.storage_bytes > 0
assert result[ "storage_bytes" ] == self.user.storage_bytes
# make sure the old title can no longer be loaded
result = self.http_post( "/notebooks/load_note_by_title/", dict(
@ -416,6 +417,7 @@ class Test_notebooks( Test_controller ):
assert result[ "new_revision" ] and result[ "new_revision" ] != previous_revision
assert result[ "previous_revision" ] == previous_revision
assert self.user.storage_bytes > 0
assert result[ "storage_bytes" ] == self.user.storage_bytes
# make sure the old title can no longer be loaded
result = self.http_post( "/notebooks/load_note_by_title/", dict(
@ -483,6 +485,7 @@ class Test_notebooks( Test_controller ):
assert result[ "new_revision" ] == None
assert result[ "previous_revision" ] == previous_revision
assert self.user.storage_bytes == previous_storage_bytes
assert result[ "storage_bytes" ] == 0
result = self.http_post( "/notebooks/load_note_by_title/", dict(
notebook_id = self.notebook.object_id,
@ -530,6 +533,7 @@ class Test_notebooks( Test_controller ):
assert result[ "new_revision" ] == None
assert result[ "previous_revision" ] == previous_revision
assert self.user.storage_bytes == previous_storage_bytes
assert result[ "storage_bytes" ] == 0
result = self.http_post( "/notebooks/load_note_by_title/", dict(
notebook_id = self.notebook.object_id,
@ -581,6 +585,7 @@ class Test_notebooks( Test_controller ):
assert result[ "new_revision" ] == None
assert result[ "previous_revision" ] == previous_revision
assert self.user.storage_bytes > 0
assert result[ "storage_bytes" ] == self.user.storage_bytes
result = self.http_post( "/notebooks/load_note_by_title/", dict(
notebook_id = self.notebook.object_id,
@ -631,6 +636,7 @@ class Test_notebooks( Test_controller ):
assert result[ "new_revision" ] not in ( first_revision, second_revision )
assert result[ "previous_revision" ] == second_revision
assert self.user.storage_bytes > 0
assert result[ "storage_bytes" ] == self.user.storage_bytes
# make sure the first title can no longer be loaded
result = self.http_post( "/notebooks/load_note_by_title/", dict(
@ -694,6 +700,7 @@ class Test_notebooks( Test_controller ):
assert result[ "new_revision" ] and result[ "new_revision" ] != previous_revision
assert result[ "previous_revision" ] == None
assert self.user.storage_bytes > 0
assert result[ "storage_bytes" ] == self.user.storage_bytes
# make sure the new title is now loadable
result = self.http_post( "/notebooks/load_note_by_title/", dict(
@ -737,6 +744,7 @@ class Test_notebooks( Test_controller ):
assert result[ "new_revision" ] and result[ "new_revision" ] != previous_revision
assert result[ "previous_revision" ] == None
assert self.user.storage_bytes > 0
assert result[ "storage_bytes" ] == self.user.storage_bytes
# make sure the new title is now loadable
result = self.http_post( "/notebooks/load_note_by_title/", dict(
@ -771,6 +779,7 @@ class Test_notebooks( Test_controller ):
assert result[ "new_revision" ] and result[ "new_revision" ] != previous_revision
assert result[ "previous_revision" ] == None
assert self.user.storage_bytes > 0
assert result[ "storage_bytes" ] == self.user.storage_bytes
# make sure the new title is now loadable
result = self.http_post( "/notebooks/load_note_by_title/", dict(
@ -792,6 +801,8 @@ class Test_notebooks( Test_controller ):
note_id = self.note2.object_id,
), session_id = self.session_id )
assert result[ "storage_bytes" ] == self.user.storage_bytes
# test that the added note shows up in notebook.startup_notes
result = self.http_get(
"/notebooks/contents?notebook_id=%s" % self.notebook.object_id,
@ -862,6 +873,8 @@ class Test_notebooks( Test_controller ):
note_id = self.note.object_id,
), session_id = self.session_id )
assert result[ "storage_bytes" ] == self.user.storage_bytes
# test that the remove note no longer shows up in notebook.startup_notes
result = self.http_get(
"/notebooks/contents?notebook_id=%s" % self.notebook.object_id,
@ -910,6 +923,8 @@ class Test_notebooks( Test_controller ):
note_id = self.unknown_note_id,
), session_id = self.session_id )
assert result[ "storage_bytes" ] == self.user.storage_bytes
# test that notebook.startup_notes hasn't changed
result = self.http_get(
"/notebooks/contents?notebook_id=%s" % self.notebook.object_id,
@ -939,6 +954,8 @@ class Test_notebooks( Test_controller ):
note_id = self.note.object_id,
), session_id = self.session_id )
assert result[ "storage_bytes" ] == self.user.storage_bytes
# test that the deleted note is actually deleted
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
@ -967,12 +984,16 @@ class Test_notebooks( Test_controller ):
note_id = self.note.object_id,
), session_id = self.session_id )
assert result[ "storage_bytes" ] == self.user.storage_bytes
# then, delete the note from the trash
result = self.http_post( "/notebooks/delete_note/", dict(
notebook_id = self.notebook.trash.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
assert result[ "storage_bytes" ] == self.user.storage_bytes
# test that the deleted note is actually deleted from the trash
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.trash.object_id,
@ -1029,15 +1050,17 @@ class Test_notebooks( Test_controller ):
# first delete the note
self.http_post( "/notebooks/delete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.unknown_note_id,
note_id = self.note.object_id,
), session_id = self.session_id )
# then undelete it
self.http_post( "/notebooks/undelete_note/", dict(
result = self.http_post( "/notebooks/undelete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
assert result[ "storage_bytes" ] == self.user.storage_bytes
# test that the undeleted note is actually undeleted
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
@ -1190,6 +1213,8 @@ class Test_notebooks( Test_controller ):
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert result[ "storage_bytes" ] == self.user.storage_bytes
# test that all notes are actually deleted
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
@ -1239,6 +1264,8 @@ class Test_notebooks( Test_controller ):
notebook_id = self.notebook.trash.object_id,
), session_id = self.session_id )
assert result[ "storage_bytes" ] == self.user.storage_bytes
# test that all notes are actually deleted from the trash
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.trash.object_id,