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

Refactor repository #149

Merged
merged 59 commits into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
3c82f2f
fix: nits
h13i32maru Jul 31, 2020
238bfc2
refactor(StreamRepo):
h13i32maru Jul 31, 2020
138cd93
refactor(StreamRepo):
h13i32maru Jul 31, 2020
7dfa9c6
refactor(StreamRepo):
h13i32maru Aug 1, 2020
adcbd23
refactor(StreamRepo):
h13i32maru Aug 1, 2020
2bad1d3
refactor(StreamRepo):
h13i32maru Aug 1, 2020
50c1584
refactor(StreamRepo):
h13i32maru Aug 1, 2020
dc07165
refactor(StreamRepo):
h13i32maru Aug 1, 2020
1ca4bf6
refactor(StreamRepo):
h13i32maru Aug 1, 2020
c88fea0
refactor(StreamRepo):
h13i32maru Aug 1, 2020
f5081be
refactor(StreamRepo):
h13i32maru Aug 1, 2020
e57bb00
refactor(StreamRepo):
h13i32maru Aug 1, 2020
eb726e5
refactor(StreamRepo):
h13i32maru Aug 1, 2020
ae12f7d
refactor(StreamRepo):
h13i32maru Aug 1, 2020
ca4b6bb
refactor(StreamRepo):
h13i32maru Aug 1, 2020
c6c26fd
refactor(FilterHistoryRepo):
h13i32maru Aug 1, 2020
9c37bed
refactor(FilterHistoryRepo):
h13i32maru Aug 1, 2020
0df5a99
refactor(StreamRepo):
h13i32maru Aug 1, 2020
de9adf3
refactor(StreamIssueRepo):
h13i32maru Aug 1, 2020
498447d
refactor:
h13i32maru Aug 1, 2020
67f7e7c
refactor(StreamIssueRepo):
h13i32maru Aug 1, 2020
5d17553
refactor(StreamIssueRepo):
h13i32maru Aug 1, 2020
a9e1f5e
refactor(SubscriptionIssueRepo):
h13i32maru Aug 1, 2020
c9496ac
refactor(SystemStreamRepo):
h13i32maru Aug 1, 2020
1ff6872
refactor(SystemStreamRepo):
h13i32maru Aug 1, 2020
933087b
refactor(SystemStreamRepo):
h13i32maru Aug 1, 2020
c3eee22
fix(Stream): query index calc
h13i32maru Aug 1, 2020
2e76678
refactor(SystemStreamRepo):
h13i32maru Aug 1, 2020
8a9af6d
refactor(SystemStreamRepo):
h13i32maru Aug 1, 2020
5b4678d
refactor(SystemStreamRepo):
h13i32maru Aug 1, 2020
be72387
refactor(SystemStreamRepo):
h13i32maru Aug 1, 2020
54b1f49
refactor(StreamPolling):
h13i32maru Aug 1, 2020
8bb448b
refactor(SystemStreamRepo):
h13i32maru Aug 1, 2020
9d10f56
refactor(SystemStreamRepo):
h13i32maru Aug 1, 2020
e135662
refactor(IssueRepo):
h13i32maru Aug 1, 2020
efceb1f
refactor(IssueRepo):
h13i32maru Aug 1, 2020
4e4059d
refactor(IssueRepo):
h13i32maru Aug 1, 2020
2b7e4ce
refactor(IssueRepo):
h13i32maru Aug 1, 2020
30f82e5
refactor(IssueRepo):
h13i32maru Aug 1, 2020
8d245b9
refactor(IssueRepo):
h13i32maru Aug 1, 2020
f0d0d98
refactor(IssueRepo):
h13i32maru Aug 1, 2020
0730d1e
refactor(IssueRepo):
h13i32maru Aug 1, 2020
457a361
refactor(IssueRepo):
h13i32maru Aug 1, 2020
59168df
refactor(VersionRepo):
h13i32maru Aug 1, 2020
8e2c123
refactor(IssueRepo):
h13i32maru Aug 1, 2020
3d9d5d6
refactor(IssueRepo):
h13i32maru Aug 1, 2020
19e50f8
refactor(IssueRepo):
h13i32maru Aug 1, 2020
bff9d34
refactor(IssueRepo):
h13i32maru Aug 1, 2020
b44e56c
refactor: nits
h13i32maru Aug 2, 2020
cab2570
refactor(IssueRepo):
h13i32maru Aug 2, 2020
8bcf72c
refactor(IssueRepo):
h13i32maru Aug 2, 2020
5166b9f
refactor(IssueRepo):
h13i32maru Aug 2, 2020
c0852ca
refactor(IssueRepo):
h13i32maru Aug 2, 2020
d71e3e7
refactor(IssueRepo):
h13i32maru Aug 2, 2020
eedb2d0
refactor(IssueRepo):
h13i32maru Aug 2, 2020
e45dc8d
refactor(StreamIssueRepo):
h13i32maru Aug 2, 2020
992dac7
refactor(DBIPC): show slow query
h13i32maru Aug 2, 2020
13aa0f8
refactor(Repo):
h13i32maru Aug 2, 2020
f9e5f9a
refactor(IssueRepo):
h13i32maru Aug 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(StreamIssueRepo):
  • Loading branch information
h13i32maru committed Aug 1, 2020
commit de9adf3df84c7eb1dab83353f5c43a8698099854
4 changes: 3 additions & 1 deletion src/Renderer/Infra/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ export class Stream {
}

const {updatedIssueIds} = await IssueRepo.import(issues);
await StreamsIssuesRepo.import(this.id, issues);
const {error: e1} = await StreamsIssuesRepo.createBulk(this.id, issues);
if (e1) return {error: e1};

if (updatedIssueIds.length) {
console.log(`[updated] stream: ${this.id}, name: ${this.name}, page: ${this.page}, totalCount: ${body.total_count}, updatedIssues: ${updatedIssueIds.length}`);
}
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/Repository/IssueRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import moment from 'moment';
import {IssueEvent} from '../Event/IssueEvent';
import {IssueFilter} from './Issue/IssueFilter';

// todo: refactor
class _IssueRepo {
async getCount(): Promise<{error?: Error; count?: number}>{
const {error, row} = await DBIPC.selectSingle('select count(1) as count from issues');
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/Repository/LibraryStreamRepo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {DBIPC} from '../../IPC/DBIPC';
import {LibraryStreamEntity} from '../Type/LibraryStreamEntity';

// todo: remove comments
class _LibraryStreamRepo {
async getAllLibraryStreams(): Promise<{error?: Error; libraryStreams?: LibraryStreamEntity[]}> {
const promises = [
Expand Down
59 changes: 44 additions & 15 deletions src/Renderer/Repository/StreamsIssuesRepo.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,57 @@
import {DBIPC} from '../../IPC/DBIPC';
import {StreamRepo} from './StreamRepo';
import {GitHubQueryParser} from '../Infra/GitHubQueryParser';
import {IssueEntity} from '../../Type/IssueEntity';
import {StreamIssueEntity} from '../../Type/StreamIssueEntity';

class _StreamsIssuesRepo {
async import(streamId: number, issues: any[]) {
for (const issue of issues) {
const params = [streamId, issue.id];
const res = await DBIPC.selectSingle(`select * from streams_issues where stream_id = ? and issue_id = ?`, params);
if (!res.row) {
await DBIPC.exec('insert into streams_issues (stream_id, issue_id) values (?, ?)', params);
}
}
async createBulk(streamId: number, issues: IssueEntity[]): Promise<{error?: Error}> {
if (!issues.length) return {};

// get StreamIssue
const {error: e1, rows} = await DBIPC.select<StreamIssueEntity>(`select * from streams_issues where stream_id = ?`, [streamId]);
if (e1) return {error: e1};

// filter notExistIssues
const existIssueIds = rows.map(row => row.issue_id);
const notExistIssues = issues.filter(issue => !existIssueIds.includes(issue.id));
if (!notExistIssues.length) return {};

// insert bulk issues
const bulkParams = notExistIssues.map(issue => `(${streamId}, ${issue.id})`);
const {error: e2} = await DBIPC.exec(`insert into streams_issues (stream_id, issue_id) values ${bulkParams.join(',')}`);
if (e2) return {error: e2};

// unlink mismatch issues
await this.unlinkMismatchIssues(issues);

// see IssuesTable
await DBIPC.exec(`
delete from
streams_issues
where
issue_id not in (select id from issues)
`);
// delete unlinked issues
const {error: e3} = await DBIPC.exec(`delete from streams_issues where issue_id not in (select id from issues)`);
if (e3) return {error: e3};

return {};
}

// async import(streamId: number, issues: any[]) {
// for (const issue of issues) {
// const params = [streamId, issue.id];
// const res = await DBIPC.selectSingle(`select * from streams_issues where stream_id = ? and issue_id = ?`, params);
// if (!res.row) {
// await DBIPC.exec('insert into streams_issues (stream_id, issue_id) values (?, ?)', params);
// }
// }
//
// await this.unlinkMismatchIssues(issues);
//
// // see IssuesTable
// await DBIPC.exec(`
// delete from
// streams_issues
// where
// issue_id not in (select id from issues)
// `);
// }

private async unlinkMismatchIssues(issues: any[]) {
if (!issues.length) return;

Expand Down
3 changes: 2 additions & 1 deletion src/Renderer/Repository/SystemStreamRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class _SystemStreamRepo {
const issue = res.body;

await IssueRepo.import([issue]);
await StreamsIssuesRepo.import(this.STREAM_ID_SUBSCRIPTION, [issue]);
const {error} = await StreamsIssuesRepo.createBulk(this.STREAM_ID_SUBSCRIPTION, [issue]);
if (error) return console.error(error);

const createdAt = moment(new Date()).utc().format('YYYY-MM-DDTHH:mm:ss[Z]');
await DBIPC.exec(`
Expand Down
25 changes: 25 additions & 0 deletions src/Type/IssueEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export type IssueEntity = {
id: number;
type: string;
title: string;
created_at: string;
updated_at: string;
closed_at: string;
read_at: string;
prev_read_at: string;
archived_at: string;
marked_at: string;
number: number;
user: string;
repo: string;
author: string;
assignees: string;
labels: string;
milestone: string;
due_on: string;
html_url: string;
body: string;
read_body: string;
prev_read_body: string;
value: string;
}
4 changes: 4 additions & 0 deletions src/Type/StreamIssueEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type StreamIssueEntity = {
stream_id: number;
issue_id: number;
}