Uutiset:

Wondering if this will always be free?  See why free is better.

Main Menu
Advertisement:

postgroup hack is slowing me down

Aloittaja MrE, joulukuu 02, 2005, 11:13:42 AP

« edellinen - seuraava »

MrE

I had a problem that I've seen else: I wanted some boards accessed based on postgroups, but I didn't want all groups to have access (there's a kid's board).  So put a little code into Subs-Post.php in the createPost function.  After it updates the member data, it goes back and does one more check:

        //hack for postgroup based group
        if ($user_info['posts'] > 50)
         {
           db_query("
                    UPDATE smf_members
                    SET additionalGroups = CASE
                    WHEN additionalGroups != ''
                    THEN CONCAT_WS(',',additionalGroups,'11')
                    WHEN additionalGroups = ''
                    THEN '11' END WHERE additionalGroups NOT LIKE '%11%'
                    AND additionalGroups NOT LIKE '%9%'
                    AND ID_GROUP != 9
                    AND posts > 50
                    AND ID_MEMBER = " . $ID_MEMBER, __FILE__, __LINE__);
          }

        //end of postgroup hack


The idea being that once someone posted their 50th post (right now it's set at > 50 to catch people who were over 50 when I implemented the hack) it makes sure that they aren't in the denied access group (9) and then puts them in the other group (11) if they're not already in it.
Result:  It worked and my board turned to mud.  My host may have been having some server issues at the same time, but after three days of having my site taking forever to do anything, I commented out the hack, and things seem back to normal.  So now I'm wondering what I did wrong.  I can see a few things I should change so the query doesn't run so often, like check for the two groups before running the query, but even so I think their must be something fundamentally wrong with my query for it to cause such problems.  At the moment the board only gets 30-40 posts per day.  I was thinking, perhaps wrongly, that the query only ran when a new post was created, which means an extra 30-40 queries against the database every day, which isn't ideal, but does seem managable.  But the board seemed slow whether there was active posting or not, so I'm probably missing something.  Any ideas?

Kindred

I believe there is a standard feature already present in SMF that allows you to set board access based on post-count....
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

MrE

#2
Lainaus käyttäjältä: Kindred - joulukuu 02, 2005, 12:41:24 IP
I believe there is a standard feature already present in SMF that allows you to set board access based on post-count....

There is indeed, but it has an undesirable result, at least for me.  Well, not just for me, because I've searced for solutions before and have found others with similar problems, but no solutions.

Problem:

  • I want to give access to certain boards once a post-count is reached
  • But, I do not want a certain subset of my group to see those boards even after they have hit the requred posts

Ever time I read of someone having this problem, the solution presented was: Don't base your permissions off the post-count group.  Which is all well and good, except that I want those boards to be invisible until you hit a certain post-count.  So that was my solution:  A non-post group group that you are automatically added to as long as 1. you reach the required posts, and 2. you are not in the excluded group.

Seemed to work, too, excpet that my board was grinding to a halt.  But, even after commenting it out, I seem to have some sluggish times, so it might be an issue with my host sever yet.  If the query doesn't look flawed or unweildy to anyone else, I'll try uncommenting it out to see if it's still causing problems.

Grudge

MrE,

Do a check on their current groups before doing the query.

i.e.

if ($user_info['posts'] > 9 && !in_array(9, $user_info['groups']) && !in_array(11, $user_info['groups']))
I'm only a half geek really...

MrE

Thank you, that is beautiful.  That is exactly what I wanted to do, but I've been having a hard time following what variables I have available at any given point and how I access them, so I set the limits in the query instead, using only $user_info['posts'] because I knew that one was there.

I knew this would have me query the database far more than necessary, but I didn't expect it to grind things to a halt, especially with such a low traffic site.  I'm still not sure my query is the culprit, as the site still seems a little sluggish, but at least I can now try it again with the query only running when necessary.

Thanks again.

MrE

Update in case anyone else wants to try something like this: Grudge's new and improved if statement appears to be working just fine.  I have actually come to think that my slowdowns were more host-server problems then excessive querying on my part, but either way, less querying is better, and now everyone seems to be being added to the new group as they post.  Thanks again for your help.

Only think to note is that Grudge's script has $user_info['posts'] > 9, and of course I needed $user_info['posts'] > 50, and you might need a different number alltogether depending on what post count you want before a member is added to the new group.

Advertisement: