# Telescope Model Hydration Analyzer PRO

Category Severity Time To Fix
🚀 Performance Major 30 minutes

Class: Enlightn\EnlightnPro\Analyzers\Performance\TelescopeModelHydrationAnalyzer

# Introduction

This analyzer scans your Telescope records to detect routes that hydrate too many models.

By default, all routes that hydrate more than 50 models are flagged.

# How To Reduce Model Hydrations

Some good practices to reduce model hydrations include:

  1. Using lazy collections (opens new window) where possible.
  2. Using query chunking (opens new window) where possible. Note that this does not reduce the number of model hydrations, but it does reduce the peak hydrations and thereby, reduces peak memory usage.
  3. Using bulk queries rather than individual queries that return hydrated models.

# Configuration Options

You can customize the limit for number of hydrated models (default: 50) using the hydration_limit configuration option:

'hydration_limit' => 50,

# Requirements

This Telescope analyzer requires you to enable the Telescope ModelWatcher and RequestWatcher.

# How To Reset Findings

This analyzer does all its calculations based on the Telescope records in the database. So, if you happen to fix a model hydration issue, you may want to prune your Telescope records so that the next time Enlightn is run, it does not pick up the routes that have already been fixed.

Generally, it would be a good practice to prune your Telescope records each time you deploy fresh code or push a new release. If your application is relatively stable, consider pruning Telescope records at a frequency (say every week or daily).

# Query Performance of Telescope Analyzers

All Telescope analyzers work by querying your database for Telescope records. For enhanced query performance, we recommend that you convert the content column of your telescope_entries table to a json data type. Note that for PostgresQL this change is mandatory, since PostgresQL does not allow json queries on text data types.

A migration code snippet on changing the column data type is provided here.

Telescope analyzer queries can take considerable time if you have a large number of Telescope records stored in your database. To further enhance performance, we recommend regularly pruning your Telescope entries.

Note that this query is only executed when you run the enlightn Artisan command and does not impact performance of your application.

# Skip Condition

This analyzer is skipped if your application does not have Laravel Telescope (opens new window) installed.

# References