Skip to content

Conversation

@pheller
Copy link
Member

@pheller pheller commented Sep 8, 2025

  • cache list of message ids in session on client entry to mailbox (when mailbox page 1 is retrieved)
  • client message indexes are offsets into this cached list
  • if client leaves and comes back to mailbox, client requests page 1 again, refreshing the cache

@pheller pheller force-pushed the fix-messages branch 3 times, most recently from b0c30ce to 67935c8 Compare September 8, 2025 04:21
- cache list of message ids in session on client entry to mailbox (when mailbox page 1 is retrieved)
- client message indexes are offsets into this cached list
- if client leaves and comes back to mailbox, client requests page 1 again, refreshing the cache
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the mailbox schema to address session-based message indexing. The key change is moving from database-stored sequential indexes to session-cached message IDs, allowing client message indexes to be offsets into a cached list that refreshes when entering the mailbox.

  • Replaces composite primary key (to_id, index) with auto-incrementing id field in messages
  • Implements session-based message ID caching that loads on mailbox page 1 requests
  • Updates message operations to use client indices as offsets into the cached message ID list

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
apps/server/lib/prodigy/server/session.ex Adds messaging field to session struct for caching message IDs
apps/server/lib/prodigy/server/service/messaging.ex Core refactor implementing session-based indexing and message ID caching
apps/core/lib/prodigy/core/data/message.ex Removes composite primary key and index field from Message schema
apps/core/priv/repo/migrations/20250907183440_fix_message_ids.exs Database migration to replace composite key with auto-incrementing id
apps/server/test/prodigy/server/service/messaging_test.exs Updates tests to reflect new client indexing behavior and verify correct message operations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@pheller pheller requested a review from Copilot September 10, 2025 23:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

apps/server/lib/prodigy/server/service/messaging.ex:1

  • The pattern match _ -> catches all non-{:ok, payload} responses including errors, but always returns {:ok, session}. This could mask actual errors. Consider explicitly handling :ok responses and error cases separately.
# Copyright 2022, Phillip Heller

apps/server/lib/prodigy/server/service/messaging.ex:344

  • The unhandled case returns {:ok, <<0>>} but should return {session, {:ok, <<0>>}} to match the expected tuple format used throughout the function.
          Logger.warn(
            "unhandled messaging request: #{inspect(request, base: :hex, limit: :infinity)}"
          )

          {:ok, <<0>>}

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@pheller pheller merged commit f4ef534 into ProdigyReloaded:main Sep 10, 2025
1 check passed
@pheller pheller deleted the fix-messages branch September 11, 2025 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant