Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api performance with a lot of nested objects #213

Open
nicolaspernoud opened this issue Feb 26, 2020 · 3 comments
Open

api performance with a lot of nested objects #213

nicolaspernoud opened this issue Feb 26, 2020 · 3 comments

Comments

@nicolaspernoud
Copy link

Hi, when using QOR restful API (GET something.json), it seems that if "something" has nested structs which can themselves have nested structs, the API performance is not great (several seconds per request). It seems than instead of doing joined tables requests with the mysql backend, qor does a lot of request on tables and join the data together itself. Is there a way to improve the performance ?

My structs :

type Election struct {
	gorm.Model
	Name      string
	Date      time.Time
	Areas     []Area
	FirstTour bool
}

type Area struct {
	gorm.Model
	Name           string
	ElectionID     uint
	Election       Election
	SeatNumber     uint
	MapId          uint
	Cities         []City
	CandidateLists []CandidateList
}

type City struct {
	gorm.Model
	Name   string
	AreaID uint
	Area   Area
	Desks  []Desk
	MapId  uint
}

type Desk struct {
	gorm.Model
	DeskIdentifier uint
	Name           string
	Subscribed     uint
	CityID         uint
	City           City
	Votes          []Vote
	Completed      bool
	DateCompleted  time.Time
	Validated      bool
}

type Party struct {
	gorm.Model
	Name           string
	Color          string
	CandidateLists []CandidateList
}

type CandidateList struct {
	gorm.Model
	Name       string
	PartyID    uint
	Party      Party
	AreaID     uint
	Area       Area
	Candidates []Candidate
	Votes      []Vote
}

// Candidate
type Candidate struct {
	gorm.Model
	Name                    string
	FirstName               string
	Rank                    uint
	Birthdate               time.Time
	PotentialIcompatibility bool
	Refused                 bool
	Removed                 bool
	CandidateListID         uint
}

// Vote
type Vote struct {
	gorm.Model
	CandidateListID uint
	CandidateList   CandidateList
	DeskID          uint
	Desk            Desk
	VoiceNumber     uint
	Blank           bool
	NullVote        bool
}
@lutfuahmet
Copy link

did you add index for necessary columns?

@nicolaspernoud
Copy link
Author

yes, I did...

@Clasyc
Copy link

Clasyc commented Jul 24, 2021

same issue, lets say I have 1 product in the list, response time is around 50ms, by adding 1 product response time increases linearly, where at 10 products, page takes around 500ms to load.

I enabled PostgreSQL DB logs, and response times are just 1 - 3 ms, so it's clearly an issue with implementation it self.


It seems this issue happens only on Win10, linux loading time stays the same, regards of how many items in the list.

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

No branches or pull requests

3 participants