Skip to content

Unified query api#158

Open
bmaranville wants to merge 8 commits intomainfrom
unified-query-api
Open

Unified query api#158
bmaranville wants to merge 8 commits intomainfrom
unified-query-api

Conversation

@bmaranville
Copy link
Copy Markdown
Contributor

@bmaranville bmaranville commented Mar 26, 2026

In this PR

  • the slddb query functions are consolidated to go through SLD_API.search(**opts)
  • the functions to support webquery and blender are moved from the SLDDB codebase to here (orsopy.slddb)
  • the SLD_API.localquery is refactored so it takes the same qdict argument as webquery
  • SLD_API.use_webquery defaults to False
  • SLD_API.update_db defaults to True
  • this function then routes the request to either
    • a webquery to the SLDDB server (if api.use_webquery == True) or
    • a localquery, using the local copy of the db file

Default configuration

The combination of use_webquery=False and update_db=True means that, in the default configuration, this will happen:

  • the first time a query is performed, the database age will be checked
  • if it is older than max_age, a new copy is downloaded from the SLDDB server
  • after that, all searches are local and use this refreshed copy of the database.

SLDDB-server independent configuration

If you set SLD_API.update_db = False before your first search (typically by doing orsopy.slddb.api.update_db = False), then no attempt is made to download a new copy of the database, and you use the version you currently have.

Webquery-preferred configuration

This is the currently the default in the released orsopy - orsopy.slddb.api.use_webquery = True, and it only falls back to the local db if the webquery fails. Every lookup then goes to the central SLDDB server.

@bmaranville
Copy link
Copy Markdown
Contributor Author

The corresponding PR to remove the functions that were copied from SLDDB to here has not been made yet... in the SLDDB server code they'll be replaced by imports from here.

Copy link
Copy Markdown
Collaborator

@aglavic aglavic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to put this all in one place. I'd not remove the default webquery, though.

Comment thread orsopy/slddb/blender.py
m = db.select_material(entry)
loaded_ids[ID] = m
elements.append(number * loaded_ids[ID])
result = elements[0]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be simply return sum(elements) ?

Comment thread orsopy/slddb/blender.py
result += element
return result


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd propose to do this simply by using a dictionary of collect functions and .get:

COLLECT_FUNCTIONS = {
  "protein": collect_protein,
  "dna": collect_dna,
  "rna": collect_rna,
  "db": collect_blendIDs,
}

Comment thread orsopy/slddb/webapi.py

def __init__(self):
self.first_access = True
self.use_webquery = True # only try webquery once, if error occurs switch to local database
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making the default just a DB download will break the SLDdb statistical functions that are used to improve search results. (I.e. return most searched and most selected materials, first.)

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