Skip to main content

Copy of some Draft Web Development Guidelines

Run fewer, simpler queries as possible

Making multiple requests whether HTTP or within a database has a carbon cost as infrastructure has to send that information back and forth. As such, managing how you store and use data locally for a visitor will help reduce wasted cycles.

Criteria: Database queries

Human-testable

If you need information that is stored in a database, and you require it (or it's likely to be requested) more than once in your code, access the database only once, and store the data locally for subsequent processing. Also, avoid reliance on framework helpers that might defer filtering to later on in the process.

Resources

Impact: Medium, Effort: Low

GRI Impact of Run fewer, simpler queries as possible
GRI Impact
materials Low
energy Low
water Low
emissions Low
Benefits of this guideline
  • Environment: Filtering out unneeded data at a deeper level of the application may reduce energy usage, as less processing is required for (de)serialization.
  • Performance: By holding the data locally rather than remotely, you can avoid waiting for an additional HTTP request to occur to process the string. Relational databases and other specialist data stores are generally heavily optimized for data filtering and retrieval. Performing transformations at this level of the application may lead to reduced CPU time and faster responses.
  • Economic: Rather than pushing multiple additional demands to the server (which could lead to stress failures and lost business), an optimized codebase can reduce bandwidth overheads.

Example
  • code $value = get_post_meta( int $post_id, string $key = '', bool $single = false ): mixed
  • content get_post_meta Function.

Tags: