optimus icon indicating copy to clipboard operation
optimus copied to clipboard

Store should fetch only the data for table and not do it for associations

Open sbchaos opened this issue 2 years ago • 0 comments

In some of store methods, the data is queried from multiple tables, where we fetch the associations. This should not be required in most of the cases. We can simplify the code in such cases and reduce the n+1 query problem by gorm.

Example: in store/postgres/namespace_repository.go:119

	if err := repo.db.WithContext(ctx).Preload("Project").Preload("Project.Secrets").
		Where("name = ? AND project_id = ?", name, project.ID.UUID()).
		First(&r).Error; err != nil {

sbchaos avatar Jun 23 '22 10:06 sbchaos