Jump to content

JLT

Members
  • Posts

    29
  • Joined

  • Last visited

Everything posted by JLT

  1. Yes, it can and currently does have an ID auto-incrementing column too, but when searching for user_id + post_id combination, that auto-incrementing field isn't utilized unless it was a back and forth situation where the anonymous user is created with a null post_id if one doesn't exist with the post_id, create the post and/or comment with that anonymous user record, update that anonymous user with the appropriate post_id if needed. It's nothing more than bad habits. Seeing an incredibly huge query along with the undesirable desire for premature optimization may be what drives the thought process. I did compare compoships vs grabbing all anonymous names, but it wasn't a fair comparison. After all, I was only checking the query duration without taking into account that the latter then has to filter out names in PHP rather than MySQL. The anonymity is optional, but what they chose will persist with the post. For instance, I chose to be anonymous for the post either when creating the post or making a comment, I cannot then comment with my real username in that post. The optional aspect seems simple enough to me, use the anonymous name if found, otherwise use the users username. If the auto-incrementing ID of the anonymous user is stored with the post / comment, it could check if the ID is present first rather than searching a table for what doesn't exist? Not certain. As for where the names come from, currently I'm just using a faker but the plan is to have a list of adjectives and nouns, and it'll pick one from each. For the sake of adding and removing words on the fly, having them stored in the database would be most ideal. The user is unable to type their own name, two users cannot have the same name in the same post, but can be given the same name in another post. BigFish from one post is completely separate to BigFish in another post. I think that answers your questions?
  2. Hi there. I have posts, post comments and users tables which are all fine in and of themselves, but I'd like users to have a unique name that's specific only to the post to hide their real username. This applies to the post itself, and the comments of the post and must remain consistent. For example, if Bill made a post with the name "BigFish", if they comment on their own post then their comments will also have that same name. Likewise, if another user comments with the name "BowlingBall", their subsequent comments will also have the same name. Now, my first attempt was to have an intermediate table of sorts, containing the post_id, user_id and display_name. This takes the appearance of a composite primary key, which are not supported in Laravel. Laravel relationships of such nature can be achieved with a package called Compoships, which does work and given the nature of the table, their resulting query being a gigantic mess of the following is reasonable at best. (post_id == ? AND user_id == ?) OR (post_id == ? AND user_id == ?) OR ... However, that can quickly scale and definitely hurts. Another way to tackle it is to retrieve all display names for each post ID, but that's then retrieving unnecessary data. It's also possible to scrap the table, store the names in the posts and post_comments tables. That's as simple as checking if the commenter is the post author and use that name, or checking if they've previously commented and use that name. I'm not sure if that's ideal either. This brings me back here, after a decade of inactivity, and I do apologise for the lengthy post. How would I go about achieving what I want to do in the best way possible? What would you do in this scenario? Thanks in advance, looking forward to y'all suggestions.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.