Roux.QueryLog (roux v0.2.2)

Copy Markdown View Source

Records which queries of a database executed, were served from the memo table, or came back unchanged (early cutoff): what an edit made a graph recompute, for tests that assert the exact recompute set and for harnesses that report it.

log = Roux.QueryLog.start(db)
Roux.Input.set(db, :source, "a.ex", "changed")
MyQueries.compile(db, "a.ex")
assert Roux.QueryLog.executions(log, :parse) == ["a.ex"]
assert Roux.QueryLog.cutoffs(log, :parse) == ["a.ex"]
Roux.QueryLog.stop(log)

One database

A log started for a database records only that database's events (the database: metadata every event carries, Roux.Database.id/1), so tests running side by side in one VM each see their own queries. start(:all) records every database's: for a harness that drives code which opens its database itself, such as a Mix compiler.

Lifetime

The events land in a public ETS table owned by a process of the log's own, not linked to the caller: a test can stop/1 it from an on_exit callback, after the test process has exited. The handler the log attaches is VM-global until stop/1 detaches it.

Summary

Types

What happened to a query key: it executed, was served, or cut off.

t()

A running log; see start/1.

Functions

Every query that kind happened to, as %{query_name => keys}, each key list sorted: the whole window, for a harness that reports it.

The keys of query_name that executed and came back unchanged, sorted.

The keys of query_name that executed, sorted.

The keys of query_name served from the memo table without executing, sorted.

Forgets everything recorded so far: the start of a new window.

Starts a log of db's queries, or of every database's with :all.

Detaches the log's handler and deletes its table. Safe to call from any process, and more than once.

Types

kind()

@type kind() :: :execution | :hit | :cutoff

What happened to a query key: it executed, was served, or cut off.

t()

@type t() :: %Roux.QueryLog{
  database: Roux.Database.id() | :all,
  handler: term(),
  owner: pid(),
  ref: reference(),
  table: :ets.tid()
}

A running log; see start/1.

Functions

by_query(query_log, kind)

@spec by_query(t(), kind()) :: %{optional(atom()) => [term()]}

Every query that kind happened to, as %{query_name => keys}, each key list sorted: the whole window, for a harness that reports it.

cutoffs(log, query_name)

@spec cutoffs(t(), atom()) :: [term()]

The keys of query_name that executed and came back unchanged, sorted.

executions(log, query_name)

@spec executions(t(), atom()) :: [term()]

The keys of query_name that executed, sorted.

hits(log, query_name)

@spec hits(t(), atom()) :: [term()]

The keys of query_name served from the memo table without executing, sorted.

reset(query_log)

@spec reset(t()) :: :ok

Forgets everything recorded so far: the start of a new window.

start(db_or_all)

@spec start(Roux.Database.t() | :all) :: t()

Starts a log of db's queries, or of every database's with :all.

stop(query_log)

@spec stop(t()) :: :ok

Detaches the log's handler and deletes its table. Safe to call from any process, and more than once.