Notes from SymfonyOnline June 2023 - day 1
Keynote: The Scheduler Component - Fabien Potencier
- Scheduler is thin layer around existing Messenger Component infrastructure
- recurring messages are generated by special kind of messenger transport: scheduler is the transport
- generated messages are handled immediately, synchronously by default
- time of execution of the handlers influences time of handling later messages - beware: delays are possible
- adding jitter when configuring schedule is good idea:
->withJitter(seconds)
- avoid CPU usage spikes - recurring message is really like a ping that triggers a handler (think: thin event)
- redispatching messages to async transport - easy, supported, there is message wrapper for it
- consumer does all the work of generating and handling messages - transport naming convention:
scheduler_<name_from_attribute>
- be careful about running multiple workers at the same time: duplication of messages may occur - use locks on schedule or message handling level
- stateful schedule -
->stateful(cache)
- remembers when last message was generated, is able to "recover" / generate missed messages - it does not map 1:1 to traditional cron, has similarities but is more flexible and integrated with the framework
Is SOLID dead? Let's discuss reusable software design - Łukasz Chruściel
- the answer: it is not
- SOLID vs. CUPID (link, link)
- types of classes: data structures, calculations (pure, impure), side effects (impure, external)
- in reusable software: think twice on using final classes (prefer interfaces, non-final classes), in non-reusable: it does not matter that much
- doctrine repository interface with 100 methods - what's the solution?
Optimize your software with API first - Maximilian Beckers
- presentation slides, original article
- first step: think about goals, design, do not code
- talk with owners, brainstorm, try to understand, design, only then fulfill the contract with implementation
- tools: miro, egon.io, domainstorytelling.org
- define contact using Open API spec - create YAML file, use vacuum, redoc
- Open API spec - not only for HTTP API (? - but also events / messages)
- generate mocks from Open API spec: prism, wiremock, wiremock-php
- implementation example, two repos:
- one for spec only
- second for implementation of the spec - contains partly auto-generated code from spec
- use pull requests flow
- versioning, one (of many) ways:
- version in path
- different controllers / handlers per version
- publish version only on BC breaks
- thephpleague/openapi-psr7-validator
- long YAML spec - just live with it
- imports available from Open API spec v3 but not supported by tooling (yet)
Teaching Doctrine to be Lazy - Kevin Bond
- presentation slides
- hydration is expensive: control what you do, checklist:
- what do I hydrate?
- when do I hydrate?
- am I doing cleanup?
- debesha/doctrine-hydration-profiler-bundle
- hooks that allow for doctrine/native visualization of hydration in SF profiler - maybe in the future
- ocramius/doctrine-batch-utils
- BatchIterator, BatchProcessor - manage efficient iteration/processing of the data
- makes memory usage stay the same - only execution time increases, 160+MB vs 20MB
- balance of hydration and num of queries - not always makes sense to optimize num of queries
- future ideas, tools for lazy and efficient collections: zenstruck/collection
- specification pattern
AssetMapper: Manage Your JS Deps Without Node - Kévin Dunglas
- SPAs as source of complexity
- strada - mobile hybrid apps solution from hotwire guys - not released yet
- symfony ux - cool but node.js, npm, webpack - makes stuff heavy
- native JS Modules to the rescue - splitting code into reusable modules that web browsers understand
- supported by all modern browsers, by node, good cache dynamics when using HTTP2+ multiplexing
- Import Maps spec
- allows for substituting non-native module names (@turbo/whatever) to resolvable URLs
- currently needs polyfill to work
- allows for reusing npm (non non-native/commonjs js modules) in browser context
- Asset Mapper component - new SF component
- tool like composer but for JS/CSS deps, can download modules locally, can use in-flight module conversion CDNs
- embraces Import Maps spec
- inspired by importmap-rails
importmap.php
- main config file- limitations: not for SPA-like usage, currently not for JS/CSS preprocessors