Heyuri / kokonotsuba

Heyuri's BBS software
Other
19 stars 12 forks source link

Deleting posts to rewind post counter #8

Open kaguy4 opened 1 year ago

kaguy4 commented 1 year ago

Currently, each post increase the post counter, even if they are deleted and no posts are made after that

To explain with an example, if post no. 10 is registered but deleted before a post no.11 is made, the next post wouldn't replace post no.10 (as I would like it to) but continue from post no. 11. This wasn't always the case with Kokonotsuba

It would be better if it was rewinding the counter back when posts are deleted without any new is made. Heyuri especially has a severe issue of spammers who try to steal GETs, we could save them if we could count back post numbers too.

crazy4cars69 commented 1 year ago

This should be optional

shimeji87 commented 1 year ago

Wouldn't this be not-to-difficult to implement?

If I were to implement it, it compromise of:

  1. Initiating all the data & stuff for a new post
  2. Check if the previous post exists, like if the new post is of ID 300, check if a post with ID 299 exists
  3. If the previous post does not exist, assign the soon-2-be new post to the previous ID, if not - continue

In the case that multiple posts were deleted, you could probably implement this recursively

fn fixPostID(postID) {
   num = postID; 
   if (!postExists(postID - 1)) {
       fixPostID(--postID);
   }
   return;
}
shimeji87 commented 1 year ago

Would this be an efficient implementation? Since I'm not really well-versed in how the code of Kokonotsuba works I can't make it accurate to the codebase, so I haven't made it a PR - plus I'll be able to probably setup Kokonotsuba after tommorow, as I'll be back home from vacation then.

<?php
function fixPostID($id) {
    $previousExists = query("EXISTS (SELECT * FROM posts WHERE id = ($id - 1))");
    if (!$previousExists) {
        return fixPostID(--$id);
    }

    return $id;
}
?>
ghost commented 1 year ago

I just realized that it looks like the mod_rss.tmp file stores the post number for the next post. Perhaps on each delete we can decrement that number? What do y'all think about that idea? I may give it a try this weekend and see if it works depending on how much free time I have

kaguy4 commented 1 year ago

I don't know much, but would that work if a new post is made before the deletion?

This shouldn't happen:

  1. spambot makes post no 42
  2. user makes post no 43
  3. moderator deletes post no 42
  4. user makes post no 43 (wormhole is summoned)