Commit 732a29a0ff765afe79f92890ec6eb755e464456a
1 parent
eb106f08
Exists in
web_steps_improvements
and in
8 other branches
refactor people blocks template to avoid load all people data
Showing
4 changed files
with
166 additions
and
2 deletions
Show diff stats
plugins/people_block/test/unit/friends_block_test.rb
| ... | ... | @@ -153,4 +153,59 @@ class FriendsBlockViewTest < ActionView::TestCase |
| 153 | 153 | |
| 154 | 154 | assert_tag_in_string render_block_footer(block), tag: 'a', attributes: {class: 'view-all', href: '/profile/mytestperson/friends' } |
| 155 | 155 | end |
| 156 | + | |
| 157 | + FACTOR = 1.8 | |
| 158 | + | |
| 159 | + # Testing blog page display. It should not present a linear increase in time | |
| 160 | + # needed to display a blog page with the increase in number of posts. | |
| 161 | + # | |
| 162 | + # GOOD BAD | |
| 163 | + # | |
| 164 | + # ^ ^ / | |
| 165 | + # | | / | |
| 166 | + # | _____ | / | |
| 167 | + # | / | / | |
| 168 | + # | / | / | |
| 169 | + # |/ |/ | |
| 170 | + # +---------> +---------> | |
| 171 | + # 0 50 100 0 50 100 | |
| 172 | + # | |
| 173 | + should 'not have a linear increase in time to display friends block' do | |
| 174 | + owner = fast_create(Person) | |
| 175 | + owner.boxes<< Box.new | |
| 176 | + block = FriendsBlock.create!(:box => owner.boxes.first) | |
| 177 | + | |
| 178 | + ActionView::Base.any_instance.stubs(:profile_image_link).returns('some name') | |
| 179 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
| 180 | + | |
| 181 | + # no people | |
| 182 | + block.reload | |
| 183 | + time0 = (Benchmark.measure { 10.times { render_block_content(block) } }) | |
| 184 | + | |
| 185 | + # first 50 | |
| 186 | + 1.upto(50).map do |n| | |
| 187 | + p = create_user("user #{n}").person | |
| 188 | + owner.add_friend(p) | |
| 189 | + end | |
| 190 | + block.reload | |
| 191 | + time1 = (Benchmark.measure { 10.times { render_block_content(block) } }) | |
| 192 | + | |
| 193 | + # another 50 | |
| 194 | + 1.upto(50).map do |n| | |
| 195 | + p = create_user("user #{n}").person | |
| 196 | + owner.add_friend(p) | |
| 197 | + end | |
| 198 | + block.reload | |
| 199 | + time2 = (Benchmark.measure { 10.times { render_block_content(block) } }) | |
| 200 | + | |
| 201 | + # should not scale linearly, i.e. the inclination of the first segment must | |
| 202 | + # be a lot higher than the one of the segment segment. To compensate for | |
| 203 | + # small variations due to hardware and/or execution environment, we are | |
| 204 | + # satisfied if the the inclination of the first segment is at least twice | |
| 205 | + # the inclination of the second segment. | |
| 206 | + a1 = (time1.total - time0.total)/50.0 | |
| 207 | + a2 = (time2.total - time1.total)/50.0 | |
| 208 | + assert a1 > a2*FACTOR, "#{a1} should be larger than #{a2} by at least a factor of #{FACTOR}" | |
| 209 | + end | |
| 210 | + | |
| 156 | 211 | end | ... | ... |
plugins/people_block/test/unit/members_block_test.rb
| ... | ... | @@ -306,4 +306,60 @@ class MembersBlockViewTest < ActionView::TestCase |
| 306 | 306 | assert_select '[href=/profile/mytestuser/members#admins-tab]' |
| 307 | 307 | end |
| 308 | 308 | end |
| 309 | + | |
| 310 | + FACTOR = 1.8 | |
| 311 | + | |
| 312 | + # Testing blog page display. It should not present a linear increase in time | |
| 313 | + # needed to display a blog page with the increase in number of posts. | |
| 314 | + # | |
| 315 | + # GOOD BAD | |
| 316 | + # | |
| 317 | + # ^ ^ / | |
| 318 | + # | | / | |
| 319 | + # | _____ | / | |
| 320 | + # | / | / | |
| 321 | + # | / | / | |
| 322 | + # |/ |/ | |
| 323 | + # +---------> +---------> | |
| 324 | + # 0 50 100 0 50 100 | |
| 325 | + # | |
| 326 | + should 'not have a linear increase in time to display members block' do | |
| 327 | + owner = fast_create(Community) | |
| 328 | + owner.boxes<< Box.new | |
| 329 | + block = MembersBlock.create!(:box => owner.boxes.first) | |
| 330 | + | |
| 331 | + ActionView::Base.any_instance.stubs(:profile_image_link).returns('some name') | |
| 332 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
| 333 | + | |
| 334 | + # no people | |
| 335 | + block.reload | |
| 336 | + time0 = (Benchmark.measure { 10.times { render_block_content(block) } }) | |
| 337 | + | |
| 338 | + 1.upto(50).map do |n| | |
| 339 | + p = create_user("user #{n}").person | |
| 340 | + owner.add_member(p) | |
| 341 | + end | |
| 342 | + | |
| 343 | + # first 50 | |
| 344 | + block.reload | |
| 345 | + time1 = (Benchmark.measure { 10.times { render_block_content(block) } }) | |
| 346 | + | |
| 347 | + 1.upto(50).map do |n| | |
| 348 | + p = create_user("user 1#{n}").person | |
| 349 | + owner.add_member(p) | |
| 350 | + end | |
| 351 | + block.reload | |
| 352 | + # another 50 | |
| 353 | + time2 = (Benchmark.measure { 10.times { render_block_content(block) } }) | |
| 354 | + | |
| 355 | + # should not scale linearly, i.e. the inclination of the first segment must | |
| 356 | + # be a lot higher than the one of the segment segment. To compensate for | |
| 357 | + # small variations due to hardware and/or execution environment, we are | |
| 358 | + # satisfied if the the inclination of the first segment is at least twice | |
| 359 | + # the inclination of the second segment. | |
| 360 | + a1 = (time1.total - time0.total)/50.0 | |
| 361 | + a2 = (time2.total - time1.total)/50.0 | |
| 362 | + assert a1 > a2*FACTOR, "#{a1} should be larger than #{a2} by at least a factor of #{FACTOR}" | |
| 363 | + end | |
| 364 | + | |
| 309 | 365 | end | ... | ... |
plugins/people_block/test/unit/people_block_test.rb
| ... | ... | @@ -145,4 +145,57 @@ class PeopleBlockViewTest < ActionView::TestCase |
| 145 | 145 | assert_select '[href=/search/people]' |
| 146 | 146 | end |
| 147 | 147 | end |
| 148 | + | |
| 149 | + FACTOR = 1.8 | |
| 150 | + | |
| 151 | + # Testing blog page display. It should not present a linear increase in time | |
| 152 | + # needed to display a blog page with the increase in number of posts. | |
| 153 | + # | |
| 154 | + # GOOD BAD | |
| 155 | + # | |
| 156 | + # ^ ^ / | |
| 157 | + # | | / | |
| 158 | + # | _____ | / | |
| 159 | + # | / | / | |
| 160 | + # | / | / | |
| 161 | + # |/ |/ | |
| 162 | + # +---------> +---------> | |
| 163 | + # 0 50 100 0 50 100 | |
| 164 | + # | |
| 165 | + should 'not have a linear increase in time to display people block' do | |
| 166 | + owner = fast_create(Environment) | |
| 167 | + owner.boxes<< Box.new | |
| 168 | + block = PeopleBlock.create!(:box => owner.boxes.first) | |
| 169 | + | |
| 170 | + ActionView::Base.any_instance.stubs(:profile_image_link).returns('some name') | |
| 171 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
| 172 | + | |
| 173 | + # no people | |
| 174 | + block.reload | |
| 175 | + time0 = (Benchmark.measure { 10.times { render_block_content(block) } }) | |
| 176 | + | |
| 177 | + # first 500 | |
| 178 | + 1.upto(50).map do | |
| 179 | + fast_create(Person, :environment_id => owner.id) | |
| 180 | + end | |
| 181 | + block.reload | |
| 182 | + time1 = (Benchmark.measure { 10.times { render_block_content(block) } }) | |
| 183 | + | |
| 184 | + # another 50 | |
| 185 | + 1.upto(50).map do | |
| 186 | + fast_create(Person, :environment_id => owner.id) | |
| 187 | + end | |
| 188 | + block.reload | |
| 189 | + time2 = (Benchmark.measure { 10.times { render_block_content(block) } }) | |
| 190 | + | |
| 191 | + # should not scale linearly, i.e. the inclination of the first segment must | |
| 192 | + # be a lot higher than the one of the segment segment. To compensate for | |
| 193 | + # small variations due to hardware and/or execution environment, we are | |
| 194 | + # satisfied if the the inclination of the first segment is at least twice | |
| 195 | + # the inclination of the second segment. | |
| 196 | + a1 = (time1.total - time0.total)/50.0 | |
| 197 | + a2 = (time2.total - time1.total)/50.0 | |
| 198 | + assert a1 > a2*FACTOR, "#{a1} should be larger than #{a2} by at least a factor of #{FACTOR}" | |
| 199 | + end | |
| 200 | + | |
| 148 | 201 | end | ... | ... |
plugins/people_block/views/blocks/people_base.html.erb
| ... | ... | @@ -3,9 +3,9 @@ |
| 3 | 3 | <%= block_title(block.view_title) %> |
| 4 | 4 | |
| 5 | 5 | <div> |
| 6 | - <% unless block.profiles.count == 0 %> | |
| 6 | + <% unless block.profile_count == 0 %> | |
| 7 | 7 | <ul> |
| 8 | - <%= profiles_images_list(block.profiles) %> | |
| 8 | + <%= profiles_images_list(block.profile_list) %> | |
| 9 | 9 | |
| 10 | 10 | <% unless block.name.blank? || block.address.blank? %> |
| 11 | 11 | <div class="common-profile-list-block"> | ... | ... |