From 32e184c5531cf451012cb59ebd86d03cc56c51a5 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Thu, 29 Jan 2009 15:30:10 -0800 Subject: [PATCH] No longer returning a list of all anonymous-readable notebooks along with the user's other notebooks. This prevents a huge list of notebooks (including forum discussion threads!) from being sent on each wiki page load. --- controller/Users.py | 11 ++--- controller/test/Test_forums.py | 4 +- controller/test/Test_root.py | 6 +-- controller/test/Test_users.py | 77 +++++++--------------------------- 4 files changed, 24 insertions(+), 74 deletions(-) diff --git a/controller/Users.py b/controller/Users.py index 88a287d..67980f8 100644 --- a/controller/Users.py +++ b/controller/Users.py @@ -632,26 +632,21 @@ class Users( object ): 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 ) ) if user_id and user_id != anonymous.object_id: notebooks = self.__database.select_many( Notebook, user.sql_load_notebooks( parents_only = True ) ) groups = self.__database.select_many( Group, user.sql_load_groups() ) # if the user is not logged in, return a login URL else: - notebooks = [] + notebooks = self.__database.select_many( Notebook, anonymous.sql_load_notebooks( undeleted_only = True ) ) groups = [] - if len( anon_notebooks ) > 0 and anon_notebooks[ 0 ]: - main_notebook = anon_notebooks[ 0 ] + if len( notebooks ) > 0 and notebooks[ 0 ]: + main_notebook = notebooks[ 0 ] login_note = self.__database.select_one( Note, main_notebook.sql_load_note_by_title( u"login" ) ) if login_note: login_url = "%s/notebooks/%s?note_id=%s" % ( self.__https_url, main_notebook.object_id, login_note.object_id ) - notebooks += anon_notebooks - for notebook in notebooks: notebook.tags = \ self.__database.select_many( Tag, notebook.sql_load_tags( user_id ) ) + \ diff --git a/controller/test/Test_forums.py b/controller/test/Test_forums.py index 041a39a..8c54b07 100644 --- a/controller/test/Test_forums.py +++ b/controller/test/Test_forums.py @@ -108,7 +108,7 @@ class Test_forums( Test_controller ): assert result assert result.get( u"redirect" ) is None assert result[ u"user" ].username == self.user.username - assert len( result[ u"notebooks" ] ) == 5 + assert len( result[ u"notebooks" ] ) == 1 assert result[ u"first_notebook" ].object_id == self.notebook.object_id assert result[ u"login_url" ] == None assert result[ u"logout_url" ] == u"https://luminotes.com/users/logout" @@ -325,7 +325,7 @@ class Test_forums( Test_controller ): ) assert result.get( u"user" ).object_id == self.user.object_id - assert len( result.get( u"notebooks" ) ) == 5 + assert len( result.get( u"notebooks" ) ) == 1 assert result.get( u"notebooks" )[ 0 ].object_id == self.notebook.object_id assert result.get( u"login_url" ) is None assert result.get( u"logout_url" ) diff --git a/controller/test/Test_root.py b/controller/test/Test_root.py index 4241c6d..9868064 100644 --- a/controller/test/Test_root.py +++ b/controller/test/Test_root.py @@ -129,7 +129,7 @@ class Test_root( Test_controller ): assert result assert result.get( u"redirect" ) is None assert result[ u"user" ].username == self.user.username - assert len( result[ u"notebooks" ] ) == 5 + assert len( result[ u"notebooks" ] ) == 1 assert result[ u"first_notebook" ].object_id == self.notebook.object_id assert result[ u"login_url" ] == None assert result[ u"logout_url" ] == u"https://luminotes.com/users/logout" @@ -222,7 +222,7 @@ class Test_root( Test_controller ): assert result assert result.get( u"redirect" ) is None assert result[ u"user" ].username == self.user.username - assert len( result[ u"notebooks" ] ) == 5 + assert len( result[ u"notebooks" ] ) == 1 assert result[ u"first_notebook" ].object_id == self.notebook.object_id assert result[ u"login_url" ] == None assert result[ u"logout_url" ] == u"https://luminotes.com/users/logout" @@ -420,7 +420,7 @@ class Test_root( Test_controller ): result = self.http_get( "/pricing", session_id = self.session_id ) assert result[ u"user" ].username == self.username - assert len( result[ u"notebooks" ] ) == 5 + assert len( result[ u"notebooks" ] ) == 1 notebook = [ notebook for notebook in result[ u"notebooks" ] if notebook.object_id == self.notebook.object_id ][ 0 ] assert notebook.object_id == self.notebook.object_id assert notebook.name == self.notebook.name diff --git a/controller/test/Test_users.py b/controller/test/Test_users.py index 9496390..a20fd40 100644 --- a/controller/test/Test_users.py +++ b/controller/test/Test_users.py @@ -183,6 +183,7 @@ class Test_users( Test_controller ): assert result[ u"user" ].email_address == self.new_email_address notebooks = result[ u"notebooks" ] + assert len( notebooks ) == 1 notebook = notebooks[ 0 ] assert notebook.object_id == new_notebook_id assert notebook.revision @@ -192,15 +193,6 @@ class Test_users( Test_controller ): assert notebook.owner == True assert notebook.rank == 0 - notebook = notebooks[ 1 ] - assert notebook.object_id == self.anon_notebook.object_id - assert notebook.revision == self.anon_notebook.revision - assert notebook.name == self.anon_notebook.name - assert notebook.trash_id == None - assert notebook.read_write == Notebook.READ_ONLY - assert notebook.owner == False - assert notebook.rank == None - assert result.get( u"login_url" ) is None assert result[ u"logout_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ] + u"/users/logout" @@ -264,14 +256,6 @@ class Test_users( Test_controller ): assert notebook.owner == False assert notebook.rank == 1 - notebook = notebooks.get( self.anon_notebook.object_id ) - assert notebook.revision == self.anon_notebook.revision - assert notebook.name == self.anon_notebook.name - assert notebook.trash_id == None - assert notebook.read_write == Notebook.READ_ONLY - assert notebook.owner == False - assert notebook.rank == None - assert result.get( u"login_url" ) is None assert result[ u"logout_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ] + u"/users/logout" @@ -303,6 +287,7 @@ class Test_users( Test_controller ): assert result[ u"user" ].email_address == self.new_email_address notebooks = result[ u"notebooks" ] + assert len( notebooks ) == 1 notebook = notebooks[ 0 ] assert notebook.object_id assert notebook.revision @@ -312,15 +297,6 @@ class Test_users( Test_controller ): assert notebook.owner == True assert notebook.rank == 0 - notebook = notebooks[ 1 ] - assert notebook.object_id == self.anon_notebook.object_id - assert notebook.revision == self.anon_notebook.revision - assert notebook.name == self.anon_notebook.name - assert notebook.trash_id == None - assert notebook.read_write == Notebook.READ_ONLY - assert notebook.owner == False - assert notebook.rank == None - assert result.get( u"login_url" ) is None assert result[ u"logout_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ] + u"/users/logout" @@ -615,7 +591,7 @@ class Test_users( Test_controller ): assert result[ u"user" ].email_address is None notebooks = result[ u"notebooks" ] - assert len( notebooks ) == 2 + assert len( notebooks ) == 1 notebook = notebooks[ 0 ] assert notebook.object_id == new_notebook_id @@ -626,15 +602,6 @@ class Test_users( Test_controller ): assert notebook.owner == True assert notebook.rank == 0 - notebook = notebooks[ 1 ] - assert notebook.object_id == self.anon_notebook.object_id - assert notebook.revision == self.anon_notebook.revision - assert notebook.name == self.anon_notebook.name - assert notebook.trash_id == None - assert notebook.read_write == Notebook.READ_ONLY - assert notebook.owner == False - assert notebook.rank == None - assert result.get( u"login_url" ) is None assert result[ u"logout_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ] + u"/users/logout" @@ -711,7 +678,7 @@ class Test_users( Test_controller ): assert result[ u"user" ] assert result[ u"user" ].object_id == self.user.object_id assert result[ u"user" ].username == self.user.username - assert len( result[ u"notebooks" ] ) == 3 + assert len( result[ u"notebooks" ] ) == 2 assert result[ u"notebooks" ][ 0 ].object_id == self.notebooks[ 0 ].object_id assert result[ u"notebooks" ][ 0 ].name == self.notebooks[ 0 ].name assert result[ u"notebooks" ][ 0 ].read_write == Notebook.READ_WRITE @@ -724,12 +691,6 @@ class Test_users( Test_controller ): assert result[ u"notebooks" ][ 1 ].owner == True assert result[ u"notebooks" ][ 1 ].rank == 1 assert result[ u"notebooks" ][ 1 ].tags == [] - assert result[ u"notebooks" ][ 2 ].object_id == self.anon_notebook.object_id - assert result[ u"notebooks" ][ 2 ].name == self.anon_notebook.name - assert result[ u"notebooks" ][ 2 ].read_write == Notebook.READ_ONLY - assert result[ u"notebooks" ][ 2 ].owner == False - assert result[ u"notebooks" ][ 2 ].rank == None - assert result[ u"notebooks" ][ 2 ].tags == [] assert result[ u"login_url" ] is None assert result[ u"logout_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ] + u"/users/logout" @@ -779,7 +740,7 @@ class Test_users( Test_controller ): assert result[ u"user" ] assert result[ u"user" ].object_id == self.user.object_id assert result[ u"user" ].username == self.user.username - assert len( result[ u"notebooks" ] ) == 3 + assert len( result[ u"notebooks" ] ) == 2 assert result[ u"notebooks" ][ 0 ].object_id == self.notebooks[ 0 ].object_id assert result[ u"notebooks" ][ 0 ].name == self.notebooks[ 0 ].name assert result[ u"notebooks" ][ 0 ].read_write == Notebook.READ_WRITE @@ -806,12 +767,6 @@ class Test_users( Test_controller ): assert result[ u"notebooks" ][ 1 ].owner == True assert result[ u"notebooks" ][ 1 ].rank == 1 assert result[ u"notebooks" ][ 1 ].tags == [] - assert result[ u"notebooks" ][ 2 ].object_id == self.anon_notebook.object_id - assert result[ u"notebooks" ][ 2 ].name == self.anon_notebook.name - assert result[ u"notebooks" ][ 2 ].read_write == Notebook.READ_ONLY - assert result[ u"notebooks" ][ 2 ].owner == False - assert result[ u"notebooks" ][ 2 ].rank == None - assert result[ u"notebooks" ][ 2 ].tags == [] assert result[ u"login_url" ] is None assert result[ u"logout_url" ] == self.settings[ u"global" ][ u"luminotes.https_url" ] + u"/users/logout" @@ -4813,7 +4768,7 @@ class Test_users( Test_controller ): ), session_id = self.session_id ) assert result[ u"user" ].username == self.user.username - assert len( result[ u"notebooks" ] ) == 3 + assert len( result[ u"notebooks" ] ) == 2 notebook = [ notebook for notebook in result[ u"notebooks" ] if notebook.object_id == self.notebooks[ 0 ].object_id ][ 0 ] assert notebook.object_id == self.notebooks[ 0 ].object_id assert notebook.name == self.notebooks[ 0 ].name @@ -4854,7 +4809,7 @@ class Test_users( Test_controller ): assert result[ u"user" ].username == self.user.username assert result.get( u"conversion" ) == None - assert len( result[ u"notebooks" ] ) == 3 + assert len( result[ u"notebooks" ] ) == 2 notebook = [ notebook for notebook in result[ u"notebooks" ] if notebook.object_id == self.notebooks[ 0 ].object_id ][ 0 ] assert notebook.object_id == self.notebooks[ 0 ].object_id assert notebook.name == self.notebooks[ 0 ].name @@ -4933,7 +4888,7 @@ class Test_users( Test_controller ): assert result[ u"user" ].username == self.user.username assert result.get( u"conversion" ) == None - assert len( result[ u"notebooks" ] ) == 3 + assert len( result[ u"notebooks" ] ) == 2 notebook = [ notebook for notebook in result[ u"notebooks" ] if notebook.object_id == self.notebooks[ 0 ].object_id ][ 0 ] assert notebook.object_id == self.notebooks[ 0 ].object_id assert notebook.name == self.notebooks[ 0 ].name @@ -4971,7 +4926,7 @@ class Test_users( Test_controller ): assert result[ u"user" ].username == self.user.username assert result.get( u"conversion" ) == None - assert len( result[ u"notebooks" ] ) == 3 + assert len( result[ u"notebooks" ] ) == 2 notebook = [ notebook for notebook in result[ u"notebooks" ] if notebook.object_id == self.notebooks[ 0 ].object_id ][ 0 ] assert notebook.object_id == self.notebooks[ 0 ].object_id assert notebook.name == self.notebooks[ 0 ].name @@ -5016,7 +4971,7 @@ class Test_users( Test_controller ): ), session_id = self.session_id ) assert result[ u"user" ].username == self.user.username - assert len( result[ u"notebooks" ] ) == 3 + assert len( result[ u"notebooks" ] ) == 2 notebook = [ notebook for notebook in result[ u"notebooks" ] if notebook.object_id == self.notebooks[ 0 ].object_id ][ 0 ] assert notebook.object_id == self.notebooks[ 0 ].object_id assert notebook.name == self.notebooks[ 0 ].name @@ -5145,7 +5100,7 @@ class Test_users( Test_controller ): # an unknown transaction id might just mean we're still waiting for the transaction to come in, # so expect a retry assert result[ u"user" ].username == self.user.username - assert len( result[ u"notebooks" ] ) == 3 + assert len( result[ u"notebooks" ] ) == 2 notebook = [ notebook for notebook in result[ u"notebooks" ] if notebook.object_id == self.notebooks[ 0 ].object_id ][ 0 ] assert notebook.object_id == self.notebooks[ 0 ].object_id assert notebook.name == self.notebooks[ 0 ].name @@ -5193,7 +5148,7 @@ class Test_users( Test_controller ): # an unknown transaction id might just mean we're still waiting for the transaction to come in, # so expect a retry assert result[ u"user" ].username == self.user.username - assert len( result[ u"notebooks" ] ) == 3 + assert len( result[ u"notebooks" ] ) == 2 notebook = [ notebook for notebook in result[ u"notebooks" ] if notebook.object_id == self.notebooks[ 0 ].object_id ][ 0 ] assert notebook.object_id == self.notebooks[ 0 ].object_id assert notebook.name == self.notebooks[ 0 ].name @@ -5241,7 +5196,7 @@ class Test_users( Test_controller ): # an unknown transaction id might just mean we're still waiting for the transaction to come in, # so expect a retry assert result[ u"user" ].username == self.user.username - assert len( result[ u"notebooks" ] ) == 3 + assert len( result[ u"notebooks" ] ) == 2 notebook = [ notebook for notebook in result[ u"notebooks" ] if notebook.object_id == self.notebooks[ 0 ].object_id ][ 0 ] assert notebook.object_id == self.notebooks[ 0 ].object_id assert notebook.name == self.notebooks[ 0 ].name @@ -5287,7 +5242,7 @@ class Test_users( Test_controller ): # an unknown transaction id might just mean we're still waiting for the transaction to come in, # so expect a retry assert result[ u"user" ].username == self.user.username - assert len( result[ u"notebooks" ] ) == 3 + assert len( result[ u"notebooks" ] ) == 2 notebook = [ notebook for notebook in result[ u"notebooks" ] if notebook.object_id == self.notebooks[ 0 ].object_id ][ 0 ] assert notebook.object_id == self.notebooks[ 0 ].object_id assert notebook.name == self.notebooks[ 0 ].name @@ -5336,7 +5291,7 @@ class Test_users( Test_controller ): # an unknown transaction id might just mean we're still waiting for the transaction to come in, # so expect a retry assert result[ u"user" ].username == self.user.username - assert len( result[ u"notebooks" ] ) == 3 + assert len( result[ u"notebooks" ] ) == 2 notebook = [ notebook for notebook in result[ u"notebooks" ] if notebook.object_id == self.notebooks[ 0 ].object_id ][ 0 ] assert notebook.object_id == self.notebooks[ 0 ].object_id assert notebook.name == self.notebooks[ 0 ].name @@ -5384,7 +5339,7 @@ class Test_users( Test_controller ): # an unknown transaction id might just mean we're still waiting for the transaction to come in, # so expect a retry assert result[ u"user" ].username == self.user.username - assert len( result[ u"notebooks" ] ) == 3 + assert len( result[ u"notebooks" ] ) == 2 notebook = [ notebook for notebook in result[ u"notebooks" ] if notebook.object_id == self.notebooks[ 0 ].object_id ][ 0 ] assert notebook.object_id == self.notebooks[ 0 ].object_id assert notebook.name == self.notebooks[ 0 ].name