-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[dashboard][server] Make Project overview page load faster by pre-fetching and caching Git provider data (branch details) #7610
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
components/gitpod-db/src/typeorm/entity/db-project-info.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright (c) 2021 Gitpod GmbH. All rights reserved. | ||
* Licensed under the Gitpod Enterprise Source Code License, | ||
* See License.enterprise.txt in the project root folder. | ||
*/ | ||
|
||
import { Entity, Column, PrimaryColumn } from "typeorm"; | ||
import { Project } from "@gitpod/gitpod-protocol"; | ||
|
||
import { TypeORM } from "../../typeorm/typeorm"; | ||
|
||
@Entity() | ||
// on DB but not Typeorm: @Index("ind_dbsync", ["_lastModified"]) // DBSync | ||
export class DBProjectInfo { | ||
|
||
@PrimaryColumn(TypeORM.UUID_COLUMN_TYPE) | ||
projectId: string; | ||
|
||
@Column({ | ||
type: 'simple-json', | ||
transformer: (() => { | ||
return { | ||
to(value: any): any { | ||
return JSON.stringify(value); | ||
}, | ||
from(value: any): any { | ||
try { | ||
const obj = JSON.parse(value); | ||
if (Project.Overview.is(obj)) { | ||
return obj; | ||
} | ||
} catch (error) { | ||
} | ||
} | ||
}; | ||
})() | ||
}) | ||
overview: Project.Overview; | ||
|
||
// This column triggers the db-sync deletion mechanism. It's not intended for public consumption. | ||
@Column() | ||
deleted: boolean; | ||
} |
18 changes: 18 additions & 0 deletions
18
components/gitpod-db/src/typeorm/migration/1642497869312-ProjectInfo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License-AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class ProjectInfo1642497869312 implements MigrationInterface { | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query("CREATE TABLE IF NOT EXISTS `d_b_project_info` ( `projectId` char(36) NOT NULL, `overview` longtext NOT NULL, `deleted` tinyint(4) NOT NULL DEFAULT '0', `_lastModified` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`projectId`), KEY `ind_dbsync` (`_lastModified`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { EncryptionService } from "@gitpod/gitpod-protocol/lib/encryption/encryp | |
import { ProjectDB } from "../project-db"; | ||
import { DBProject } from "./entity/db-project"; | ||
import { DBProjectEnvVar } from "./entity/db-project-env-vars"; | ||
import { DBProjectInfo } from "./entity/db-project-info"; | ||
|
||
function toProjectEnvVar(envVarWithValue: ProjectEnvVarWithValue): ProjectEnvVar { | ||
const envVar = { ...envVarWithValue }; | ||
|
@@ -37,6 +38,10 @@ export class ProjectDBImpl implements ProjectDB { | |
return (await this.getEntityManager()).getRepository<DBProjectEnvVar>(DBProjectEnvVar); | ||
} | ||
|
||
protected async getProjectInfoRepo(): Promise<Repository<DBProjectInfo>> { | ||
return (await this.getEntityManager()).getRepository<DBProjectInfo>(DBProjectInfo); | ||
} | ||
|
||
public async findProjectById(projectId: string): Promise<Project | undefined> { | ||
const repo = await this.getRepo(); | ||
return repo.findOne({ id: projectId, markedDeleted: false }); | ||
|
@@ -106,6 +111,12 @@ export class ProjectDBImpl implements ProjectDB { | |
project.markedDeleted = true; | ||
await repo.save(project); | ||
} | ||
// Delete any additional cached infos about this project | ||
const projectInfoRepo = await this.getProjectInfoRepo(); | ||
const info = await projectInfoRepo.findOne({ projectId, deleted: false }); | ||
if (info) { | ||
await projectInfoRepo.update(projectId, { deleted: true }); | ||
} | ||
} | ||
|
||
public async setProjectEnvironmentVariable(projectId: string, name: string, value: string, censored: boolean): Promise<void> { | ||
|
@@ -164,4 +175,19 @@ export class ProjectDBImpl implements ProjectDB { | |
const envVarsWithValues = await envVarRepo.findByIds(envVars); | ||
return envVarsWithValues; | ||
} | ||
|
||
public async findCachedProjectOverview(projectId: string): Promise<Project.Overview | undefined> { | ||
const projectInfoRepo = await this.getProjectInfoRepo(); | ||
const info = await projectInfoRepo.findOne({ projectId }); | ||
return info?.overview; | ||
} | ||
|
||
public async storeCachedProjectOverview(projectId: string, overview: Project.Overview): Promise<void> { | ||
const projectInfoRepo = await this.getProjectInfoRepo(); | ||
await projectInfoRepo.save({ | ||
projectId, | ||
overview, | ||
creationTime: new Date().toISOString(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not using for now, but let's keep it. we can add more optimization based on it. |
||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I'm using
longtext
foroverview
instead of justtext
because the (enormous) Project Overview of the GitLab repository (my stress test) wouldn't fit into a simpletext
.We could also look into trimming unnecessary information from Project Overviews, but I'd leave this as a potential future optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should look into this issue. I assume it's because of commit message length.