Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding session manager #943

Closed

Conversation

scicco
Copy link

@scicco scicco commented Oct 15, 2024

Description

This commit attempts to clean old strays after some time. Currently, the expiration check is accomplished every time a new connection is made.

Related to issue #846

How to test this

  1. Create two or three users named test<n> where n means the amount of minutes before expiration if no new connection is performed
  2. Open your favourite browser and use some extension that separates sessions from one tab to another
  3. Login with test<n> on a tab
  4. use it a little bit then wait n minutes
  5. Login with admin on another tab
  6. Go back to test<n> tab: the previous "session " of test<n> should be cleaned (the chat history should be empty)

What is missing

Currently, the cleanup and the refresh of sessions happen only when a new connection is done. We need also to refresh the expiration when a user's message arrives. I need some guidance to understand where is the right place to invoke refresh on the code, I think the call should go in some line of

async def __call__(self, message_dict):

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

@zAlweNy26
Copy link
Member

Wrong target branch, please point to develop

@scicco
Copy link
Author

scicco commented Oct 15, 2024

Wrong target branch, please point to develop

oh you're right, sorry, I'll fix it

@scicco scicco changed the base branch from main to develop October 15, 2024 19:29
@scicco scicco force-pushed the feature/session_manager branch from 8bc5cfc to 6901632 Compare October 15, 2024 19:31
@pieroit
Copy link
Member

pieroit commented Oct 15, 2024

Awesome.
Will review in a few days, thanks

@scicco scicco force-pushed the feature/session_manager branch 17 times, most recently from 074fb78 to dd49557 Compare October 15, 2024 21:37
@pieroit
Copy link
Member

pieroit commented Nov 1, 2024

@scicco tried to do a review but I guess we must pseudocode first and have a better design (my bad). I should also explain to you a few things on cat inner workings ;)

Thanks a lot, sorry for closing let's try again

@pieroit pieroit closed this Nov 1, 2024
@@ -111,6 +144,10 @@ async def get_user_stray(self, user: AuthUserInfo, connection: Request) -> Stray
# TODOV2: user_id should be the user.id
user_id=user.name, user_data=user, main_loop=event_loop
)

self.refresh_user_expiration(connection, user)
Copy link
Member

Choose a reason for hiding this comment

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

Hi @scicco thanks
Does not sound good to me that this methods are called from all child classes
Can't they be run in parent class at Connection.__call__ jut after get_user_stray is called?

Let me know if I'm not getting something

Copy link
Author

@scicco scicco Nov 2, 2024

Choose a reason for hiding this comment

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

you are right, it's better to move them on parent class


# then we create a new session
self.sessions[current_time] = {"user_id": user.id, "name": user.name}
pass
Copy link
Member

Choose a reason for hiding this comment

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

why pass? It does nothing ;)


current_time = datetime.now(timezone.utc) + timedelta(minutes=minutes)

# if user_id is already in the session we removed it first
Copy link
Member

Choose a reason for hiding this comment

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

having a hard time understanding what you are doing here

also, self.strays is already a dictionary in which keys are the id? Why loop over timestamps, if they are not even sorted? Sorry cannot understand

# user: test4 will expire after 4 minutes
# and so on
#
if "test" in user.name:
Copy link
Member

Choose a reason for hiding this comment

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

I cannot accept this sorry 😔
Tests should not be in cat code, should be in the test suite

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.

3 participants