zeeguu/core/word_scheduling/arts/bookmark_priority_updater.py
def update_bookmark_priority(cls, db, user):
        """ Update all bookmark priorities of one user

        :param db: The connection to the database
        :param user: The user object
        """
        try:
            bookmarks_for_user = user.all_bookmarks_fit_for_study()
            fit_for_study_count = len(bookmarks_for_user)

            zeeguu.core.log(f"{fit_for_study_count} bookmarks fit for study")
            if fit_for_study_count == 0:
                return

            # tuple(0=bookmark, 1=exercise)
            bookmark_exercise_of_user = map(cls._get_exercise_of_bookmark, bookmarks_for_user)
            b1, b2 = itertools.tee(bookmark_exercise_of_user, 2)

            max_iterations = max(pair.exercise.id if pair.exercise is not None else 0 for pair in b1)

            exercises_and_priorities = [cls._calculate_bookmark_priority(x, max_iterations) for x in b2]

            # with db.session.no_autoflush:  # might not be needed, but just to be safe
            for each in exercises_and_priorities:
                entry = BookmarkPriorityARTS.find_or_create(each.bookmark, each.priority)
                zeeguu.core.log(
                    f"Updating {each.bookmark.id} with priority: {each.priority} from: {entry.priority}")
                entry.priority = each.priority

                max_retries = 3

                while True:

                    try:
                        db.session.add(entry)
                        db.session.commit()
                        break
                    except IntegrityError:
                        db.session.rollback()
                        capture_message("conflict in saving bookmark priority; will retry")
                        max_retries -= 1
                        if max_retries < 1:
                            raise



        except Exception as e:
            db.session.rollback()
            capture_exception(e)
            print('Error during updating bookmark priority')
            print(e)
            print(traceback.format_exc())
 Update all bookmark priorities of one user

        :param db: The connection to the database
        :param user: The user object
        
Update all bookmark priorities of one user
Update all bookmark priorities of one user
def update_bookmark_priority(cls, db, user):
        try:
            bookmarks_for_user = user.all_bookmarks_fit_for_study()
            fit_for_study_count = len(bookmarks_for_user)
            zeeguu.core.log(f"{fit_for_study_count} bookmarks fit for study")
            if fit_for_study_count == 0:
                return
            bookmark_exercise_of_user = map(cls._get_exercise_of_bookmark, bookmarks_for_user)
            b1, b2 = itertools.tee(bookmark_exercise_of_user, 2)
            max_iterations = max(pair.exercise.id if pair.exercise is not None else 0 for pair in b1)
            exercises_and_priorities = [cls._calculate_bookmark_priority(x, max_iterations) for x in b2]
            for each in exercises_and_priorities:
                entry = BookmarkPriorityARTS.find_or_create(each.bookmark, each.priority)
                zeeguu.core.log(
                    f"Updating {each.bookmark.id} with priority: {each.priority} from: {entry.priority}")
                entry.priority = each.priority
                max_retries = 3
                while True:
                    try:
                        db.session.add(entry)
                        db.session.commit()
                        break
                    except IntegrityError:
                        db.session.rollback()
                        capture_message("conflict in saving bookmark priority; will retry")
                        max_retries -= 1
                        if max_retries < 1:
                            raise
        except Exception as e:
            db.session.rollback()
            capture_exception(e)
            print('Error during updating bookmark priority')
            print(e)
            print(traceback.format_exc())
def update_bookmark_priority ( cls , db , user ) : try : bookmarks_for_user = user . all_bookmarks_fit_for_study ( ) fit_for_study_count = len ( bookmarks_for_user ) zeeguu . core . log ( f"{fit_for_study_count} bookmarks fit for study" ) if fit_for_study_count == 0 : return bookmark_exercise_of_user = map ( cls . _get_exercise_of_bookmark , bookmarks_for_user ) b1 , b2 = itertools . tee ( bookmark_exercise_of_user , 2 ) max_iterations = max ( pair . exercise . id if pair . exercise is not None else 0 for pair in b1 ) exercises_and_priorities = [ cls . _calculate_bookmark_priority ( x , max_iterations ) for x in b2 ] for each in exercises_and_priorities : entry = BookmarkPriorityARTS . find_or_create ( each . bookmark , each . priority ) zeeguu . core . log ( f"Updating {each.bookmark.id} with priority: {each.priority} from: {entry.priority}" ) entry . priority = each . priority max_retries = 3 while True : try : db . session . add ( entry ) db . session . commit ( ) break except IntegrityError : db . session . rollback ( ) capture_message ( "conflict in saving bookmark priority; will retry" ) max_retries -= 1 if max_retries < 1 : raise except Exception as e : db . session . rollback ( ) capture_exception ( e ) print ( 'Error during updating bookmark priority' ) print ( e ) print ( traceback . format_exc ( ) )
Update all bookmark priorities of one user
Update all bookmark priorities of one user
""" Update all bookmark priorities of one user

        :param db: The connection to the database
        :param user: The user object
        """ # tuple(0=bookmark, 1=exercise) # with db.session.no_autoflush:  # might not be needed, but just to be safe
cls
db
The connection to the database
The connection to the database
user
The user object
The user object