00-database-procs.tcl

  • last updated 9 hours ago
Constraints
Constraints: committers
 
Constraints: files
Constraints: dates
Fix typo (thanks to Thomas Renner)

Cleanup not more relevant comments, remove idiom meant to work in the context of a db_with_handle we are not using anymore

Reuse already existing db_list_of_ns_sets inside db_foreach and db_list_of_lists, as it uses the most native return type: the ns_set

Operate on the original list to not incur in possible memory foortprint inflation via lrange

Exploit new -with_headers flag in db_list_of_lists to reimplement db_foreach in a way that only one db handle is used

Advantages:

- api is now transaction safe (with respect to database operations executed in the code block)

- nested db_foreach statements won't risk to occupy all available handles anymore

Possible drawbacks:

- query result needs to be completely stored inside a list before looping

- calling stack is now one level deeper...

This passes automated tests

Reduce code duplication

Introduce -with_headers flag in db_list_of_lists so names of returned column values can be returned as well as the first list in the result

Reduce code duplication (passes automated tests)

Deprecate duplicated api and replace its only occurence in upstream codebase

  1. … 2 more files in changeset.
make sure not to release handles active in an transaction, transactions are based on handles

activate usage of "ns_db currenthandles" when available

add error, when we are running out of handles

reduce verbosity, deactivate usage 'ns_db currenthandles' for now

fix typo

db_handle reform

Use "ns_db currenthandles" (when available) to implement "db_with_handle"

instead of the old approach based on the global db_state variables.

The enws approach has the advantantge that it is

- more robust (deletion and creation of the per-request variables,

no coherency problem),

- simpler, and

- faster (less overhead per db_with_handle call, simple queries up to 20% faster)

time {db_string . {select object_id from acs_objects limit 1}} 1000

old: 200-230 microseconds per iteration

new: 160-180 microseconds per iteration

Reduce code duplication (passes automated tests)

improve spelling

  1. … 15 more files in changeset.
Whitespace cleanup

Remove proc doc duplication in 'db_1row'. As the proc is essentially a wrapper for 'db_0or1row', just a pointer is better, avoiding future issues if parameters change.

prefer built-in ns_dbquotevalue over DoubleApos

  1. … 2 more files in changeset.
make former private functions, used in several packages to public functions

  1. … 4 more files in changeset.
fix typo

Port from downstream cache transaction logics and fix automated test as now db_transaction will return 0 instead of the empty string (and no particular return value should be assumed)

  1. … 1 more file in changeset.
reduce hammering on nsv for variables that never change. Use namespaced variables instead.

  1. … 3 more files in changeset.
improve spelling

  1. … 10 more files in changeset.
unify spelling of names

  1. … 3 more files in changeset.
Revert massive replacement of empty list creation sentences. The use of '[list]' instead of '{}' adds semantics that could be used for performance improvements in the future, such as using a different internal representation. There is already work in this direction, avoiding the generation of the string representation during comparison of empty strings (huge thanks to Stefan Sobernig for the pointer: https://core.tcl.tk/tcl/info/44527c632ed609c2).

  1. … 475 more files in changeset.
Rework variable assigning loops (set -> lassign) + Whitespace changes

  1. … 13 more files in changeset.
Prefer '{}' to '[list]' when creating empty lists

  1. … 71 more files in changeset.
improve documentation

  1. … 10 more files in changeset.