Bitcoin Forum
June 20, 2024, 03:27:48 PM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: « 1 [2]  All
  Print  
Author Topic: Quoting from locked threads (SMF patch)  (Read 455 times)
dkbit98
Legendary
*
Offline Offline

Activity: 2268
Merit: 7248



View Profile WWW
June 12, 2024, 10:26:26 AM
Merited by PowerGlove (1)
 #21

That was one of the quickest ever SMF patch adoption by theymos, but like I suspected now BPIP quote copy option is missing when extension is used. and that was probably faster way of quoting posts.
Maybe suchmoon can make small tweaks to make it work again.

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
PowerGlove (OP)
Hero Member
*****
hacker
Offline Offline

Activity: 528
Merit: 4310



View Profile
June 12, 2024, 04:16:04 PM
Merited by dkbit98 (3)
 #22

(...) but like I suspected now BPIP quote copy option is missing when extension is used.
Hmm... that's a pity. (I've sent suchmoon a PM offering my help to fix it.)



Nice! It's a pretty self-contained patch, so I was able to add it fairly easily. I left a warning on the post page, though, since I don't think it was otherwise obvious enough what was going on.
I think the warning you added was a good call. Thanks for merging this one! (That was quick. Of course, it had to be in the topic where I said "it's difficult to get theymos to come down from the mountain" that you merged it within a few hours of logging in.) Cheesy



Thanks for the kind words everyone! I'm always tempted to hit that +Merit button on every post that makes me smile, but I (mostly) always succeed in stopping myself: It just seems very self-serving to "encourage" posts like that, but you should all be aware that I appreciate reading them, and that they do mean a lot to me.
Upgrade00
Legendary
*
Offline Offline

Activity: 2072
Merit: 2197


Playgram - The Telegram Casino


View Profile WWW
June 12, 2024, 04:56:39 PM
 #23

I'm always tempted to hit that +Merit button on every post that makes me smile, but I (mostly) always succeed in stopping myself: It just seems very self-serving to "encourage" posts like that, but you should all be aware that I appreciate reading them, and that they do mean a lot to me.
Maybe we'll create a patch that stops you from stopping yourself. Grin
But you're the one who needs the appreciation and merits. I'm sure theymos wonders where you have been all his bitcointalk life.

This is and there excellent improvement to the forum and adding a warning message was a great call, otherwise users who find their way to a locked thread without knowing what went on here will be very confused. It shouldn't be long now before you return with another fix.

▄▄███████▄▄███████
▄███████████████▄▄▄▄▄
▄████████████████████▀░
▄█████████████████████▄░
▄█████████▀▀████████████▄
██████████████▀▀█████████
████████████████████████
██████████████▄▄█████████
▀█████████▄▄████████████▀
▀█████████████████████▀░
▀████████████████████▄░
▀███████████████▀▀▀▀▀
▀▀███████▀▀███████

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
 
Playgram.io
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

▄▄▄░░
▀▄







▄▀
▀▀▀░░
▄▄▄███████▄▄▄
▄▄███████████████▄▄
▄███████████████████▄
▄██████████████▀▀█████▄
▄██████████▀▀█████▐████▄
██████▀▀████▄▄▀▀█████████
████▄▄███▄██▀█████▐██████
█████████▀██████████████
▀███████▌▐██████▐██████▀
▀███████▄▄███▄████████▀
▀███████████████████▀
▀▀███████████████▀▀
▀▀▀███████▀▀▀
██████▄▄███████▄▄████████
███▄███████████████▄░░▀█▀
███████████░█████████░░
░█████▀██▄▄░▄▄██▀█████░
█████▄░▄███▄███▄░▄█████
███████████████████████
███████████████████████
██░▄▄▄░██░▄▄▄░██░▄▄▄░██
██░░░░██░░░░██░░░░████
██░░░░██░░░░██░░░░████
██▄▄▄▄▄██▄▄▄▄▄██▄▄▄▄▄████
███████████████████████
███████████████████████
 
PLAY NOW

on Telegram
dkbit98
Legendary
*
Offline Offline

Activity: 2268
Merit: 7248



View Profile WWW
June 12, 2024, 05:09:55 PM
 #24

Hmm... that's a pity. (I've sent suchmoon a PM offering my help to fix it.)
Thanks!
I created another post in BPIP topic about this issue, but it's nothing urgent if suchmoon is busy.

Now I am wondering what is your upcoming SMF patch idea, the way you are going I think this is slowly becoming addiction for you to patch bitcointalk Wink

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
Quickseller
Copper Member
Legendary
*
Offline Offline

Activity: 2912
Merit: 2346


View Profile
June 15, 2024, 07:08:31 AM
 #25


Code:
 
+ // Previous posts won't be displayed by the template when $context['only_peeking'] is true, so save some cycles...
+ $limit = $context['only_peeking'] ? ' LIMIT 0' : $limit;
+
  // If you're modifying, get only those posts before the current one. (otherwise get all.)
  $request = db_query("
  SELECT IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime, m.body, m.smileysEnabled, m.ID_MSG
  FROM {$db_prefix}messages AS m
  LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
  WHERE m.ID_TOPIC = $topic" . (isset($_REQUEST['msg']) ? "
  AND m.ID_MSG < " . (int) $_REQUEST['msg'] : '') . "
  ORDER BY m.ID_MSG DESC$limit", __FILE__, __LINE__);
  $context['previous_posts'] = array();
  while ($row = mysql_fetch_assoc($request))
  {
  // Censor, BBC, ...
  censorText($row['body']);
  $row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);
 

I am not 100% certain, but this may be an unnecessary query to the database. When quoting from a locked thread, the limit is set to zero, so no rows will be returned in the query, but the query will still run.
PowerGlove (OP)
Hero Member
*****
hacker
Offline Offline

Activity: 528
Merit: 4310



View Profile
June 15, 2024, 10:05:02 AM
 #26

I am not 100% certain, but this may be an unnecessary query to the database. When quoting from a locked thread, the limit is set to zero, so no rows will be returned in the query, but the query will still run.
Yup, the query will run, but the intention there is for the query optimizer to recognize the LIMIT 0 and internally reduce that query down to something that quickly returns an empty set (look for "LIMIT Query Optimization" in the MySQL documentation).

In general, when you spot an odd-looking construct in one of my SMF patches, it's likely because I estimated that the alternative way(s) of doing that thing would have led to a less compact diff. Obviously, I'm not going to favor small diffs over every other concern, but it is something that heavily factors into my decision-making (because, in turn, I believe it's something that factors into theymos' decision-making).
theymos
Administrator
Legendary
*
Offline Offline

Activity: 5236
Merit: 13089


View Profile
June 16, 2024, 03:58:18 PM
 #27

I am not 100% certain, but this may be an unnecessary query to the database. When quoting from a locked thread, the limit is set to zero, so no rows will be returned in the query, but the query will still run.

You're right that a maximally-performant implementation would definitely omit the query entirely. Even a query like "SELECT 1;" is slower than just about anything done within PHP, since a network request introduces a (relative) ton of latency.

However, I would consider it a slightly worse patch if it fixed this because it would increase the code complexity a fair bit, and the only benefit would be saving a few milliseconds on a page that will probably only be accessed a handful of times each day. In fact, if I'd been writing this, I probably would've left the query as-is, since that would've only used a couple of additional miliseconds.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
PowerGlove (OP)
Hero Member
*****
hacker
Offline Offline

Activity: 528
Merit: 4310



View Profile
June 16, 2024, 09:59:46 PM
 #28

In fact, if I'd been writing this, I probably would've left the query as-is, since that would've only used a couple of additional miliseconds.
I nearly left it as-is, but that particular spot (just above the query and just below the stuff already establishing a $limit variable) jumped out at me: it's just such a neat/tempting location to place a little optimization like that...

But, thinking about it now and in terms of profiling the code over a day instead of only in request-specific isolation, it could have been a mistake for me to add it: I mean, the additional bytecode generated for testing $context['only_peeking'] and then branching is negligible, but it is present during every invocation of getTopic() (even the invocations that have nothing to do with quoting from locked threads), so depending on the ratio between ;peek requests and ordinary ones, a complete tally of time-saved vs. time-spent might not be as clear-cut as I guessed.
Quickseller
Copper Member
Legendary
*
Offline Offline

Activity: 2912
Merit: 2346


View Profile
June 16, 2024, 11:18:51 PM
 #29

I am not 100% certain, but this may be an unnecessary query to the database. When quoting from a locked thread, the limit is set to zero, so no rows will be returned in the query, but the query will still run.
Yup, the query will run, but the intention there is for the query optimizer to recognize the LIMIT 0 and internally reduce that query down to something that quickly returns an empty set (look for "LIMIT Query Optimization" in the MySQL documentation).

In general, when you spot an odd-looking construct in one of my SMF patches, it's likely because I estimated that the alternative way(s) of doing that thing would have led to a less compact diff. Obviously, I'm not going to favor small diffs over every other concern, but it is something that heavily factors into my decision-making (because, in turn, I believe it's something that factors into theymos' decision-making).
Yes, when such a query is executed, there shouldn't be any rows that are parsed, but some database resources will still be consumed.

I certainly agree that the particular change does prioritize code simplicity, which is fair.

I am not 100% certain, but this may be an unnecessary query to the database. When quoting from a locked thread, the limit is set to zero, so no rows will be returned in the query, but the query will still run.

You're right that a maximally-performant implementation would definitely omit the query entirely. Even a query like "SELECT 1;" is slower than just about anything done within PHP, since a network request introduces a (relative) ton of latency.

However, I would consider it a slightly worse patch if it fixed this because it would increase the code complexity a fair bit, and the only benefit would be saving a few milliseconds on a page that will probably only be accessed a handful of times each day. In fact, if I'd been writing this, I probably would've left the query as-is, since that would've only used a couple of additional miliseconds.
I wouldn't necessarily be worried about the user experience of a single request (which, as you say, will be negligible), but of the additional resources consumed. This is coming from a perspective of not knowing where the resource bottlenecks are if any exist.

It seems that PowerGlove is aware that you prioritize simple changes, which is a fair priority, as a more complex change can be more difficult to test, and has the potential to break things and/or introduce a vulnerability.

I am not an expert on the SMF code base, but if there is a bottleneck in the database, the query could be eliminated with the following change to the getTopic topic in Post.php.

Code:
function getTopic()
{
    global $topic, $db_prefix, $modSettings, $context;

    // If we're only peeking, we don't need to fetch previous posts
    if ($context['only_peeking'])
    {
        $context['previous_posts'] = array();
        return;
    }

    // Calculate the amount of new replies.
    $newReplies = empty($_REQUEST['num_replies']) || $context['num_replies'] <= $_REQUEST['num_replies'] ? 0 : $context['num_replies'] - $_REQUEST['num_replies'];

    if (isset($_REQUEST['xml']))
        $limit = "
        LIMIT " . (empty($newReplies) ? '0' : $newReplies);
    else
        $limit = empty($modSettings['topicSummaryPosts']) ? '' : '
        LIMIT ' . (int) $modSettings['topicSummaryPosts'];

    // If you're modifying, get only those posts before the current one. (otherwise get all.)
    $request = db_query("
        SELECT IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime, m.body, m.smileysEnabled, m.ID_MSG
        FROM {$db_prefix}messages AS m
            LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
        WHERE m.ID_TOPIC = $topic" . (isset($_REQUEST['msg']) ? "
            AND m.ID_MSG < " . (int) $_REQUEST['msg'] : '') . "
        ORDER BY m.ID_MSG DESC$limit", __FILE__, __LINE__);
    $context['previous_posts'] = array();
    while ($row = mysql_fetch_assoc($request))
    {
        // Censor, BBC, ...
        censorText($row['body']);
        $row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);

        $context['previous_posts'][] = $row;
    }
    mysql_free_result($request);
}
suchmoon
Legendary
*
Offline Offline

Activity: 3710
Merit: 8981


https://bpip.org


View Profile WWW
June 17, 2024, 12:07:33 AM
Merited by PowerGlove (1)
 #30

But, thinking about it now and in terms of profiling the code over a day instead of only in request-specific isolation, it could have been a mistake for me to add it: I mean, the additional bytecode generated for testing $context['only_peeking'] and then branching is negligible, but it is present during every invocation of getTopic() (even the invocations that have nothing to do with quoting from locked threads), so depending on the ratio between ;peek requests and ordinary ones, a complete tally of time-saved vs. time-spent might not be as clear-cut as I guessed.

Maybe you could eliminate the call to getTopic altogether? Still branching as many times however the cost would likely be offset by not having the function call.

Not that it matters much, this seems such a minor issue.
PowerGlove (OP)
Hero Member
*****
hacker
Offline Offline

Activity: 528
Merit: 4310



View Profile
June 17, 2024, 12:21:44 AM
 #31

Not that it matters much, this seems such a minor issue.
It's an incredibly minor issue, and given the unnecessary discussion it's caused, I regret including the optimization to begin with. Undecided
Pages: « 1 [2]  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!