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

Make Github stars dynamic and improve database init #5000

Merged
merged 15 commits into from
Apr 24, 2024

Conversation

ady-beraud
Copy link
Contributor

I extracted the init database logic into its own file.
You can now run it with yarn database:init.
Added database entry for GitHub stars.

Do you want me to remove the init route or is it used for something else ?

@@ -0,0 +1,390 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't want to commit that? Goal would be to get rid of sqlite

@@ -0,0 +1,4 @@
CREATE TABLE `githubStars` (
`id` text PRIMARY KEY NOT NULL,
`numberOfStars` integer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels odd to have this structure.
I would rather (1) create a more generic key/value table (e.g githubInfo with last release number, total star count, etc.).
Or (2) make this a time series table by introducing a date field (and then you only retrieve the most recent one).


console.log('Synching data..');

const query = graphql.defaults({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is related to Github, shouldn't be in the database folder. What you should do instead is isolate the logic into a folder dedicated to the Github sync. Also make sure you don't copy/paste too much code, this seems very similar to existing code in init/route.tsx?

export const AppHeader = async () => {
const githubStars = await findOne(
githubStarsModel,
desc(githubStarsModel.id),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've set a text primary key (uuid?). I guess desc() would make sense if you had an auto-incrementing integer key but here it doesn't really?

@@ -25,7 +37,9 @@ export const HeaderDesktop = () => {
Docs <ExternalArrow />
</ListItem>
<ListItem href="https://github.com/twentyhq/twenty">
<GithubIcon color="rgb(71,71,71)" /> 8.3k <ExternalArrow />
<GithubIcon color="rgb(71,71,71)" />{' '}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need {' '} ? Does this reflect a gap/margin issue?


export const HeaderDesktop = ({ numberOfStars }: Props) => {
const formatNumberOfStars = (numberOfStars: number) => {
if (numberOfStars < 1000) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully we should never need this 😁.
Makes sens if you put that function in a util (which would be nice, could be not just for stars) but since you kept it in that context it should be as short and focused on that use-case as possible

return (
<>
<HeaderDesktop />
<HeaderDesktop numberOfStars={githubStars?.[0]?.numberOfStars} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expose the formatted number of stars as an endpoint for Thomas to retrieve on Framer?

@ady-beraud
Copy link
Contributor Author

Applied the required modifications

@@ -8,7 +8,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"database:init": "npx tsx src/database/init-database.ts",
"github:sync": "npx tsx src/database/init-database.ts",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a github sync or a database init? you kept the file name init database

@@ -1,6 +1,6 @@
import { graphql } from '@octokit/graphql';

import { Repository } from '@/app/contributors/api/types';
import { Repository } from '@/github-synch/contributors/types';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

synch is an unusual name, we usually use sync or synchronization (sync is better imo)

return (
<>
<HeaderDesktop />
<HeaderDesktop numberOfStars={githubStars?.[0]?.numberOfStars} />
<HeaderMobile />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also show the number of stars on mobile?

@ady-beraud
Copy link
Contributor Author

Implemented the changes

@ady-beraud
Copy link
Contributor Author

It's working on my side, I couldn't reproduce the error. Let me know if it's working for you !

@FelixMalfait
Copy link
Member

I'm not sure it will work when rolling out it production. It didn't work for me as an upgrade to the previous migration (it does work if you start from scratch of course though). Let's merge and see!

@FelixMalfait FelixMalfait merged commit 0a7f823 into main Apr 24, 2024
7 of 8 checks passed
@FelixMalfait FelixMalfait deleted the update-github-stars branch April 24, 2024 07:44
arnavsaxena17 pushed a commit to arnavsaxena17/twenty that referenced this pull request Oct 6, 2024
I extracted the init database logic into its own file. 
You can now run it with yarn database:init.
Added database entry for GitHub stars. 

Do you want me to remove the init route or is it used for something else
?

---------

Co-authored-by: Ady Beraud <[email protected]>
Co-authored-by: Félix Malfait <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants