I am using Revisions for my nodes, and I noticed that when I use the Similar Block, it shows all revisions of a given node, instead of the latest one. I believe it should only show the latest published version.

I am running v4.7.2 and followed the install instructions correctly.

Thanks. -Gman

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

deekayen’s picture

Assigned: Unassigned » deekayen

You're right and I agree.

deekayen’s picture

Status: Active » Fixed

Added missing DISTINCT() to the node id in the node_revisions query and sorted by revision ID in descending order to get the newest revision. Applied to DRUPAL-4-7 and DRUPAL-4-6.

JillJack’s picture

I'm using 4.7.2 and the latest release of Similar Entries. I'm still seeing multiple revisions in the listings. Also, special characters are escaping (i.e. &)

deekayen’s picture

Status: Fixed » Active
Gman’s picture

Yes, I verify that it is still showing multiple revisions of the same node. - Gman

anisotropic’s picture

FileSize
1.38 KB

There are two queries there depending on whether you have selected taxonomy filtering or not. The additional fix is to add the DISTINCT() call on 228 as well - works for me.

BTW, this works really well as an article level block, a la Nick Lewis's blog post.

deekayen’s picture

Status: Active » Fixed

I committed that patch 13 days ago. Are you guys confirming the bug still exists on an old version? The CVS ID version in the top of the source for similar.module for the update with DISTINCT() for Drupal 4.7 is 1.2.2.5 and 1.1.2.5 for Drupal 4.6.

Gman’s picture

Thanks, seems to be working. I must have copied over the patch, since it seems to be the same. Looks good now, except, the term_node table is not in {} in the query:

...FROM {node_revisions} r, {node} n, term_node ...

should be

... FROM {node_revisions} r, {node} n, {term_node} ...

deekayen’s picture

Committed term_node patch to DRUPAL-4-6 and DRUPAL-4-7.

Gman’s picture

FileSize
1.9 KB

Not trying to be a pest, but I noticed that with Distinct, it MySQL chooses the first match for the node, which may not be the current revision of the node. So similar would display an older revisions title and teaser.

I have experimented a bit (also looked at how the node module picks the latest revision) and think that a change from distinct to INNER JOINs will work, since the node table is already open, just inner join on the vid, and then for good measure I updated the taxonomy part to another inner join.

I admin that I am a bit new to this, so please look this over, but I did test on my local testbed and seems to be working.

-Greg

deekayen’s picture

G - I think your patch comes to the same end result. Note the ORDER BY sorts vid in descending order, which would make the biggest/newest version number first in the list before DISTINCT picks the first one. Another alternative might be to not use DISTINCT() might also be to just order by vid desc but add LIMIT 1 at the end. I think it's more an issue of which one uses less memory, less CPU clocks, and/or is more portable between DB versions. Honestly, I don't know which it is.

I'm declining the patch unless you've got a more convincing argument to go one way over the others.

Gman’s picture

I have not clue regarding efficiency issues, since I am rather new, but my observations did show that the DISTINCT and ORDER BY were not getting the most current node.

In my use, the teaser and title being displayed were from an old revision. From my observation, and a little reading on the net, DISTINCT acts on the list before ORDER BY acts. I also thought that ORDER BY acts after the results had been queried, not during the query.

I do believe this is needed. If a node is updated, making the content no longer the top 5 scoring nodes to match the current node, I believe the current setup may (not always, but at times) choose an older revision when creating the title/teaser of the node.

Of course, the actual node linked is to the current one, but the title/teaser of the Similar block may not match that of the actual node that is presented.

Either way (I will keep this mod for myself :), I really like this module, and I thank you for your effort in creating this.

Gman’s picture

EDIT: Had another thought as well.

The first sort order is by score, then by vid, so if an older revision matches the node with a higher score, than that older revision will be at the top of the stack when DISTINCT acts on it, thus returning an older title/teaser.

But if the INNER JOIN is done, the you will only be looking at the best score of current nodes.

A little thinking on speed:

I believe with the INNER JOIN, fewer records will be returned (no duplicate revisions), so the sorting will go faster. So it is really a test between the INNER JOINS with fewer sorts, against the current (which of course I haven't a clue which is better). Thanks for listening. :)

Greg

deekayen’s picture

Status: Fixed » Needs review
gmark’s picture

I just downloaded and installed 1.2.2.7, and am getting the Multiple Revisions issue. Do I need to install these patches? Or should they have already been rolled into the current release?

deekayen’s picture

Gman's patch isn't in 1.2.2.7. I would appreciate you applying his patch to your version and see if it solves the problem. I don't have a site with a lot of node revisions to properly test this issue.

noid’s picture

I am not sure if this issue is related or is the same one, but I've downloaded the 1.1.2.7 revision ($Id: similar.module,v 1.1.2.7 2006/07/05 19:46:07 deekayen Exp$) (http://drupal.org/node/25974/release) for my 4.6.9 installation, and UNPUBLISHED version(s) of a node are displayed along with the published version (e.g. mysite/this-article-0 is also displayed aside from mysite/this-article, when the latter should only be displayed). I wanted to try Gman's patch (using INNER JOIN), but I'm using 4.6. What's the exact code to try to fix this for 4.6? Thanks in advance! :)

mercmobily’s picture

I am a little confused... deekayen, is this bug actually closed? That is, only the latest revision is shown, and it does _not_ consider unpublished nodes?

Thanks a lot!

Merc.

deekayen’s picture

mercmobily - no this bug is not closed. I have trouble committing a patch that I'm not able to verify the results of, just based on the report of a single person, whether the patch looks syntax looks ok or not. Looking for testers. I can roll a 4.6 version for noid if that will get things moving...

deekayen’s picture

FYI, CVS revision 1.5 has had Gman's patch applied since Nov 6 and needs review (for Drupal 5).

Gman’s picture

Sorry, I haven't been able to check this update. Stopped using this module due to clutter on my site. I will grab the update and re-install to to check against my site.

Gman’s picture

Looks good to me. I installed and set the block and noted a few nodes (pages in a book). The module showed other nodes in the book, as expected.

Then I updated the page title of one of them (creating a new revision). The similar module did show the updated title when listing similar nodes (meaning it was pulling the latest revision information, instead of older revisions).

I then completely changed the content of the node, creating yet another revision. Now the similar block did not show any of the original nodes (since they didn't match the new content). Also, the other nodes did not refer to the new updated node in the similar block either (the old revision match but are not accessible and should not be displayed, this way the error that I was getting that prompted this patch).

Lastly, I reverted back to the original revision (which causes Drupal to make a new copy of the old revision) and it all goes back to matching similar nodes as before.

Appears to be working against the test cases that prompted the patch. -Gman

mercmobily’s picture

Hi,

WOW... this means that the issue is really resolved, and we can start using it for Free Software Magazine?

Merc.

deekayen’s picture

Status: Needs review » Fixed

Gman's bug and Gman says it's fixed, so closing. FYI, I just branched to DRUPAL-5 for dev snapshots.

deekayen’s picture

Just backported to Drupal 4-7 branch and tagged for a stable 1.0 release

Anonymous’s picture

Status: Fixed » Closed (fixed)