user_canvas_version.py


Overview

The user_canvas_version.py file defines a service class, UserCanvasVersionService, responsible for managing versions of user canvases stored in the database. It provides functionality to retrieve multiple versions associated with a specific user canvas and to clean up old versions beyond a certain threshold (20 versions).

This service extends a generic CommonService which likely provides common database operations. It interacts directly with the UserCanvasVersion database model and uses the Peewee ORM for querying and managing data.


Classes and Methods

Class: UserCanvasVersionService

Inheritance:
Inherits from CommonService

Purpose:
Manages CRUD and retrieval operations related to the UserCanvasVersion model, focusing on listing versions by canvas ID and deleting excess versions to maintain version limits.


Properties


Methods

list_by_canvas_id(cls, user_canvas_id)

@classmethod
@DB.connection_context()
def list_by_canvas_id(cls, user_canvas_id)
versions = UserCanvasVersionService.list_by_canvas_id(123)
if versions:
    for version in versions:
        print(f"Version ID: {version.id}, Title: {version.title}")
else:
    print("No versions found for this canvas.")

delete_all_versions(cls, user_canvas_id)

@classmethod
@DB.connection_context()
def delete_all_versions(cls, user_canvas_id)
result = UserCanvasVersionService.delete_all_versions(123)
if result:
    print("Old versions deleted successfully or no excess versions to delete.")
else:
    print("Failed to delete old versions or no versions found.")

Important Implementation Details


Interaction with Other System Components


Diagram: Class Structure of UserCanvasVersionService

classDiagram
    class CommonService {
        +delete_by_ids(ids: List[int])
        ...
    }

    class UserCanvasVersionService {
        +model = UserCanvasVersion
        +list_by_canvas_id(user_canvas_id: int)
        +delete_all_versions(user_canvas_id: int)
    }

    UserCanvasVersionService --|> CommonService

Summary

The user_canvas_version.py file defines a specialized service class focused on managing user canvas version records in the database. It provides methods to list all versions for a given canvas and to prune older versions beyond a limit of 20 to optimize storage and performance. This service leverages the Peewee ORM and inherits from a common service base to maximize code reuse and maintain database connection safety.


If you need further details about the UserCanvasVersion model or CommonService methods, reviewing related files in api.db would provide deeper insights.