Closed (fixed)
Project:
Views Lazy Load
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
13 Jul 2015 at 20:08 UTC
Updated:
2 Sep 2015 at 09:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
lucaschain commentedComment #2
benjy commentedI think we could remove the reference to Search API. I wrote it for a project which was using SAPI but really, this just prevents the view from executing the query.
Lets wrap this in a variable_get() at the very least so we can change it globally.
If this is truthy, can't we just return preg_match value and cast to bool?
Comment #3
lucaschain commentedHello
Seems great to me and I can do that
We can return and cast it to bool, yes
Although I don't know the Drupal contribution process so I'm a little lost here, do you have any material that I can read so I won't screw things up?
Comment #4
benjy commentedOK, welcome to contributing :) Here's some docs that might help: https://www.drupal.org/novice
Usually how the process goes from a high level:
1. Someone posts a patch - Status: Needs Review.
2. Others review the patch and leave feedback. Status: Needs Work:
3. Patches continue to be posted addressing feedback, status back to needs review.
4. Once reviewers are happy issue goes to Reviewed and Tested by the Community
5 Maintainer commits the patch, sets to Fixed.
I'd also checkout the Drupal Coding Standards. Specifically in your patch I noticed the lowercase true/false where as Drupal always uses TRUE/FALSE.
Comment #5
lucaschain commentedThanks for the contributing tips, in this patch I changed the webcrawlers list to a configurable variable in the admin page.
Also changed the true/false logic by casting the result from preg_match to bool.
Comment #6
lucaschain commentedComment #8
lucaschain commentedSorry, I created the previous patch using the wrong command, now the patch has been created the right way (using diff between branches).
Comment #9
lucaschain commentedComment #10
benjy commentedGreat, thanks for working on this. Few points to note in the review, mainly just look like copy and paste errors from the system module. Also, if you fancy trying, it would be great if we could add tests for this, not sure how easy it will be to set the user agency though in simpletest.
$user_agent should be in lower case.
The name of the variable should be prefixed with the module name. views_lazy_load_crawlers.
$crawlers should be wrapped in a preg_quote()?
Space after (bool)
These look like copy paste errors.
Same here.
This should be required, it can be handled by system settings form once we remove the serialized
Do we need to serialise this? It could just be a string for me?
Not actually sure if this needed at all?
Wrong callback.
Copy paste error, should just be the views_lazy_load.admin file
Comment #11
lucaschain commentedHello, I just fixed the path with these modifications:
1. All garbage code was removed. I used a system example and forgot to clean it all
2. I used preg_quote on the user input. I couldn't use it at the regex build moment because it would escape the pipes. To prevent slashes from accumulating, I used stripslashes when displaying the items on the textbox
3. Changed the default crawlers constant to a pipe-separated string
4. Coding conventions (space after cast and lowercase variables)
5. Removed the Config menu item (now it is just the module settings button)
6. Created a test forcing the $_SERVER['HTTP_USER_AGENT'] to simulate a webcrawler visit
Comment #13
lucaschain commentedDo you know any restriction on the Drupal.org tester? It seems like he does not allow me to set a $_SERVER variable. Do you know anything I can try to handle this?
--- EDIT ---
Is it a good idea submitting the changes without these tests and open another issue regarding to them? I'm still trying to set the user agent $_SERVER variable and nothing comes to my mind.
Thanks
Comment #14
lucaschain commentedHere is the patch without the tests if you want to apply
Comment #15
sothish commentedThanks @lucaschain, I have applied the patch and tested using FireFox UserAgent Switcher plugin( "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) "), the content is still loaded using AJAX.
Comment #16
lucaschain commentedHello @sothish
Thank you for testing.
I did the same and still can't reproduce this here, can you provide some more information?
Can you tell me what is in the variable views_lazy_load_webcrawlers ?
drush vget views_lazy_load_webcrawlersThank you very much :)
Comment #17
sothish commentedHi lucaschain,
drush vget views_lazy_load_webcrawlers
views_lazy_load_webcrawlers: "Googlebot|msnbot|Rambler|Yahoo|AbachoBOT|accoona|AcioRobot|APSeek|CocoCrawler|Dumbot|FAST\-WebCrawler|GeonaBot|Gigabot|Lycos|MSRBOT|Scooter|AltaVista|IDBot|eStyle|Scrubby"
Please find a screenshot of what I saw, I thought the view should not be loaded through AJAX. may be my understanding was wrong.
Comment #18
sothish commentedComment #19
sothish commented@lucaschain, Sorry I uploaded wrong file, please find the one
Comment #20
lucaschain commented@sothish You are right, the lazy loading should be disabled when your user agent contains the word "Googlebot".
I saw your correct screenshot and you are testing right, but I still can't reproduce that.
Can you make sure that the User-Agent request header is being sent correctly?
Also, would you send me the exported code of your view?
Again. thank you very much for your help by testing this
----EDIT----
One more thing: I saw that you var_dumped the $pattern string. Can you var_dump the $user_agent string and the (bool) preg_match($pattern, $user_agent) result?
like this:
Comment #21
sothish commentedHi @lucaschain , Please find the details
string(173) "/Googlebot|msnbot|Rambler|Yahoo|AbachoBOT|accoona|AcioRobot|APSeek|CocoCrawler|Dumbot|FAST\-WebCrawler|GeonaBot|Gigabot|Lycos|MSRBOT|Scooter|AltaVista|IDBot|eStyle|Scrubby/i" string(72) "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" bool(true)
Also, FYI - I'm using Views Module - 7.x-3.11
$view = new view();
$view->name = 'all_articles_lazy_load';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'All Articles lazy load';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'All Articles lazy load';
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '9';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Field: Content: Image */
$handler->display->display_options['fields']['field_image']['id'] = 'field_image';
$handler->display->display_options['fields']['field_image']['table'] = 'field_data_field_image';
$handler->display->display_options['fields']['field_image']['field'] = 'field_image';
$handler->display->display_options['fields']['field_image']['label'] = '';
$handler->display->display_options['fields']['field_image']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_image']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_image']['settings'] = array(
'image_style' => '',
'image_link' => '',
);
/* Field: Content: Body */
$handler->display->display_options['fields']['body']['id'] = 'body';
$handler->display->display_options['fields']['body']['table'] = 'field_data_body';
$handler->display->display_options['fields']['body']['field'] = 'body';
$handler->display->display_options['fields']['body']['label'] = '';
$handler->display->display_options['fields']['body']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['body']['type'] = 'text_summary_or_trimmed';
$handler->display->display_options['fields']['body']['settings'] = array(
'trim_length' => '600',
);
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
'article' => 'article',
);
$handler->display->display_options['views_lazy_load_enabled'] = 1;
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['views_lazy_load_enabled'] = 1;
$handler->display->display_options['path'] = 'all-articles-lazy-load';
Comment #22
lucaschain commentedHello @sothish
Thanks for the info. I was able to test everything now.
I noticed one thing: When you have a pager on the view, it seems to lazy load but it does not, it's just the normal pager behavior. Here is what i've done:
1. I commented out my condition and the code inside it, like this:
2. Even with that commented out, the lazy effect still appeared when I reloaded the page. That's when I noticed the pager
3. When I removed the pager to continue my tests, everything went back to normal.
When I finished my tests, I came to the conclusion that the pager will always have this behavior (when configured).
Can you repeat your test (without commenting the lines) for me without the paging system so it will be a little more inside our context?
Comment #23
benjy commentedThere is no lazy loading with the pager, when views_lazy_load is enabled we force AJAX to TRUE and therefore the pager pulls in results via AJAX.
Comment #24
lucaschain commented@benjy That's exactly what I tried to mean, maybe I misused some words because english is not my first language :)
Thank you for correcting.
What do you think is the best we can do?
Comment #25
lucaschain commentedI created a new patch to ensure that ajax will be disabled on a crawler visit.
That fixed the error for me, would you test now?
Comment #26
sothish commented@lucaschain, infact the below code worked for me. Thanks
Two issues with your previous fix,
- "Loading.." message was still shown in the page.
- was throwing JS exception, as dom_id was not found
Comment #27
lucaschain commentedYou're totally right, @sothish
I updated my patch with your code and added you on the commit credits
Comment #28
sothish commented@lucaschain, Cool Thanks.
Why did you remove one test?, Now we can have this test also, right?
Comment #29
lucaschain commentedGood Idea @sothish
I thought we couldn't handle $_SERVER variables on the drupal.org tester but let's test it again
Again, I recreated the patch with your name on the contributions
Comment #30
sothish commented@lucaschain, All the 6 tests are passed in my local also, Please find the interdiff patch attached, with some formatting done as per Drupal Coding standards
Comment #31
benjy commentedCan we add some docs for this method.
Can we not preq_quote this where we actually do the check? Seems a little funny to preq_quote() before we save the value.
Why implode these here, they could just be an array?
Comment #32
lucaschain commentedWhere can I add it? Comments?
I used preg_quote on the user input for one thing: I couldn't use it at the regex build moment because it would escape the pipes. To prevent slashes from accumulating, I used stripslashes when displaying the items on the textbox
It is not recommended to use an array inside a constant. Not all PHP versions support this and I didn't want to serialize the array. You can read more here http://php.net/manual/en/function.define.php
Comment #33
lucaschain commentedUploaded new patch with the isClientCrawler documentation and fix on some drupal coding standarts according to @sothish
Comment #34
sothish commentedComment #35
benjy commentedThanks for all the work on this, I've made a few changes and now I think it's ready. If you would like to test again?
Changes are:
I was thinking we could simplify this feature a whole lot more by simply removing the admin form altogether and just leaving it in variable_get(), that way users can override per site from their settings file? If we did that, it could just be a regex string and we wouldn't need any converting to/from textareas etc
*EDIT* Patch against this comment was actually an interdiff against your last patch.
Comment #37
benjy commentedTwo patches, full patch from #35 and then a no-admin version as a POC
Comment #40
benjy commentedI think I prefer the no admin approach, it's much simpler. Couple of points i picked up in my own patch.
Trailing space to fix on commit.
This would need removing from no-admin version.
Comment #41
benjy commentedTry again.
Comment #42
benjy commentedVersion number on this issue was incorrect.
Comment #45
benjy commentedIs there a reason we need to disable ajax and not just disable the views query? The result should be displayed without doing this?
Comment #46
lucaschain commentedThis is done because views still need to be rendered, and things that would still use ajax like pagination should not. thats why we set ajax to false
Comment #47
benjy commentedAhh yes, that makes sense. OK, so the rest is good? Did you have a preference on just dropping the UI? Core doesn't have a UI for things like 404_fast_paths I think it might be overkill here?
Comment #48
lucaschain commentedI think the rest is good. My opinion is to maintain the UI, when you said that it would be useful I realized that really is. There are lots of robots coming out to the world every moment and we should not rely on module upgrades to fulfill this
Comment #49
benjy commentedWe wouldn't need a new release to add more robots, it would just be configurable from $conf in your settings.php file or with a simple variable_set in an update hook.
Comment #50
benjy commentedWill look at committing later today.
Comment #51
benjy commentedCommitted #41 as it was the simplest patch. @lucaschain thanks for all your efforts here, much appreciated.