Closed kimdv closed 6 years ago
We are currently making multiple SQL requests when we fetch categories. First all categories, and then accessory count for each category.
This can be made in one request. I have played around with some queries, and maybe this will work
SELECT category.*, (SELECT COUNT(*) FROM accessories a WHERE a.category_id = category.id) AS accessory_count FROM category
We are doing a lot of the same around the app, fetching categories, fetching manufacturer count etc.
Can we place this somewhere in the app, so it is accessible from all the controllers?
Because if we change some params on the, lets say manufacturer count, then we need to change it multiple places in the app?
Hey @kimdv! This is great. I will take a look at this PR this upcoming week since I am a little busy, can you please point your PR to our new vapor3 branch? Master is only for stable release since it's our production environment π
Pointing to Vapor 3 branch!
There is a lot of opgimatimaztions and refactor there can be made.
Introduced a QueryHelper because a lot of queries was more or less the same. So if we decide to change one filter etc, we only need to do it one place.
We could use https://github.com/BrettRToomey/Jobs to automatically update categories with accessory count every 24 ours etc
@kimdv Can't we simply continue to use the current method which queries the DB to get the number if accessories in each category? I would try to avoid having a cron job to only count the accessories.
hmm I can revert back. But there is a lot of unnecessary requests to the db I think.
first fetch categories and afterwards fetch accessories count for each category. This can be made more efficient. :)
@kimdv I think it's important to always have an up to date DB from the user perspective. The best option to do this would be to have a trigger in the PostgreSQL DB so that every time a new object is added, the appropriate count column is updated.
Hey @kimdv! Thanks a lot for your work so far. I will have more time to work on this towards the end of the month. What's the current status of this PR?
Hi @BalestraPatrick I have had some busy months. I hope I will get some more time now.
Vapor is also more polished now, so hopefully we can finish it π
I will look into it in the follow days/weeks π
Sent with GitHawk
Hi @BalestraPatrick !
I have been working on HomeKitty and I think I have reached something we can use.
Please review when you have time, any feedback is appreciated π
Hey @kimdv, thank you so much! I am trying out the project right now but the project is crashing with this message β οΈ [PostgreSQLError.server.fatal.InitializeSessionUserId: role "test" does not exist]
.
Did you create any test table or object in your local PostgreSQL
instance?
No, you need to setup enovirement variables in you Xcode project file. They are not using json files anymore.
I am still seeing an error in the migration:
[psql] [2018-06-24 14:04:05 +0000] SELECT current_setting('server_version') AS "version" []
[ INFO ] Migrating 'psql' database (MigrationConfig.swift:69)
[psql] [2018-06-24 14:04:06 +0000] SELECT COUNT(*) AS "fluentAggregate" FROM "fluent" []
[psql] [2018-06-24 14:04:06 +0000] SELECT * FROM "fluent" ORDER BY "fluent"."batch" DESC LIMIT 1 OFFSET 0 []
β οΈ [PostgreSQLError.decode: Could not decode UUID: 6 (INTEGER).]
Can you enter the HomeKitty slack group so we can better discuss there? :) https://join.slack.com/t/homekitty/shared_invite/enQtMzg2OTk1NTc5NDI3LTYyY2QzYzYwYmIyZTk5Y2YzZjIxOTJjMGIzNDY4MTU3MWU3NWI0NGUwYTEyYzdiOGE1ODg3OTNjZDBkMGRkZDA
Hey @kimdv! I now have some time to look more into our Vapor 3 migration. Are you ok if I merge this PR into the vapor3
branch and we can then fix bugs there, and when we feel confident that it's working locally we can push it to staging in order to deploy it to our staging environment (https://homekitty-staging.herokuapp.com)?
Sure you can merge it! Iβm currently on vacation, so I canβt look into it before next week.
Sent with GitHawk
I saw that Fluent is updated and PostgresFluent will be updates this week or next week. So we can try and see if it can update with the error you had.
Sent with GitHawk
@kimdv I was able to fix the first issue with PostgreSQL but I am now encountering a few more. I'll merge this PR and then we can take care of the rest later.
Hi!
Started converting to Vapor 3, but still a lot to do!
I took my time to refactor some .leaf files because there was a lot of duplicated code.
I also refactored some routes. See manufactor, categories and accessory.
If any questions feel free to ask!
I will continue to work on it as Vapor 3 will continue to develop and more of the needed services update to Vapor 3
TODO