Closed pbn4 closed 3 years ago
Public app optimizations:
Backend:
@seanmalbert Together with @bpsushi we are having problems with exposing listing in application DTO as IdDto without joining it earlier using a query builder.
Expected model:
{
...
"listing": {
"id": "..."
} (IdDto)
}
Current state is that we would like to use @RelationId
decorator to expose foreign key column to the ORM model (without joining the actual table) and build an IdDto out of that, but DTO definition is ignoring our @Expose
decorators for getter making it impossible to build listing IdDto out of listingId
(relation key).
My suspicion is that since we are extending application.entity.ts entity class (with OmitType) we are inheriting decorators for keys that are omitted too and later those are passed to class-transformer (unexpectedly). What we want to try next is geting rid of OmitType
extend/inheritance type of defining a DTO for an entity class and just put standard implements class
there + redefine all properties in it. This way we will still retain strict type checking + it will be clear what decorators and what metadata is exactly part of our DTO definition. Hopefully that will also make exposing getters work. :)
Is there more we want to do on this or can I close? @pbn4
The problem with our current setup (my subjective opinion):
Excessive memory usage when querying listings and applications because of nested joins, see issues:
The problem is two-fold: TypeORM might be better with memory usage when handling nested relations and our data model requires many JOIN operations to fetch all data requires for server response.
Querybuilder ease of use, right now to join relations we have to write something like this:
which I find problematic because this is not typed in any way and you have no guarantee that what's actually returned matches your runtime model, you have to check it yourself.
Potential solutions
Point 1 is crucial, point 2 is something we can live with eventually. I've been watching those linked issues for quite a bit now and there seems to be no progress in improving performance, neither do I feel competent to fix it myself and submit a PR to TypeORM repo, so we have two options:
Option 1. Query optimizations for Application and Listing models.
Applications
Currently we have a following query built on each application retrieval:
I think we could optimize it slightly by removing:
user
join because we do not return user information in application DTOs at alllisting
join because we only return listingId from the APIListings
We currently cannot optimize any joins:
so we solved long query time with http caching, which we will not be able to use when we introduce CMS (data changes should be reflected immediately in e.g. preview).
Option 2. Find TypeORM replacement:
This approach requires:
Finding an ORM which:
Replacing TypeORM with this new ORM:
ORMs that I'm currently researching: