solved JR PJ - Comments Sort

Dazed
Dazed
@dazed
11 years ago
1,022 posts
So I have the below code and I noticed today that I have comments from 2010. Did the order by clause change?

{jrCore_list module="jrComment" order_by="_created NUMERICAL_DESC" limit="10" template="side_comments.tpl" assign="SIDE_COMMENTS"}

updated by @dazed: 01/13/15 06:09:36AM
michael
@michael
11 years ago
7,772 posts
The order by clause did change. _created used to run just by the inserted id in the database, but because imports from external systems could end up entering the newest first in the database _created was no longer always in the same order as the timestamp for when it was created.

Does that make sense? another way.

#1 - time = 1001
#2 - time = 1030
#3 - time = 1052

so ordering by #1,#2,#3 is the same order as ordering by 1001,1030,1052 but when things are imported its not the same.

So yes it has changed to use the timestamp instead of the item id.

Its in the changelog under Version 5.2.16
Quote:

Jamroom Core changelog Version 5.2.16: - New: modules can include their own sprite icons in img/icons_(black|white) - Change: ordering by _created no longer maps to ordering by _item_id - Change: Form Designer field ordering updated to be more consistent - Bug Fix: Form Designer could get "stuck" turned on for a specific form - Bug Fix: Cache key used in {jrCore_list} could be incorrect based on listeners
here:
https://www.jamroom.net/the-jamroom-network/networkmarket/32/jamroom-5-system-core
Dazed
Dazed
@dazed
11 years ago
1,022 posts
Thanks Michael. I changed it to "_item_id NUMERICAL_DESC" and that is pulling it in correctly.
michael
@michael
11 years ago
7,772 posts
Champion. ;)

Glad you got it sorted.
Dazed
Dazed
@dazed
11 years ago
1,022 posts
very punny :)
paul
@paul
11 years ago
4,335 posts
Wonder if Michael meant that ;-)


--
Paul Asher - JR Developer and System Import Specialist
brian
@brian
11 years ago
10,148 posts
Dazed:
Thanks Michael. I changed it to "_item_id NUMERICAL_DESC" and that is pulling it in correctly.

On your site that should have made no difference - ordering by _created DESC and _item_id DESC should give you the exact same results.

The only reason we had to make this change is that when importing from other sites, sometimes the items can be "out of order" - i.e. item_id 3 actually is NEWER than _item_id 4. But on a JR system that is running on data just input from JR, there should be no difference.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Dazed
Dazed
@dazed
11 years ago
1,022 posts
Hey Brian. Changing this did correct the sort issue. Using _created desc had me all over the map for site comments. I had posts for 2008 appearing as the first post.
michael
@michael
11 years ago
7,772 posts
paul:
Wonder if Michael meant that ;-)

Went straight over my head. No fancy multi-meaning stuff here.
brian
@brian
11 years ago
10,148 posts
Dazed:
Hey Brian. Changing this did correct the sort issue. Using _created desc had me all over the map for site comments. I had posts for 2008 appearing as the first post.

OK - those would be posts that were "imported" via the JR4 import tool. We would need to check that out and make sure it was creating the correct time stamp.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
blindmime
@blindmime
11 years ago
772 posts
I'm seeing this issue with the youtube module and a module I created via Aparna. I'm seeing it on all of my jamroom websites. None of the items in both modules were "imported". Before updating to ver16 I was using "_created DESC" and these items were listing from last entered to first entered. After the update, not so. Changing to "_item_id DESC" fixes it, but you may want to check those module's timestamping I guess. The blog module doesn't seem to be affected.

I do have a jr website where I have imported thousands of profiles using phpmyadmin. The mysql inserts I constructed for that contained a timestamp value which is the same for every record. "_created DESC" has stopped working there of course, which makes sense if _created is going by the timestamp now. I wonder if the jr_import tool does something similar.

Reading what Brian has said, the youtube and aparna modules are evidently not creating proper timestamps. Even youtube videos added AFTER the v16 update do not appear at the top of a "_created DESC" list.
updated by @blindmime: 12/07/14 04:09:31AM
brian
@brian
11 years ago
10,148 posts
I will test this more in depth the coming week and make sure we don't have a problem with the underlying sort functionality - thanks for letting me know.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
brian
@brian
11 years ago
10,148 posts
I've just finished testing this and I'm not seeing any issues with it - ordering by _created as well as _item_id are working properly, and show the exact same order for created items (i.e. the items are not overriding the core's _created value).

Can you show me a jrCore_list call you are using that is not functioning correctly for you?

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
blindmime
@blindmime
11 years ago
772 posts
{jrCore_list module="jrYouTube" order_by="_item_id DESC" template="index_list_youtube.tpl" limit="10"} lists newest to oldest

{jrCore_list module="jrYouTube" order_by="_created DESC" template="index_list_youtube.tpl" limit="10"} oldest to newest, used to list newest to oldest

Aparna-generated modules do the same thing.

Happens on all of my websites.
updated by @blindmime: 12/10/14 04:46:40AM
Dazed
Dazed
@dazed
11 years ago
1,022 posts
If it helps, here was my original Brian.

{jrCore_list module="jrComment" order_by="_created desc" template=$site_comments_template pagebreak="6"  page=$_post.p}
brian
@brian
11 years ago
10,148 posts
Okay I just setup a test here:

https://www.jamroom.net/youtube_test

and I'm not seeing any issues. Note that the ordering on the YouTube listing is different - that's because those youtube videos were "imported" at the same time, and if MySQL sees a bunch of items with the SAME value, it will return them in ASC order.

Here's the template I used if you want to test yourself on your site (and link here if you see an issue):

{jrCore_include template="header.tpl"}

{capture name="yt" assign="tpl"}
{literal}
{foreach $_items as $i}
ITEM_ID: {$i._item_id} : CREATED: {$i._created}<br>
{/foreach}
{/literal}
{/capture}

<h1>Comments</h1>
<br>
ORDER BY _item_id DESC:<br>
{jrCore_list module="jrComment" order_by="_item_id DESC" skip_triggers=true template=$tpl limit="20"}
<br><br>
ORDER BY _created DESC:<br>
{jrCore_list module="jrComment" order_by="_created DESC" skip_triggers=true template=$tpl limit="20"}

<br><br>

<h1>YouTube</h1>
<br>
ORDER BY _item_id DESC:<br>
{jrCore_list module="jrYouTube" order_by="_item_id DESC" skip_triggers=true template=$tpl limit="20"}
<br><br>
ORDER BY _created DESC:<br>
{jrCore_list module="jrYouTube" order_by="_created DESC" skip_triggers=true template=$tpl limit="20"}

{jrCore_include template="footer.tpl"}

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
blindmime
@blindmime
11 years ago
772 posts
Interesting. My youtube videos weren't imported at the same time. They're scattered over many months and over many different websites and a few different hosts, each using the same code referenced above. I use this on many different sites and before the recent update I was using _created DESC to order them newest to oldest. After the update, the order changed. I also verified this by importing a NEW video after the update on one existing site, as well as a brand new website started on v16. _created DESC is not ordering newest to oldest. I can only get the order to run newest to oldest by using _item_id DESC. Only difference I see is in the skip_triggers option.
brian
@brian
11 years ago
10,148 posts
If you use my template above is it ordered correctly on your site?


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
blindmime
@blindmime
11 years ago
772 posts
I get this:

Comments
ORDER BY _item_id DESC:


ORDER BY _created DESC:
ITEM_ID: 1 : CREATED: 1412159783


YouTube
ORDER BY _item_id DESC:
ITEM_ID: 82 : CREATED: 1417950036
ITEM_ID: 81 : CREATED: 1414361773
ITEM_ID: 80 : CREATED: 1414361545
ITEM_ID: 79 : CREATED: 1414361355
ITEM_ID: 78 : CREATED: 1414361167
ITEM_ID: 77 : CREATED: 1414281974
ITEM_ID: 76 : CREATED: 1414281771
ITEM_ID: 75 : CREATED: 1414132157
ITEM_ID: 74 : CREATED: 1413740175
ITEM_ID: 73 : CREATED: 1413739349
ITEM_ID: 72 : CREATED: 1413739101
ITEM_ID: 71 : CREATED: 1413738521
ITEM_ID: 70 : CREATED: 1413267569
ITEM_ID: 69 : CREATED: 1413267543
ITEM_ID: 68 : CREATED: 1412731334
ITEM_ID: 67 : CREATED: 1412730877
ITEM_ID: 65 : CREATED: 1412540177
ITEM_ID: 64 : CREATED: 1412540065
ITEM_ID: 63 : CREATED: 1412540047
ITEM_ID: 62 : CREATED: 1412540026


ORDER BY _created DESC:
ITEM_ID: 1 : CREATED: 1381471710
ITEM_ID: 2 : CREATED: 1381471813
ITEM_ID: 3 : CREATED: 1381619406
ITEM_ID: 4 : CREATED: 1381619725
ITEM_ID: 5 : CREATED: 1381727234
ITEM_ID: 6 : CREATED: 1381751462
ITEM_ID: 7 : CREATED: 1381754670
ITEM_ID: 8 : CREATED: 1381910815
ITEM_ID: 9 : CREATED: 1381911003
ITEM_ID: 10 : CREATED: 1381911045
ITEM_ID: 11 : CREATED: 1381911067
ITEM_ID: 12 : CREATED: 1381913273
ITEM_ID: 13 : CREATED: 1381988934
ITEM_ID: 14 : CREATED: 1381988989
ITEM_ID: 15 : CREATED: 1381989903
ITEM_ID: 16 : CREATED: 1381990030
ITEM_ID: 17 : CREATED: 1381990058
ITEM_ID: 18 : CREATED: 1381991867
ITEM_ID: 19 : CREATED: 1381991906
ITEM_ID: 20 : CREATED: 1381991957
michael
@michael
11 years ago
7,772 posts
The difference between DESC and NUMERIC_DESC is:

DESC:
1
11
111
1111
2
22
222

and NUMERIC_DESC

1
2
11
22
111
222
1111
blindmime
@blindmime
11 years ago
772 posts
The correct term is NUMERICAL_DESC, but I'm not sure that's the issue, Michael. numerical_desc gives me the same order as desc.

Why is my list different than Brian's? Brian's list has desc running newest to oldest and mine is the opposite. I just copied and pasted his code as a new page on my site called test.
updated by @blindmime: 12/12/14 02:54:46AM
brian
@brian
11 years ago
10,148 posts
I have a feeling it might be related to this issue:

https://www.jamroom.net/the-jamroom-network/forum/new_posts/18784/events-listing-problem#last

I found a small issue when sorting by _created BUT it may not always happen due to the order that the datastore puts "where" conditions in. I'm working on the new core release so let's see if it is fixed after that.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
brian
@brian
11 years ago
10,148 posts
This should (hopefully) be working correctly in jrCore 5.2.17 - let me know if it looks good now.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
blindmime
@blindmime
11 years ago
772 posts
It looks good now -- thanks, Brian!
brian
@brian
11 years ago
10,148 posts
Glad to hear it - thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net