Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 1 replies (of 1 total)
  • @vadimfrost09

    Participant

    Hi Luca! It sounds like you’re building a unique feature with delayed visibility for interactions—cool idea! Let me break this down for you and provide some guidance:

    1. User Interactions Visibility Logic
    You’re debating between two strategies:

    Option 1: Posts become visible after X hours.
    Option 2: Posts become visible at the next 8AM local time, but only if it’s X hours after posting.
    Implementation Thoughts
    Database-level flags: Add a visible_from datetime column to your interaction records (e.g., posts, comments, stars). This way, you calculate when they should become visible at the time of creation.

    For Option 1, set visible_from = created_at + X hours.
    For Option 2, calculate visible_from as the next 8AM that occurs at least X hours after created_at.
    Query filtering: Use this visible_from column in your database queries. For example:

    sql
    Копировать код
    SELECT * FROM interactions WHERE visible_from <= NOW();
    This ensures you’re only fetching interactions that should be visible.

    Efficient templating: Instead of adding logic in templates, handle this at the query level. Templating frameworks (e.g., Django, React) should just display what is passed to them, avoiding inefficiency in loops.

    2. Handling Email Notifications
    You want to delay email notifications about interactions while ensuring administrative emails (like password resets) remain instant.

    Approach
    Separate email queues:
    Use a task queue like Celery (Python) or Sidekiq (Ruby) to handle email sending.
    Assign different priorities or queues for email types:
    High priority: Immediate emails (e.g., password resets).
    Delayed priority: Interaction notifications, where tasks are scheduled to run after visible_from.
    Notification scheduler:
    Add logic to enqueue email notifications for interactions only after they become visible.
    For example, enqueue interaction notifications at visible_from time using delayed task execution.
    Example: Scheduling Emails
    If using Python and Celery:

    python
    Копировать код
    from datetime import timedelta
    from celery import shared_task

    @shared_task
    def send_email(user_email, interaction_id):
    # Logic to send the email notification here
    pass

    # Schedule email when an interaction is created
    interaction_time = … # ‘visible_from’ datetime from logic above
    send_email.apply_async(
    (user_email, interaction_id),
    eta=interaction_time
    )
    3. Additional Considerations
    Time zones: If you’re using local time for visibility, store interactions in UTC and calculate visible_from based on the user’s time zone.
    Edge cases: Consider scenarios like users editing their posts or comments. Decide if you want to reset the delay or leave the visibility timing as-is.
    Testing: Ensure thorough testing, especially for time zone conversions and delays, to prevent unintended visibility or email timing issues.
    Summary Workflow
    On post creation:
    Calculate and store visible_from.
    Schedule any delayed notifications for visible_from.
    On content fetch:
    Query only interactions where visible_from <= NOW().
    Use task queues to handle email delays efficiently while prioritizing admin emails.
    Let me know if you’d like examples tailored to your tech stack or further clarifications! 😊
    You can find more info at our FAQ pages.

Viewing 1 replies (of 1 total)
Skip to toolbar