zeeguu/core/model/user_reading_session.py
def _close_user_reading_sessions(cls, db_session, user_id):
        """
        Finds and closes all open sessions from a specific user

        Parameters:
        db_session = database session
        user_id = user identifier to close his sessions

        returns: None

        Note: If duration is zero, the session is deleted
        """
        query = cls.query
        query = query.filter(cls.user_id == user_id)
        query = query.filter(cls.is_active == True)
        reading_sessions = query.with_for_update().all()
        for reading_session in reading_sessions:
            time_diff = reading_session.last_action_time - reading_session.start_time
            # If the duration is zero, we delete the session
            # This can happen when the user opens a session and does nothing afterwards,
            # so the timeout closes the session with a duration of zero
            if time_diff.total_seconds() == 0:
                db_session.delete(reading_session)
            else:
                reading_session.is_active = False
                reading_session.duration = (
                    time_diff.total_seconds() * 1000
                )  # Convert to miliseconds
                db_session.add(reading_session)
            db_session.commit()
        return None

        Finds and closes all open sessions from a specific user

        Parameters:
        db_session = database session
        user_id = user identifier to close his sessions

        returns: None

        Note: If duration is zero, the session is deleted
        
Finds and closes all open sessions from a specific user
Parameters:
db_session = database session
user_id = user identifier to close his sessions

None

If duration is zero, the session is deleted
Finds and closes all open sessions from a specific user Parameters : db_session = database session user_id = user identifier to close his sessions None If duration is zero the session is deleted
def _close_user_reading_sessions(cls, db_session, user_id):
        query = cls.query
        query = query.filter(cls.user_id == user_id)
        query = query.filter(cls.is_active == True)
        reading_sessions = query.with_for_update().all()
        for reading_session in reading_sessions:
            time_diff = reading_session.last_action_time - reading_session.start_time
            if time_diff.total_seconds() == 0:
                db_session.delete(reading_session)
            else:
                reading_session.is_active = False
                reading_session.duration = (
                    time_diff.total_seconds() * 1000
                )  
                db_session.add(reading_session)
            db_session.commit()
        return None
def _close_user_reading_sessions ( cls , db_session , user_id ) : query = cls . query query = query . filter ( cls . user_id == user_id ) query = query . filter ( cls . is_active == True ) reading_sessions = query . with_for_update ( ) . all ( ) for reading_session in reading_sessions : time_diff = reading_session . last_action_time - reading_session . start_time if time_diff . total_seconds ( ) == 0 : db_session . delete ( reading_session ) else : reading_session . is_active = False reading_session . duration = ( time_diff . total_seconds ( ) * 1000 ) db_session . add ( reading_session ) db_session . commit ( ) return None
Finds and closes all open sessions from a specific user
Parameters:
db_session = database session
user_id = user identifier to close his sessions
Finds and closes all open sessions from a specific user Parameters : db_session = database session user_id = user identifier to close his sessions
"""
        Finds and closes all open sessions from a specific user

        Parameters:
        db_session = database session
        user_id = user identifier to close his sessions

        returns: None

        Note: If duration is zero, the session is deleted
        """ # If the duration is zero, we delete the session # This can happen when the user opens a session and does nothing afterwards, # so the timeout closes the session with a duration of zero # Convert to miliseconds
cls
db_session
user_id