<commit_before>from app import db

import datetime
import uuid

class UserSession(db.Model):
    __tablename__ = 'user_sessions'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, nullable=False)
    hash = db.Column(db.String(32), unique=True, nullable=False)
    created_date = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    
    def __init__(self, user_id):
        self.user_id = user_id
        self.hash = str(uuid.uuid4().get_hex())
        
    def __repr__(self):
        return '<UserSession(user_id=%r, hash=%s)>' % (self.user_id, self.hash)
    
    def commit(self):
        db.session.add(self)
        db.session.commit()<commit_msg>switched from uuid to base64 utf-8 encoded urandom(24) for generating access tokens<commit_after>from app import db

from os import urandom
from base64 import b64encode
import datetime

class UserSession(db.Model):
    __tablename__ = 'user_sessions'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, nullable=False)
    hash = db.Column(db.String(32), unique=True, nullable=False)
    created_date = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    
    def __init__(self, user_id):
        self.user_id = user_id
        self.hash = b64encode(urandom(24)).decode('utf-8')
        
    def __repr__(self):
        return '<UserSession(user_id=%r, hash=%s)>' % (self.user_id, self.hash)
    
    def commit(self):
        db.session.add(self)
        db.session.commit()
{'fraction_non_alphanumeric': 0.12343234323432344, 'fraction_numerical': 0.012541254125412541, 'mean_word_length': 3.343839541547278, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2247989', 'n_tokens_mistral': 519, 'n_tokens_neox': 510, 'n_words': 102}