Skip to content

refactor(adapter): fix config at construction, drop setters/getters & query logging#14

Merged
loks0n merged 1 commit into
mainfrom
feat/remove-setters-2
Jun 23, 2026
Merged

refactor(adapter): fix config at construction, drop setters/getters & query logging#14
loks0n merged 1 commit into
mainfrom
feat/remove-setters-2

Conversation

@loks0n

@loks0n loks0n commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

What

Adapter configuration is now passed via readonly constructor params instead of post-construction setters. setTenant is the one mutable exception — a single adapter serves many tenants across requests, so tenant legitimately changes over an instance's lifetime.

ClickHouse adapter

  • Setters → readonly constructor params: setNamespace, setDatabase, setSecure, setSharedTables, setAsyncInserts (→ asyncInserts + asyncInsertWait), setDualReadSampleRate. Host/port/namespace/database validation and dual-read-rate clamping moved into the constructor. New params sit after $client, so existing positional callers are unaffected.
  • Removed config-mirror getters (all unused): getNamespace, getTenant, isSharedTables.
  • Kept: setTenant, setNextQueryId (per-query runtime state), and the operational getRouteLog/clearRouteLog/getConnectionStats.

Database adapter

  • Dropped setNamespace/setSharedTables — callers configure the injected Utopia\Database instance directly (as the tests already do). Kept setTenant.

Usage facade

  • Dropped setNamespace/setSharedTables/setDualReadSampleRate (config is now construction-time). Kept setTenant (flushes buffer + delegates).

Query logging removed

The enableQueryLogging flag, queryLog, logQuery(), and getQueryLog()/clearQueryLog() are gone. A code search across appwrite + appwrite-labs found zero consumers. getConnectionStats() stays (used by tests for request_count + async flags) minus its query_logging_enabled key.

Why

Less surface area, immutable-by-default configuration, and a net −225 LoC.

⚠️ Breaking change

Consumers that call the removed setters must move that config into the constructor. Notably cloud (app/cli.php, app/worker.php) calls ->setDatabase(...) on the usage adapter:

$clickhouseAdapter = new ClickHouse(
    host: $dsn->getHost(),
    port: $dsn->getPort(),
    username: $dsn->getUser(),
    password: $dsn->getPassword(),
    secure: $secure === 'true',
    database: ltrim($dsn->getPath(), '/'), // was ->setDatabase(...)
);

A coordinated cloud update is needed before/with the release that bumps this dependency.

Test plan

  • pint --test
  • phpstan (level config) ✅
  • Non-DB unit suites (MetricTest, UsageQueryTest) ✅
  • ClickHouse/MariaDB integration tests lint + type-check clean but need live services (not run here)

🤖 Generated with Claude Code

… query logging

Adapter configuration (namespace, database, secure, sharedTables, async
inserts, dual-read sample rate) is now passed via readonly constructor
params instead of post-construction setters. Tenant remains a mutable
setter — a single adapter serves many tenants across requests.

- ClickHouse: setNamespace/setDatabase/setSecure/setSharedTables/
  setAsyncInserts/setDualReadSampleRate → constructor params; remove
  config-mirror getters (getNamespace/getTenant/isSharedTables).
- Database: drop setNamespace/setSharedTables (callers configure the
  injected Utopia\Database directly); keep setTenant.
- Usage facade: drop setNamespace/setSharedTables/setDualReadSampleRate;
  keep setTenant.
- Remove the unused query-logging feature (enableQueryLogging, queryLog,
  logQuery, getQueryLog/clearQueryLog) — not referenced in any consumer.

Net -225 LoC. BREAKING: consumers calling the removed setters (e.g. cloud's
->setDatabase()) must move that config into the constructor.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jun 23, 2026

Copy link
Copy Markdown

Greptile encountered an error while reviewing this PR. Please reach out to support@greptile.com for assistance.

@loks0n loks0n merged commit c534bfc into main Jun 23, 2026
4 checks passed
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.

1 participant