Skip to content

Commit

Permalink
Optimizes sqlalchemy_utils imports
Browse files Browse the repository at this point in the history
Importing functions from slqalchemy_utils directly causes the entire
library to get imported, even though many of the library's modules go
unused. Using more-focused imports should improve initialization time in
performance-sensitive situations.

This commit also removes a few unused imports.

Closes #357
  • Loading branch information
mfulgo committed Jul 30, 2024
1 parent 91730be commit 3eda9e6
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sqlalchemy_continuum/fetcher.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import operator
import sqlalchemy as sa
from sqlalchemy_utils import get_primary_keys, identity
from sqlalchemy_utils.functions.orm import get_primary_keys, identity
from .utils import tx_column_name, end_tx_column_name


Expand Down
4 changes: 1 addition & 3 deletions sqlalchemy_continuum/manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import re
from functools import wraps

import sqlalchemy as sa
from sqlalchemy.orm import object_session
from sqlalchemy_utils import get_column_key
from sqlalchemy_utils.functions import get_column_key

from .builder import Builder
from .fetcher import SubqueryFetcher, ValidityFetcher
Expand Down Expand Up @@ -454,4 +453,3 @@ def track_association_operations(
'operation_type': op,
})
uow.pending_statements.append(stmt)

2 changes: 1 addition & 1 deletion sqlalchemy_continuum/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections import OrderedDict

import sqlalchemy as sa
from sqlalchemy_utils import identity
from sqlalchemy_utils.functions.orm import identity


class Operation(object):
Expand Down
5 changes: 3 additions & 2 deletions sqlalchemy_continuum/plugins/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@
import sqlalchemy as sa
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.inspection import inspect
from sqlalchemy_utils import JSONType, generic_relationship
from sqlalchemy_utils.generic import generic_relationship
from sqlalchemy_utils.types.json import JSONType

from .base import Plugin
from ..factory import ModelFactory
Expand Down Expand Up @@ -318,7 +319,7 @@ def target_version_type(cls):

class ActivityPlugin(Plugin):
activity_cls = None

def after_build_models(self, manager):
self.activity_cls = ActivityFactory()(manager)
manager.activity_cls = self.activity_cls
Expand Down
2 changes: 1 addition & 1 deletion sqlalchemy_continuum/plugins/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from flask import current_app, has_app_context, has_request_context, request
except ImportError:
pass
from sqlalchemy_utils import ImproperlyConfigured
from sqlalchemy_utils.exceptions import ImproperlyConfigured

from .base import Plugin

Expand Down
1 change: 0 additions & 1 deletion sqlalchemy_continuum/table_builder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sqlalchemy as sa
from sqlalchemy_utils import get_column_key


class ColumnReflector(object):
Expand Down
2 changes: 1 addition & 1 deletion sqlalchemy_continuum/unit_of_work.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from copy import copy

import sqlalchemy as sa
from sqlalchemy_utils import get_primary_keys, identity
from sqlalchemy_utils.functions.orm import get_primary_keys, identity
from .operation import Operations
from .utils import (
end_tx_column_name,
Expand Down

0 comments on commit 3eda9e6

Please sign in to comment.