News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Best Answer

Started by Avalanche91, December 05, 2013, 09:09:24 AM

Previous topic - Next topic

Avalanche91

Quote from: Arantor Beeblebrox the First on December 06, 2013, 03:18:20 PM
Thanks for ignoring what I was trying to tell you.

1. I am not referring to $message which is a per-post item created during the depths of prepareDisplayContext. This is why you are generating queries per post.

2. I mentioned $messages, not $message, as an array of the message ids that will be fetched for the current post. I only didn't tell you where to look because I was in the middle of something else. Look at Display.php, line 814 onwards.


Using this information, let's be *really* clever and avoid extra queries.

The query on line 180 fetches the topic data. Fetch the msg id as the 'best answer' in that query, no extra queries required. This will be pushed into $topicinfo which is global.

Then by the time you get to the messages query stuff at line 814, you'll already know whether or not you have the best answer. But even if you didn't worry about that, you will have the topic's 'best answer' id available in $topicinfo, which means by the time you get to prepareDisplayContext, you don't have to do any queries but simple comparisons.
Now I understand you, sir. Thanks for the suggestion but at this point of development I will take the liberty to go on with a separate query. I am already joining one more table on my query and I will have to make some more replacements in the view. I will consider it again tomorrow, but I think I had enough of it for today; I would like to consult with my pillow firstly :)

Avalanche91

Hey, @Arantor Beeblebrox the First , I spent some time trying to work out your suggestion. So I would like to hear your opinion now, here's what I managed to figure out. As you well noted, I can merge my code into the query at line 180 where we normally have:
Code (mysql) Select
SELECT
t.num_replies, t.num_views, t.locked, ms.subject, t.is_sticky, t.id_poll,
t.id_member_started, t.id_first_msg, t.id_last_msg, t.approved, t.unapproved_posts,
' . ($user_info['is_guest'] ? 't.id_last_msg + 1' : 'IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1') . ' AS new_from
' . (!empty($modSettings['recycle_board']) && $modSettings['recycle_board'] == $board ? ', id_previous_board, id_previous_topic' : '') . '
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)' . ($user_info['is_guest'] ? '' : '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = {int:current_topic} AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = {int:current_board} AND lmr.id_member = {int:current_member})') . '
WHERE t.id_topic = {int:current_topic}
LIMIT 1


So after adding more fields to the select clause and joining two more tables, I ended up with this.
Code (mysql) Select
SELECT
t.num_replies, t.num_views, t.locked, ms.subject, t.is_sticky, t.id_poll,
t.id_member_started, t.id_first_msg, t.id_last_msg, t.approved, t.unapproved_posts,
' . ($user_info['is_guest'] ? 't.id_last_msg + 1' : 'IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1') . ' AS new_from
' . (!empty($modSettings['recycle_board']) && $modSettings['recycle_board'] == $board ? ', id_previous_board, id_previous_topic' : '') . '
/* LINE ADDED */ ,`ba`.`id`,`ba`.`id_msg`,`ba`.`id_topic`,`ba`.`id_member`,DATE(`ba`.`time_marked`) AS `day`,TIME(`ba`.`time_marked`) AS `time`,`m`.`member_name`
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)' . ($user_info['is_guest'] ? '' : '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = {int:current_topic} AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = {int:current_board} AND lmr.id_member = {int:current_member})') . '
/* LINE ADDED */ LEFT JOIN {db_prefix}best_answer AS `ba` ON `ms`.`id_msg` = `ba`.`id_msg`
/* LINE ADDED */ LEFT JOIN {db_prefix}members AS `m` ON `ba`.`id_member` = `m`.`id_member`
WHERE t.id_topic = {int:current_topic}
LIMIT 1


So far so good! Now I only need to *somehow* place the second query here, which, by purpose, needs to tell me if the post marked as best answer is among the first 3 answers to the topic. Here comes the thing that troubles me. I have been thinking for hours and I did find a solution but, honestly, I don't really like for two reasons.
- One, it's actually a subquery and I have to disable query check to allow the subquery to work;
- Two, I am using concatenation that may take a lot of resources although I am not absolutely sure here.
This is the line of code:
Code (mysql) Select
(SELECT SUBSTRING_INDEX(GROUP_CONCAT(`id_msg` SEPARATOR "|"), "|", 4) FROM {db_prefix}messages WHERE `id_topic` = {int:id_topic}) AS `ba_jump_in_arr`
-- returns something like:  ["ba_jump_in_arr"]=> string(5) "2|3|4"


So, have you got any suggestions whether my concerns are reasonable or this way of building the query will cause no problems?

Arantor

I'm curious: why you have a table for best answer joined to *message*? Surely there's only one best answer for a topic? I assumed, slightly naively, that you had added it to the topics table based on the fact that's what I'd do if I were doing it...

Why also do you need the best answer being in the first three replies? There is really no good way to do that.

Avalanche91

Quote from: Arantor Beeblebrox the First on December 09, 2013, 03:26:54 PM
I'm curious: why you have a table for best answer joined to *message*? Surely there's only one best answer for a topic? I assumed, slightly naively, that you had added it to the topics table based on the fact that's what I'd do if I were doing it...

Why also do you need the best answer being in the first three replies? There is really no good way to do that.
Everything is because one link that I am displaying below the question post. This link is supposed to take you to that post which is marked as best answer. It comes very handy when you have several pages of posts and you are just looking for the solution of the problem. So, there is no need of displaying this link when there are just few posts (3)... you can clearly see where the answer is.

To be honest, the original idea was to make it as if in Stackoverflow, with that best answer at very top. But unfortunately I found it impossible to mess with the order of the posts. On the other hand, now that you have personally explained to me what does $messages do in Display.php, I might actually be able to work that order out.

Arantor

Well... store the msg id of the best answer in the topics table.

You can always generate the link to a specific message from the topic id and message id - index.php?topic=123.msg456#msg456 will always take you to message 456 if message 456 is in topic 123. SMF will figure out which page to go to etc.

Reinjecting the message id into $messages won't work very well; the query that fetches the post data explicitly orders those posts by way of id_msg. You may have to do a separate query to fetch the best answer if the best answer is not currently listed in $messages, but that's also problematic.

Avalanche91

Quote from: Arantor Beeblebrox the First on December 09, 2013, 04:14:06 PM
Well... store the msg id of the best answer in the topics table.
It is not going to help me. I store additional information regarding time and user; I don't want to drop it.

Maybe I should reconsider my logic, so many efforts for such a simple task. Or I could just delete that piece of code and work with the CSS to make it look less silly when I have only one answer. Or take the laziest way, to leave it just like this...

CHAOS-THEORY

Theres only one bug that u didn't notice; when u delete the choosen best answer's reply in the topi... the Best answer tip stays there all the time and can't be removed.

'This topic contains a post which is marked as Best Answer. Press here if you would like to see it.'

ir's stuck/bugged; i can't remove it, due that the reply choosed as best answer is removed. give me a fix as quick as u can. thanks for ur cooperation

Shambles

Maybe Avalanche91 could consider moving the mod to the Customization Development board with [WIP][MOD] in the title, just to remind other members that it's still under development/fix...?

Avalanche91

Quote from: Shambles on December 10, 2013, 09:26:55 AM
Maybe Avalanche91 could consider moving the mod to the Customization Development board with [WIP][MOD] in the title, just to remind other members that it's still under development/fix...?
Thank you very much, I wanted to warn the users somehow but I actually had no idea how to do it.

@CHAOS-THEORY
Thank you for the report, this bug has been fixed.

Although it looks like a small update I actually did some serious changes including the suggestion of @Arantor Beeblebrox the First. I managed to catch most of the bugs that were caused by the new changes, but I am still afraid that there might be more that I am not aware of.

Alex_Ita

Hi. Congratulation for this mod, very helpfully.

I 've just downloaded newest version and it works better then older.

I've occurred a probably bug: if I merge two threads, and in those trhreads there are two best answer, in new merged topic there's some problem:
in the first post I can read there is a best answer, but the best answer has lost highlight, and the buttons "best answer" and "undo best answer" are disappared.

Would be great if I can assigne privilege to mark best answer at a particular group (not only section moderators).

My best regards.


Alex

Skaty

#50
It would be great feature to use this mod in specific boards.

-Which code should i move to fix that issue ? (display php attached).


-I think there is no permissions for mod right now ?

thank your for the mod it is usefull.


Avalanche91

Quote from: Skaty on December 12, 2013, 07:48:39 AM
It would be great feature to use this mod in specific boards.

-Which code should i move to fix that issue ? (display php attached).


-I think there is no permissions for mod right now ?

thank your for the mod it is usefull.
It looks like there is a conflict between the two mods. I will have to install Thank-o-Matic and change the CSS a bit.

@Alex_Ita Thank you very much. The fix for the bug with the merged topics is ready but I will upload it once I make a fix for in case of using the option to split topics. Things are slightly different when we speak of topic splitting, there are several possible occasions and a single solution might not be the best option here. I want to make the MOD as useful as possible but I have the feeling that eventually the solution would simply be to unset the post marked as best answer, and the person doing the topic splitting would have to manually mark the desired post again.
Quote from: Alex_Ita on December 11, 2013, 02:48:22 PMWould be great if I can assigne privilege to mark best answer at a particular group (not only section moderators).
Originally I wanted to make things simple, if I go for such extras I will have to create a new view (template) for the MOD and I will have to add all the things that I have in my mind (custom colours, rating system, etc :D). I could eventually think of adding such things in version two of my modification, but I don't think that I will have the time (and the patience) any time soon. This is my first mod and it looks like I have underrated the complexity of the SMF platform.

Hopefully I will be ready with the fix for Skaty's problem and the rest of the things that were already reported by the end of tomorrow. Thank you very much guys, great community!

Alex_Ita

Quote from: Avalanche91 on December 12, 2013, 12:57:04 PM
Hopefully I will be ready with the fix for Skaty's problem and the rest of the things that were already reported by the end of tomorrow. Thank you very much guys, great community!

Thanks for your job and you patience. Great mod!

I waiting for your update  :)

Skaty

Turkish Translate



// Best Answer
$txt['bestanswer'] = 'En İyi Cevap';
$txt['rv_bestanswer'] = 'En İyi Cevap (Geri Al)';
$txt['bestanswer_marked'] = 'Bu mesaj En İyi Cevap olarak işaretlendi. İşaretleyen: ';
$txt['bestanswer_jumpto_1'] = 'Bu konu En İyi Cevap olarak işaretlenmiş bir mesaj içeriyor.';
$txt['bestanswer_jumpto_2'] = 'Görmek için tıklayınız.';
// End of Best Answer

Avalanche91

According to GooGle Translate the Turkish translation quite makes sense. I don't speak Turkish and I have no idea if the translation is correct so if anyone has to say something about Skaty's strings, let it be. Other than that I can only say thanks.


Quote* Notes
   - Topic managing:
      -- In case of merging topics each of containing posts marked as best answers, these posts will no longer be marked as such and you will have to choose a new best answer manually, otherwise the best answer will be merged along with the rest of the posts;
      -- In case of splitting a topic containing a post marked as best answer, the best answer will be moved along with the rest of the posts or unset as best answer if it is the only post going to be split.
It was easier than I thought, once you figure out how the topic splitting/merging works you can make the life of the user a little easier... at least.


One more thing, I haven't fixed the problem with the Thank-o-matic MOD. I hope I am mistaken, but GooGle brought me to this page when I searched for the MOD and apparently the MOD is no longer there. That's why I couldn't download it and make any tests.

margarett

ADK-Team removed all their MODs from our modsite, that's why you don't find it in there
http://www.smfpersonal.net/ModsSmfp.html;sa=topic;id=3284
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Alex_Ita

Thank you so much Avalanche91

here you are an Italian language:

// Best Answer
$txt['bestanswer'] = 'Miglior risposta';
$txt['rv_bestanswer'] = 'Annulla Miglior risposta';
$txt['bestanswer_marked'] = 'Marcato come miglior risposta da';
$txt['bestanswer_jumpto_1'] = 'Questo topic contiene un post marcato come Miglior Risposta.';
$txt['bestanswer_jumpto_2'] = 'Clicca qui se vuoi prenderne visione.';
// End of Best Answer


UTF8
// Best Answer
$txt['bestanswer'] = 'Miglior risposta';
$txt['rv_bestanswer'] = 'Annulla miglior risposta';
$txt['bestanswer_marked'] = 'Marcato come miglior risposta da';
$txt['bestanswer_jumpto_1'] = 'Questo topic contiene un post marcato come Miglior Risposta.';
$txt['bestanswer_jumpto_2'] = 'Clicca qui se vuoi prenderne visione.';
// End of Best Answer

Avalanche91

Quote from: margarett on December 13, 2013, 07:05:18 PM
ADK-Team removed all their MODs from our modsite, that's why you don't find it in there
http://www.smfpersonal.net/ModsSmfp.html;sa=topic;id=3284
Thank you very much, margarett. I just spent about two hours trying to figure out some way to go through this problem and I didn't find a good enough solution. The trouble comes a little below the lines where the code producing user signatures comes:
Code (php) Select
echo '
</div>
</div>
<span class="botslice"><span></span></span>
</div>
<hr class="post_separator" />';


For some reason the guys working on Thank-o-meter have decided to place their code within the echo. In matter of fact, that hr tag has display property set to none so basically it is not even visible. It would have been so painless if they have placed their div tag containing thank counts after the hr. The only way I could sort things out is to put my code within the echo as well, searching for the whole piece of code before the hr tag. Which I don't really want to do because it may cause more conflicts with other modifications. Plus that, to make things even worse Thank-o-meter is looking for tabulations too:
Code (xml) Select
<search position="after"><![CDATA[ <hr class="post_separator" />';]]></search>These white-spaces cause more code conflict and in the end if you are to uninstall one of these two mods from your forum - you will have to firstly uninstall the mod that you have installed second.

I will contact the Thank-o-meter team to ask them for a consensus about this precedent. If nothing comes out of that I will publish the changes and I will have my fingers crossed for no other code conflicts with any other modifications. And yes, the Italian version will also be included, thank you Alex_Ita.

Arantor

Except they don't want to put it there because they want it 'inside the post' and thus inside the div.

As for consensus, don't expect great things. They removed all their mods from here because they didn't like how we do things.

Avalanche91

Quote from: Arantor Beeblebrox the First on December 14, 2013, 02:40:48 PM
Except they don't want to put it there because they want it 'inside the post' and thus inside the div.

As for consensus, don't expect great things. They removed all their mods from here because they didn't like how we do things.
Yes, I agree with you. If I were to make their mod I'd probably want to make it *attached* to the post. But honestly, it looks like it is outside of the post, as if it is a new tiny post. There I lose the point.

I changed my mind, there is no point of contacting them. Even if they make any changes there would still be many people using older versions of their MOD. I will look for another solution.

Advertisement: