summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-02-13 21:16:08 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2010-02-13 21:16:08 +0000
commitaedcd6aea6aa3b4601bbc26f5fc23c084c8996ac (patch)
treebcf773463439c124b0ea8c655e3ac461c26686b5 /test
parentf4573f73d0c7f7ce5b184e6c227d0e4f406643a5 (diff)
downloadsqlalchemy-aedcd6aea6aa3b4601bbc26f5fc23c084c8996ac.tar.gz
- reduced a bit of overhead in attribute expiration, particularly
the version called by column loaders on an incomplete row (i.e. joined table inheritance). there are more dramatic changes that can be made here but this one is conservative so far as far as how much we're altering how InstanceState tracks "expired" attributes.
Diffstat (limited to 'test')
-rw-r--r--test/orm/test_attributes.py14
-rw-r--r--test/orm/test_extendedattr.py8
-rw-r--r--test/perf/objselectspeed.py37
3 files changed, 47 insertions, 12 deletions
diff --git a/test/orm/test_attributes.py b/test/orm/test_attributes.py
index c69021aa3..e6041d566 100644
--- a/test/orm/test_attributes.py
+++ b/test/orm/test_attributes.py
@@ -142,21 +142,21 @@ class AttributesTest(_base.ORMTest):
attributes.register_attribute(Foo, 'b', uselist=False, useobject=False)
f = Foo()
- attributes.instance_state(f).expire_attributes(None)
+ attributes.instance_state(f).expire_attributes(attributes.instance_dict(f), None)
eq_(f.a, "this is a")
eq_(f.b, 12)
f.a = "this is some new a"
- attributes.instance_state(f).expire_attributes(None)
+ attributes.instance_state(f).expire_attributes(attributes.instance_dict(f), None)
eq_(f.a, "this is a")
eq_(f.b, 12)
- attributes.instance_state(f).expire_attributes(None)
+ attributes.instance_state(f).expire_attributes(attributes.instance_dict(f), None)
f.a = "this is another new a"
eq_(f.a, "this is another new a")
eq_(f.b, 12)
- attributes.instance_state(f).expire_attributes(None)
+ attributes.instance_state(f).expire_attributes(attributes.instance_dict(f), None)
eq_(f.a, "this is a")
eq_(f.b, 12)
@@ -182,7 +182,7 @@ class AttributesTest(_base.ORMTest):
attributes.register_attribute(MyTest, 'b', uselist=False, useobject=False)
m = MyTest()
- attributes.instance_state(m).expire_attributes(None)
+ attributes.instance_state(m).expire_attributes(attributes.instance_dict(m), None)
assert 'a' not in m.__dict__
m2 = pickle.loads(pickle.dumps(m))
assert 'a' not in m2.__dict__
@@ -355,7 +355,7 @@ class AttributesTest(_base.ORMTest):
x.bars
b = Bar(id=4)
b.foos.append(x)
- attributes.instance_state(x).expire_attributes(['bars'])
+ attributes.instance_state(x).expire_attributes(attributes.instance_dict(x), ['bars'])
assert_raises(AssertionError, b.foos.remove, x)
@@ -1294,7 +1294,7 @@ class HistoryTest(_base.ORMTest):
eq_(attributes.get_state_history(attributes.instance_state(f), 'bars'), ([bar4], [], []))
lazy_load = [bar1, bar2, bar3]
- attributes.instance_state(f).expire_attributes(['bars'])
+ attributes.instance_state(f).expire_attributes(attributes.instance_dict(f), ['bars'])
eq_(attributes.get_state_history(attributes.instance_state(f), 'bars'), ((), [bar1, bar2, bar3], ()))
def test_collections_via_lazyload(self):
diff --git a/test/orm/test_extendedattr.py b/test/orm/test_extendedattr.py
index 685be3a5f..4374b9ecb 100644
--- a/test/orm/test_extendedattr.py
+++ b/test/orm/test_extendedattr.py
@@ -161,21 +161,21 @@ class UserDefinedExtensionTest(_base.ORMTest):
assert Foo in attributes.instrumentation_registry._state_finders
f = Foo()
- attributes.instance_state(f).expire_attributes(None)
+ attributes.instance_state(f).expire_attributes(attributes.instance_dict(f), None)
eq_(f.a, "this is a")
eq_(f.b, 12)
f.a = "this is some new a"
- attributes.instance_state(f).expire_attributes(None)
+ attributes.instance_state(f).expire_attributes(attributes.instance_dict(f), None)
eq_(f.a, "this is a")
eq_(f.b, 12)
- attributes.instance_state(f).expire_attributes(None)
+ attributes.instance_state(f).expire_attributes(attributes.instance_dict(f), None)
f.a = "this is another new a"
eq_(f.a, "this is another new a")
eq_(f.b, 12)
- attributes.instance_state(f).expire_attributes(None)
+ attributes.instance_state(f).expire_attributes(attributes.instance_dict(f), None)
eq_(f.a, "this is a")
eq_(f.b, 12)
diff --git a/test/perf/objselectspeed.py b/test/perf/objselectspeed.py
index e04ef4efb..d3fd34046 100644
--- a/test/perf/objselectspeed.py
+++ b/test/perf/objselectspeed.py
@@ -8,21 +8,44 @@ db = create_engine('sqlite://')
metadata = MetaData(db)
Person_table = Table('Person', metadata,
Column('id', Integer, primary_key=True),
+ Column('type', String(10)),
Column('name', String(40)),
Column('sex', Integer),
Column('age', Integer))
+
+Employee_table = Table('Employee', metadata,
+ Column('id', Integer, ForeignKey('Person.id'), primary_key=True),
+ Column('foo', String(40)),
+ Column('bar', Integer),
+ Column('bat', Integer))
+
class RawPerson(object): pass
class Person(object): pass
mapper(Person, Person_table)
+
+class JoinedPerson(object):pass
+class Employee(JoinedPerson):pass
+mapper(JoinedPerson, Person_table, \
+ polymorphic_on=Person_table.c.type, polymorphic_identity='person')
+mapper(Employee, Employee_table, \
+ inherits=JoinedPerson, polymorphic_identity='employee')
compile_mappers()
def setup():
metadata.create_all()
i = Person_table.insert()
- data = [{'name':'John Doe','sex':1,'age':35}] * 100
+ data = [{'name':'John Doe','sex':1,'age':35, 'type':'employee'}] * 100
for j in xrange(500):
i.execute(data)
+
+ # note we arent fetching from employee_table,
+ # so we can leave it empty even though its "incorrect"
+ #i = Employee_table.insert()
+ #data = [{'foo':'foo', 'bar':'bar':'bat':'bat'}] * 100
+ #for j in xrange(500):
+ # i.execute(data)
+
print "Inserted 50,000 rows"
def sqlite_select(entity_cls):
@@ -55,6 +78,11 @@ def orm_select():
session = create_session()
people = session.query(Person).all()
+#@profiling.profiled(report=True, always=True)
+def joined_orm_select():
+ session = create_session()
+ people = session.query(JoinedPerson).all()
+
def all():
setup()
try:
@@ -103,6 +131,13 @@ def all():
orm_select()
t2 = time.clock()
usage('sqlalchemy.orm fetch')
+
+ gc_collect()
+ usage.snap()
+ t = time.clock()
+ joined_orm_select()
+ t2 = time.clock()
+ usage('sqlalchemy.orm "joined" fetch')
finally:
metadata.drop_all()