Skip to content

Support lazy loading of Projects#53

Merged
sburns merged 2 commits intoredcap-tools:masterfrom
tjrivera:issue-52
Jul 8, 2015
Merged

Support lazy loading of Projects#53
sburns merged 2 commits intoredcap-tools:masterfrom
tjrivera:issue-52

Conversation

@tjrivera
Copy link
Copy Markdown

@tjrivera tjrivera commented Apr 8, 2015

No description provided.

@tjrivera tjrivera force-pushed the issue-52 branch 2 times, most recently from 4b9d877 to 0b1debf Compare April 8, 2015 14:54
@sburns
Copy link
Copy Markdown
Collaborator

sburns commented Apr 8, 2015

Definitely a great idea. The issue I ran into at some point is that some (most?) code paths (e.g. exporting & importing DataFrames, any file-related method) depend on the project being configured because they assume attributes like def_field, field_names, etc. So to truly maintain backwards compatibility, you'll need to self.configure() before the guts of some of these methods. Which really means that we've just moved the metadata API call from initialization to when it's actually needed. But that's the definition of lazy, right?

Perhaps a little more documentation is in order about what this means? One of the advantages of issuing metadata API call so early is that the application quickly knows if the credentials are correct and that the API is responsive.

@tjrivera
Copy link
Copy Markdown
Author

tjrivera commented Apr 8, 2015

By default initialization will still occur just as before here. If a project is initialized "lazily" a user could still get all that configuration at any time by running Project.configure()

My use case here is the use of PyCap to drive real-time interaction with REDCap in a web application. My application essentially proxies calls to REDCap for an arbitrary project. As a result the metadata calls on initialization could get pretty costly from an app performance point of view. In my case, I know most of the metadata (def_field, field_names, forms, etc) up front.

I'll try and add a bit more documentation here for clarification. Thanks for the feedback

@sburns
Copy link
Copy Markdown
Collaborator

sburns commented Apr 9, 2015

So you're going to do something like this?

lazy_project = Project('https://redcap.foo.edu/api', 'bar', lazy=True)  # super fast construction
lazy_project.def_field = 'something I know'
lazy_project.field_names = ('field_names', 'that', 'i', 'will', 'use', 'later')
# now really use the lazy_project

Because if you don't set some of these attributes on your own, some methods are going to silently break.

@tjrivera
Copy link
Copy Markdown
Author

tjrivera commented Apr 9, 2015

In my case I want to be able to quickly initialize a project and use the export_records function as a quick and easy abstraction of calls to the REDCap API. I recognize some things will fail silently, but I don't rely on those things for the majority of my calls and exporting records still behaves as I would expect.

I do recognize the confusion it might cause if one were to initialize lazily and find much of their attributes empty. I'll add some code to configure the project as necessary on certain function calls.

I guess the question then becomes -- should this be the default behavior? With Project attributes only being pulled as needed?

@sburns
Copy link
Copy Markdown
Collaborator

sburns commented Apr 9, 2015

I'd like this PR to stay as is and if you don't mind, please explore what it means to use a lazy project (ie when do you need to add attributes, when not, etc) ? It would obviously be a 2.0-type of change that should be in a separate PR.

@tjrivera tjrivera changed the title Issue 52 Support lazy loading of Projects Apr 14, 2015
Tyler Rivera added 2 commits July 8, 2015 09:21
There are situations where I'd like to make programmatic calls to a project ad-hoc but not have to pull metadata for the project on every initialization. A proposed solution would be to provide an additional keyword argument on the Project object lazy which would default to False (to preserve current behavior). Setting lazy to True would result in the Project being initialized without the metadata being pulled. Users can still export/import records and metadata, it would just be done on
demand.

Signed off by: Tyler Rivera tyler.rivera@gmail.com

Fixes redcap-tools#52
@tjrivera
Copy link
Copy Markdown
Author

tjrivera commented Jul 8, 2015

Hi Scott, I added a little more clarification as to the purpose behind lazily loading projects. Essentially it exists to quickly Initialize a Project object -- anticipating that calls to it (i.e. export_records) will occur later in the objects lifecycle. Feel free to merge if you're happy with the PR.

sburns added a commit that referenced this pull request Jul 8, 2015
Support lazy loading of Projects
@sburns sburns merged commit bd435ed into redcap-tools:master Jul 8, 2015
@sburns
Copy link
Copy Markdown
Collaborator

sburns commented Jul 8, 2015

thanks @tjrivera !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants