Skip to:
Content
Pages
Categories
Search
Top
Bottom

User Total # Post & Starded Topics without plugin

  • @7i7griffin

    Member

    I don’t like to for anything use plugin cause of that I coded this code to show any user total number of posts in topics :)

    <?php
    global $bb_table_prefix;
    $user_id=get_post_author_id();
    $query1 = "SELECT COUNT(*) FROM ".$bb_table_prefix."posts WHERE poster_id = $user_id AND post_status = 0";
    echo "<li>Posts: ".$bbdb->get_var($query1)."</li>";
    ?>

    So enjoy it :D

    EDIT: I forgot this! You must put it in post.php where the other post author information is :D

Viewing 9 replies - 1 through 9 (of 9 total)
  • @7i7griffin

    Member

    You can add this query for Total # of Topics Starded

    $query2 = "SELECT COUNT(*) FROM ".$bb_table_prefix."posts WHERE poster_id = $user_id AND post_status = 0 AND post_position = 1";
    echo "<li>Topics: ".$bbdb->get_var($query2)."</li>";

    @anointed

    Participant

    I’m curious what the side effects to such a query would be on very large sites. Myself and friends have sites with millions of topics and hundreds of thousands of users. Without caching this could be a bit of a scary function to run no?

    *I am just getting my feet wet when it comes to caching and performance, so forgive any ignorance shown :)

    **thnx for the snippets though, love seeing new contributions

    @7i7griffin

    Member

    Nope dude, can you explain me what type of scary thing?

    See bbShowcase and Persian WP forum to see it. But this is a code and they are a plugin called Post Count Plus by _ck_

    It’s just get it from database and do not cache anything.

    In Persian WP forum we have 17,121 registered user and 85,766 post :-D Check the topics for see the scary thing you said :) I repeat that is a Plugin and it’s a jus’ code that have jus’ a query :)

    @7i7griffin

    Member

    You would like to know bbPress.org jus’ have 52,283 post :)

    ** I forgot it: Yeah buddy I would like to learnin’ manything here and share what I know :) But I don’t know anything about bbPlugin :( bbPress 1.x is my game

    @anointed

    Participant

    The query is going to be run on each and every topic/reply. So a topic page with 20 authors showing would run this query 20 times on that page.

    Multiply that by hundreds of concurrent users and you have a lot of queries to handle. That is why I brought up needing to cache the output.

    I’m not saying that it is a bad query, actually I think that is exactly how to get it, just worried about performance for such little benefit is all.

    I was actually contemplating a different approach:

    1. run an initial query to count all users topics/replies and store that value in the usermeta table.

    2. append the submit topic/reply form to add to the users topic count in the usermeta table.

    3. simply call the value stored for the user and output that.

    This means that bbpress never has to do the manual counts on page load, but just pulls the number just like any other data.

    *would also need to modify system so if a topic/reply is deleted that the users count is also modified to lower their count.

    good idea?

    @7i7griffin

    Member

    Yep :-D But you must worry about the database mass, when we need to back it up for big forums you have a big volume to back up, nuh?

    Till now my theme for Persian bbPress support site is about 25 query in homepage, it’s cause of the Ajax and jQuery I used in it :-/ I don’t think for big forums a query be something that they worry about it.

    Another thing, your plugin need to count the post numbers after anypost, save it then give it out. I think it will be more heavier than this query that jus’ evoke the number :)

    Any way I jus’ cause of that write this code to have the number without plugin, cause plugins that we have now make another method and etc. that not awesome.

    But still have this mind for myself, we need to upgrade the StandAlone vr more than the bbPlugin cause anyone have not a WP installed! Someone are here that jus’ wanna a forum software! other way, bbPlugin is so awesome! :-D :-D

    @anointed

    Participant

    I have not tried the 1x vs. of bbPress, so no experience there.

    For the plugin, I actually roll my own themes from scratch, so I would not need to include a plugin for users. I would simply add the functions to my bbPress functions just like all the other custom functions I write.

    I don’t count the number on each form submit, I was simply thinking about appending a +1 to the count already stored for the users topic/reply counts on form submit. (user-x topic_count = 200)

    As to db size, yeah that is already a ‘problem’ as my db’s are huge. I really don’t know which tradeoff is better, storing the number in the db usermeta table, or doing the calculation on the fly.

    Doing it this way would only store a single entry for each user, just like the username, first-name, etc. Printing it out on the screen then takes zero effort and only a single call with zero counts needed.

    Scenario: site gets 100 new posts a day and 1000 topic page views a day

    your way — Assuming 10 topics/replies per single topic page

    10x per page X 1000 page views a day = 10,000 count calculations

    my way — Assuming 10 topics/replies per single topic page

    100 new topics/replies per day = 100 count calculations as it’s done on submit form.

    I still end up showing the 10,000 user counts, but never have to calculate the count prior to display.

    100 counts vs. 10,000 counts

    mostly just brainstorming in case JJ finds the thread and jumps in. I would love to see more counts stored in bbPress in the future.

    @7i7griffin

    Member

    Yep, the counting is the problem. but first go and see is your way possible or not. Get the # a +1 will be awesome but how will stored in database? hum?

    I have not a good knowledge about database but I know make a +1 to database is a very hard way! :-/

    My way is the way bbPress go, how? bbPress count it, store it into the database and you don’t need to store it again, jus’ get it and show it. Your way said bbPress counted it & stored it into db, ok I don’t need it. I’ll count & store it again then show it (I didn’t used bbPlugin, maybe I didn’t see what’s going on here!) but in this way countin’ will be lower but the problem is the +1 that is possible or not cause MySQLs I think have not this ability and everytime they overwrite themselves mean they recount and rewrite the metas, they are not mathmen :D

    @7i7griffin

    Member

    And something else, can your way after deleting a post reduce the number?

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
Skip to toolbar