Skip to content

Commit 0dc6102

Browse files
committed
Bulk operations started
1 parent c026d02 commit 0dc6102

File tree

22 files changed

+756
-93
lines changed

22 files changed

+756
-93
lines changed

package-lock.json

+54-54
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"lint-staged": "^12.3.7",
3636
"prettier": "^2.8.3",
3737
"ts-node": "^10.9.1",
38-
"typescript": "^4.9.5"
38+
"typescript": "^5.0.4"
3939
},
4040
"dependencies": {
4141
"chalk": "^4.1.2",

src/BenchmarkUtils/BenchmarkRunner/BenchmarkSuite.ts

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export class BenchmarkSuite<T extends TestTemplate> {
130130
try {
131131
const data = await implementationFn()
132132
await validationFn(data)
133+
await resetFn()
133134
} catch (e) {
134135
return this.errorHandler(e, TestType.LATENCY)
135136
}

src/Benchmarks/BulkOperations.ts

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import {
2+
BenchmarkSuite,
3+
TestTemplate,
4+
} from 'BenchmarkUtils/BenchmarkRunner/BenchmarkSuite'
5+
import { CatDatabase } from 'Databases/CatDatabase/CatDatabase'
6+
import assert from 'node:assert/strict'
7+
8+
export interface BulkOperationsBenchmark extends TestTemplate {
9+
bulkInsert: (
10+
houses: Array<{ id: number; houseAddress: string; hasDog: boolean }>
11+
) => Promise<number>
12+
bulkDelete: (toyName: string) => Promise<number>
13+
bulkUpdate: (
14+
originalCurrency: string,
15+
resultingCurrency: string
16+
) => Promise<number>
17+
pagination: (pageSize: number) => Promise<Array<Record<any, any>>>
18+
}
19+
20+
export const BulkOperations = new BenchmarkSuite<BulkOperationsBenchmark>(
21+
'BulkOperations',
22+
CatDatabase,
23+
{
24+
bulkInsert: {
25+
testName: 'Bulk Insert',
26+
referenceCheck: async (data: number) => {
27+
assert.equal(data, 6000)
28+
},
29+
call: (implementation: BulkOperationsBenchmark['bulkInsert']) => () =>
30+
implementation(
31+
Array.from({ length: 5000 }, (_, i) => ({
32+
id: 10000 + i,
33+
houseAddress: `House ${i}`,
34+
hasDog: i % 2 === 0,
35+
}))
36+
),
37+
reset: async pg => {
38+
await pg.query('delete from house where id >= 10000')
39+
},
40+
testLatency: true,
41+
latencyIterations: 10,
42+
testValidity: false,
43+
},
44+
bulkDelete: {
45+
testName: 'Bulk Delete',
46+
call: (implementation: BulkOperationsBenchmark['bulkDelete']) => () =>
47+
implementation('Catnip'),
48+
referenceCheck: async (data: number) => {
49+
assert.equal(data, 0)
50+
},
51+
reset: async pg => {
52+
await pg.query(`insert into toy (id, toys_producer_id, toy_name, barcode, price, currency) values (300, 1, 'Catnip', '667322379012', 5.99, 'USD');
53+
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (301, '100003200000', 100.0, 'USD', 'Catnip', 2, '1/0');
54+
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (302, '100420000001', 100.0, 'USD', 'Catnip', 5, '1/0');`)
55+
},
56+
testValidity: true,
57+
testLatency: true,
58+
latencyIterations: 10,
59+
},
60+
bulkUpdate: {
61+
testName: 'Bulk Update',
62+
referenceCheck: async (data: number) => {
63+
assert.equal(data, 3)
64+
},
65+
call: (implementation: BulkOperationsBenchmark['bulkUpdate']) => () =>
66+
implementation('GBP', 'FIT'),
67+
reset: async pg => {
68+
await pg.query(
69+
"update toy set currency = 'GBP' where currency = 'FIT';"
70+
)
71+
},
72+
testValidity: true,
73+
testLatency: true,
74+
latencyIterations: 10,
75+
},
76+
pagination: {
77+
testName: 'Pagination',
78+
call: (implementation: BulkOperationsBenchmark['pagination']) => () =>
79+
implementation(500),
80+
referenceCheck: async (data: Array<Record<any, any>>) => {
81+
assert.equal(data.length, 7)
82+
},
83+
testValidity: true,
84+
testLatency: true,
85+
latencyIterations: 10,
86+
},
87+
}
88+
)

src/Databases/CatDatabase/sql/data.sql

+9-4
Original file line numberDiff line numberDiff line change
@@ -6342,7 +6342,7 @@ insert into toys_producer (id, hq_location, stock_info) values (21, '["7 Charles
63426342

63436343
-- Insert toys
63446344

6345-
insert into toy (id, toys_producer_id, toy_name, barcode, price, currency) values (1, 1, 'Catnip', '667321679012', 5.99, 'USD');
6345+
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (1, '473408829853', 19.75, 'XAF', 'Scratcher', 6, '1E02');
63466346
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (2, '593593051966', 16.18, 'THB', 'Trencher', 2, 'הָיְתָהtestالصفحات التّحول');
63476347
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (3, '780605489446', 96.78, 'UAH', 'Backhoe', null, null);
63486348
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (4, '875684774524', 84.58, 'CNY', 'Bulldozer', null, null);
@@ -6397,15 +6397,15 @@ insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naugh
63976397
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (53, '894662928371', 150.09, 'VEF', 'Crawler', 3, '˙ɐnbᴉlɐ ɐuƃɐɯ ǝɹolop ʇǝ ǝɹoqɐl ʇn ʇunpᴉpᴉɔuᴉ ɹodɯǝʇ poɯsnᴉǝ op pǝs ''ʇᴉlǝ ƃuᴉɔsᴉdᴉpɐ ɹnʇǝʇɔǝsuoɔ ''ʇǝɯɐ ʇᴉs ɹolop ɯnsdᴉ ɯǝɹo˥');
63986398
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (54, '553704594989', 26.24, 'BRL', 'Crawler', 13, '<script>alert(''hi'')</script>');
63996399
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (55, '504179785305', 185.57, 'PLN', 'Bulldozer', null, null);
6400-
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (56, '832262212804', 50.11, 'RUB', 'Scraper', 18, '١٢٣');
6400+
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (56, '832262212804', 50.11, 'GBP', 'Scraper', 18, '١٢٣');
64016401
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (57, '348818167065', 37.95, 'MAD', 'Excavator', 19, ',。・:*:・゜’( ☻ ω ☻ )。・:*:・゜’');
64026402
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (58, '949144481992', 51.01, 'ZMW', 'Dump Truck', null, null);
64036403
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (59, '150757510319', 4.45, 'EUR', 'Dump Truck', 10, '˙ɐnbᴉlɐ ɐuƃɐɯ ǝɹolop ʇǝ ǝɹoqɐl ʇn ʇunpᴉpᴉɔuᴉ ɹodɯǝʇ poɯsnᴉǝ op pǝs ''ʇᴉlǝ ƃuᴉɔsᴉdᴉpɐ ɹnʇǝʇɔǝsuoɔ ''ʇǝɯɐ ʇᴉs ɹolop ɯnsdᴉ ɯǝɹo˥');
64046404
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (60, '974496147594', 165.35, 'IDR', 'Grader', 2, '0.00');
64056405
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (61, '862533973429', 43.52, 'VEF', 'Excavator', 3, ' ');
64066406
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (62, '145191140569', 76.11, 'RUB', 'Backhoe', 18, '<>?:"{}|_+');
6407-
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (63, '473408829853', 19.75, 'XAF', 'Grader', 6, '1E02');
6408-
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (64, '404210808889', 39.91, 'RUB', 'Scratcher post', 10, '1E+02');
6407+
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (63, '473408829854', 19.75, 'XAF', 'Grader', 6, '1E02');
6408+
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (64, '404210808889', 39.91, 'GBP', 'Scratcher post', 10, '1E+02');
64096409
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (65, '399150397896', 43.43, 'IDR', 'Feather', 20, 'NULL');
64106410
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (66, '124598347553', 164.65, 'PHP', 'Backhoe', 8, '田中さんにあげて下さい');
64116411
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (67, '574493828188', 142.1, 'CNY', 'Dump Truck', 18, '🐵 🙈 🙉 🙊');
@@ -6416,6 +6416,11 @@ insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naugh
64166416
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (72, '100000000000', 100.0, 'USD', 'Ball', 1, '1/0');
64176417
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (73, '100000000001', 100.0, 'USD', 'Mouse', 1, '1/0');
64186418

6419+
insert into toy (id, toys_producer_id, toy_name, barcode, price, currency) values (300, 1, 'Catnip', '667322379012', 5.99, 'USD');
6420+
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (301, '100003200000', 100.0, 'USD', 'Catnip', 2, '1/0');
6421+
insert into toy (id, barcode, price, currency, toy_name, toys_producer_id, naughty) values (302, '100420000001', 100.0, 'USD', 'Catnip', 5, '1/0');
6422+
6423+
64196424
insert into toy_house (house_id, toy_id, amount) values (2, 73, 8);
64206425
insert into toy_house (house_id, toy_id, amount) values (1, 72, 5);
64216426
insert into toy_house (house_id, toy_id, amount) values (413, 73, 1);
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
DROP TABLE IF EXISTS cat_color CASCADE;
2-
DROP TABLE IF EXISTS cat CASCADE;
3-
DROP TABLE IF EXISTS color_hex CASCADE;
4-
DROP TABLE IF EXISTS house CASCADE;
5-
DROP TABLE IF EXISTS toy CASCADE;
6-
DROP TABLE IF EXISTS toys_producer CASCADE;
7-
DROP TABLE IF EXISTS house_cat CASCADE;
8-
DROP TABLE IF EXISTS toy_house CASCADE;
1+
-- DROP TABLE IF EXISTS cat_color CASCADE;
2+
-- DROP TABLE IF EXISTS cat CASCADE;
3+
-- DROP TABLE IF EXISTS color_hex CASCADE;
4+
-- DROP TABLE IF EXISTS house CASCADE;
5+
-- DROP TABLE IF EXISTS toy CASCADE;
6+
-- DROP TABLE IF EXISTS toys_producer CASCADE;
7+
-- DROP TABLE IF EXISTS house_cat CASCADE;
8+
-- DROP TABLE IF EXISTS toy_house CASCADE;

0 commit comments

Comments
 (0)