diff options
| author | Dan Krause <dan.krause@rackspace.com> | 2015-03-10 21:42:53 -0500 |
|---|---|---|
| committer | Dan Krause <dan.krause@rackspace.com> | 2015-03-11 15:57:07 -0500 |
| commit | 9f64c47cb74b27c40135fff79e23d2bd1c6acfdd (patch) | |
| tree | f980c7cb76aea3cd53ca5da1e19d401a6b62a0b2 /taskflow/persistence/backends/impl_sqlalchemy.py | |
| parent | f9e520679a5d95ed1a3292296a4b736cdd5b7387 (diff) | |
| download | taskflow-9f64c47cb74b27c40135fff79e23d2bd1c6acfdd.tar.gz | |
lazy loading for logbooks and flowdetails
You can now specify a "lazy" argument when asking a
persistence backend for a logbook for flowdetail.
This will return a logbook with no flowdetails in it,
or a flowdetail with no atomdetails in it, respectively.
Change-Id: Ie81a19a2107b44e2c35c2a92507bec03eee55c50
Diffstat (limited to 'taskflow/persistence/backends/impl_sqlalchemy.py')
| -rw-r--r-- | taskflow/persistence/backends/impl_sqlalchemy.py | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/taskflow/persistence/backends/impl_sqlalchemy.py b/taskflow/persistence/backends/impl_sqlalchemy.py index 4368b78..d4f343f 100644 --- a/taskflow/persistence/backends/impl_sqlalchemy.py +++ b/taskflow/persistence/backends/impl_sqlalchemy.py @@ -527,7 +527,7 @@ class Connection(base.Connection): raise exc.StorageFailure("Failed saving logbook" " '%s'" % book.uuid, e) - def get_logbook(self, book_uuid): + def get_logbook(self, book_uuid, lazy=False): try: logbooks = self._tables.logbooks with contextlib.closing(self._engine.connect()) as conn: @@ -538,40 +538,42 @@ class Connection(base.Connection): raise exc.NotFound("No logbook found with" " uuid '%s'" % book_uuid) book = self._converter.convert_book(row) - self._converter.populate_book(conn, book) + if not lazy: + self._converter.populate_book(conn, book) return book except sa_exc.DBAPIError as e: raise exc.StorageFailure( "Failed getting logbook '%s'" % book_uuid, e) - def get_logbooks(self): + def get_logbooks(self, lazy=False): gathered = [] try: with contextlib.closing(self._engine.connect()) as conn: q = sql.select([self._tables.logbooks]) for row in conn.execute(q): book = self._converter.convert_book(row) - self._converter.populate_book(conn, book) + if not lazy: + self._converter.populate_book(conn, book) gathered.append(book) except sa_exc.DBAPIError as e: raise exc.StorageFailure("Failed getting logbooks", e) for book in gathered: yield book - def get_flows_for_book(self, book_uuid): + def get_flows_for_book(self, book_uuid, lazy=False): gathered = [] try: with contextlib.closing(self._engine.connect()) as conn: - for row in self._converter.flow_query_iter(conn, book_uuid): - flow_details = self._converter.populate_flow_detail(conn, - row) - gathered.append(flow_details) + for fd in self._converter.flow_query_iter(conn, book_uuid): + if not lazy: + self._converter.populate_flow_detail(conn, fd) + gathered.append(fd) except sa_exc.DBAPIError as e: raise exc.StorageFailure("Failed getting flow details", e) for flow_details in gathered: yield flow_details - def get_flow_details(self, fd_uuid): + def get_flow_details(self, fd_uuid, lazy=False): try: flowdetails = self._tables.flowdetails with self._engine.begin() as conn: @@ -581,7 +583,10 @@ class Connection(base.Connection): if not row: raise exc.NotFound("No flow details found with uuid" " '%s'" % fd_uuid) - return self._converter.convert_flow_detail(row) + fd = self._converter.convert_flow_detail(row) + if not lazy: + self._converter.populate_flow_detail(conn, fd) + return fd except sa_exc.SQLAlchemyError as e: raise exc.StorageFailure("Failed getting flow details with" " uuid '%s'" % fd_uuid, e) @@ -601,5 +606,16 @@ class Connection(base.Connection): raise exc.StorageFailure("Failed getting atom details with" " uuid '%s'" % ad_uuid, e) + def get_atoms_for_flow(self, fd_uuid): + gathered = [] + try: + with contextlib.closing(self._engine.connect()) as conn: + for ad in self._converter.atom_query_iter(conn, fd_uuid): + gathered.append(ad) + except sa_exc.DBAPIError as e: + raise exc.StorageFailure("Failed getting atom details", e) + for atom_details in gathered: + yield atom_details + def close(self): pass |
