Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 72d8422

Browse files
[Backport 5.1] internal/event_logs: optimize ping cte (#55714)
The aggregatedCodyUsageEventsQuery is timing out for dotcom. These changes are cte optimization steps. ## Test plan Extract query from most expensive ping-supporting query, [aggregatedCodyUsageEventsQuery](https://sourcegraph.sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/internal/database/event_logs.go?L1594), analyze original query: ``` GroupAggregate (cost=143042.53..143382.23 rows=270 width=158) (actual time=492.653..608.924 rows=87 loops=1) Group Key: event_logs.name, (date_trunc(&#39;month&#39;::text, &#39;2023-08-01 17:00:00-07&#39;::timestamp with time zone)), ((date_trunc(&#39;week&#39;::text, (&#39;2023-08-01 17:00:00-07&#39;::timestamp with time zone + &#39;1 day&#39;::interval)) - &#39;1 day&#39;::interval)), (date_trunc(&#39;day&#39;::text, &#39;2023-08-01 17:00:00-07&#39;::timestamp with time zone)) CTE code_generation_keys -&gt; Function Scan on unnest key (cost=0.00..0.09 rows=9 width=32) (actual time=0.005..0.007 rows=9 loops=1) CTE explanation_keys -&gt; Function Scan on unnest key_1 (cost=0.00..0.05 rows=5 width=32) (actual time=0.012..0.013 rows=5 loops=1) -&gt; Sort (cost=143042.38..143046.21 rows=1530 width=62) (actual time=492.526..496.803 rows=33511 loops=1) Sort Key: event_logs.name Sort Method: external merge Disk: 3056kB -&gt; Gather (cost=1000.16..142961.45 rows=1530 width=62) (actual time=12.381..418.370 rows=33511 loops=1) Workers Planned: 2 Workers Launched: 2 -&gt; Parallel Seq Scan on event_logs (cost=0.17..141808.45 rows=638 width=62) (actual time=10.540..417.177 rows=11170 loops=3) Filter: ((name !~~ &#39;%completion:suggested%&#39;::text) AND (name !~~ &#39;%completion:started%&#39;::text) AND (name !~~ &#39;%CTA%&#39;::text) AND (name !~~ &#39;%Cta%&#39;::text) AND (NOT (hashed SubPlan 9)) AND (lower(name) ~~ &#39;%cody%&#39;::text) AND (&quot;timestamp&quot; &gt;= (date_trunc(&#39;month&#39;::text, &#39;2023-08-01 17:00:00-07&#39;::timestamp with time zone) - &#39;1 mon&#39;::interval))) Rows Removed by Filter: 382174 SubPlan 9 -&gt; Function Scan on unnest (cost=0.00..0.13 rows=13 width=32) (actual time=0.007..0.008 rows=13 loops=3) SubPlan 8 -&gt; CTE Scan on explanation_keys explanation_keys_3 (cost=0.00..0.10 rows=5 width=32) (actual time=0.000..0.001 rows=5 loops=1) SubPlan 7 -&gt; CTE Scan on explanation_keys explanation_keys_2 (cost=0.00..0.10 rows=5 width=32) (actual time=0.014..0.016 rows=5 loops=1) SubPlan 6 -&gt; CTE Scan on explanation_keys explanation_keys_1 (cost=0.00..0.10 rows=5 width=32) (actual time=0.000..0.001 rows=5 loops=1) SubPlan 5 -&gt; CTE Scan on code_generation_keys code_generation_keys_1 (cost=0.00..0.18 rows=9 width=32) (actual time=0.000..0.002 rows=9 loops=1) SubPlan 4 -&gt; CTE Scan on explanation_keys (cost=0.00..0.10 rows=5 width=32) (actual time=0.000..0.001 rows=5 loops=1) SubPlan 3 -&gt; CTE Scan on code_generation_keys (cost=0.00..0.18 rows=9 width=32) (actual time=0.007..0.010 rows=9 loops=1) Planning Time: 1.556 ms Execution Time: 610.143 ms ``` Add indexes and analyze again in comments. <br> Backport 41e5cf3 from #55538 --------- Co-authored-by: Nathan Downs <[email protected]>
1 parent 47f426c commit 72d8422

File tree

10 files changed

+244
-81
lines changed

10 files changed

+244
-81
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ All notable changes to Sourcegraph are documented in this file.
3232
- Pressing `Mod-f` will always select the input value in the file view search [#55546](https://github.com/sourcegraph/sourcegraph/pull/55546)
3333
- When using OpenAI or Azure OpenAI for Cody completions, code completions will be disabled - chat will continue to work. This is because we currently don't support code completions with OpenAI. [#55624](https://github.com/sourcegraph/sourcegraph/pull/55624)
3434
- The commit message defined in a batch spec will now be passed to `git commit` on stdin using `--file=-` instead of being included inline with `git commit -m` to improve how the message is interpreted by `git` in certain edge cases, such as when the commit message begins with a dash, and to prevent extra quotes being added to the message. This may mean that previous escaping strategies will behave differently.
35+
- Improved performance of ping aggregations by adding functional indexes. [#55538](https://github.com/sourcegraph/sourcegraph/pull/55538)
3536

3637
### Fixed
3738

3839
- Fixed a bug where user account requests could not be approved even though the license would permit user creation otherwise. [#55482[(https://github.com/sourcegraph/sourcegraph/pull/55482)
3940
- Fixed a bug where the background scheduler for embedding jobs based on policies would not schedule jobs for private repositories. [#55698](https://github.com/sourcegraph/sourcegraph/pull/55698)
41+
- Fixed a bug where user account requests could not be approved even though the license would permit user creation otherwise. [#55482](https://github.com/sourcegraph/sourcegraph/pull/55482)
42+
- Fixed a bug where date truncations were incorrectly converted to UTC, causing some dates to be off by one day. [#55367](https://github.com/sourcegraph/sourcegraph/pull/55367)
4043

4144
### Removed
4245

internal/database/event_logs.go

Lines changed: 13 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,27 +1565,11 @@ func (l *eventLogStore) aggregatedSearchEvents(ctx context.Context, queryString
15651565
return events, nil
15661566
}
15671567

1568-
// List of events that don't meet the criteria of "active" usage of Cody.
1569-
var nonActiveCodyEvents = []string{
1570-
"CodyVSCodeExtension:CodySavedLogin:executed",
1571-
"web:codyChat:tryOnPublicCode",
1572-
"web:codyEditorWidget:viewed",
1573-
"web:codyChat:pageViewed",
1574-
"CodyConfigurationPageViewed",
1575-
"ClickedOnTryCodySearchCTA",
1576-
"TryCodyWebOnboardingDisplayed",
1577-
"AboutGetCodyPopover",
1578-
"TryCodyWeb",
1579-
"CodySurveyToastViewed",
1580-
"SiteAdminCodyPageViewed",
1581-
"CodyUninstalled",
1582-
"SpeakToACodyEngineerCTA",
1583-
}
1584-
15851568
var aggregatedCodyUsageEventsQuery = `
1586-
WITH events AS (
1569+
WITH
1570+
events AS (
15871571
SELECT
1588-
name AS key,
1572+
name,
15891573
` + aggregatedUserIDQueryFragment + ` AS user_id,
15901574
` + makeDateTruncExpression("month", "timestamp") + ` as month,
15911575
` + makeDateTruncExpression("week", "timestamp") + ` as week,
@@ -1595,36 +1579,11 @@ WITH events AS (
15951579
` + makeDateTruncExpression("day", "%s::timestamp") + ` as current_day
15961580
FROM event_logs
15971581
WHERE
1598-
timestamp >= ` + makeDateTruncExpression("month", "%s::timestamp") + `
1599-
AND lower(name) like '%%cody%%'
1600-
AND name not like '%%CTA%%'
1601-
AND name not like '%%Cta%%'
1602-
AND (name NOT IN ('` + strings.Join(nonActiveCodyEvents, "','") + `'))
1603-
),
1604-
code_generation_keys AS (
1605-
SELECT * FROM unnest(ARRAY[
1606-
'CodyVSCodeExtension:recipe:rewrite-to-functional:executed',
1607-
'CodyVSCodeExtension:recipe:improve-variable-names:executed',
1608-
'CodyVSCodeExtension:recipe:replace:executed',
1609-
'CodyVSCodeExtension:recipe:generate-docstring:executed',
1610-
'CodyVSCodeExtension:recipe:generate-unit-test:executed',
1611-
'CodyVSCodeExtension:recipe:rewrite-functional:executed',
1612-
'CodyVSCodeExtension:recipe:code-refactor:executed',
1613-
'CodyVSCodeExtension:recipe:fixup:executed',
1614-
'CodyVSCodeExtension:recipe:translate-to-language:executed'
1615-
]) AS key
1616-
),
1617-
explanation_keys AS (
1618-
SELECT * FROM unnest(ARRAY[
1619-
'CodyVSCodeExtension:recipe:explain-code-high-level:executed',
1620-
'CodyVSCodeExtension:recipe:explain-code-detailed:executed',
1621-
'CodyVSCodeExtension:recipe:find-code-smells:executed',
1622-
'CodyVSCodeExtension:recipe:git-history:executed',
1623-
'CodyVSCodeExtension:recipe:rate-code:executed'
1624-
]) AS key
1582+
timestamp >= %s::timestamp - '1 month'::interval
1583+
AND iscodyactiveevent(name)
16251584
)
16261585
SELECT
1627-
key,
1586+
name,
16281587
current_month,
16291588
current_week,
16301589
current_day,
@@ -1634,25 +1593,23 @@ SELECT
16341593
COUNT(DISTINCT user_id) FILTER (WHERE month = current_month) AS uniques_month,
16351594
COUNT(DISTINCT user_id) FILTER (WHERE week = current_week) AS uniques_week,
16361595
COUNT(DISTINCT user_id) FILTER (WHERE day = current_day) AS uniques_day,
1637-
SUM(case when month = current_month and key in
1638-
(SELECT * FROM code_generation_keys)
1596+
SUM(case when month = current_month and iscodygenerationevent(name)
16391597
then 1 else 0 end) as code_generation_month,
1640-
SUM(case when week = current_week and key in
1641-
(SELECT * FROM explanation_keys)
1598+
SUM(case when week = current_week and iscodygenerationevent(name)
16421599
then 1 else 0 end) as code_generation_week,
1643-
SUM(case when day = current_day and key in (SELECT * FROM code_generation_keys)
1600+
SUM(case when day = current_day and iscodygenerationevent(name)
16441601
then 1 else 0 end) as code_generation_day,
1645-
SUM(case when month = current_month and key in (SELECT * FROM explanation_keys)
1602+
SUM(case when month = current_month and iscodyexplanationevent(name)
16461603
then 1 else 0 end) as explanation_month,
1647-
SUM(case when week = current_week and key in (SELECT * FROM explanation_keys)
1604+
SUM(case when week = current_week and iscodyexplanationevent(name)
16481605
then 1 else 0 end) as explanation_week,
1649-
SUM(case when day = current_day and key in (SELECT * FROM explanation_keys)
1606+
SUM(case when day = current_day and iscodyexplanationevent(name)
16501607
then 1 else 0 end) as explanation_day,
16511608
0 as invalid_month,
16521609
0 as invalid_week,
16531610
0 as invalid_day
16541611
FROM events
1655-
GROUP BY key, current_month, current_week, current_day
1612+
GROUP BY name, current_month, current_week, current_day
16561613
`
16571614

16581615
var searchLatencyEventNames = []string{

internal/database/event_logs_test.go

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ func TestEventLogs_AggregatedCodyEvents(t *testing.T) {
13171317

13181318
codyEventNames := []string{"CodyVSCodeExtension:recipe:rewrite-to-functional:executed",
13191319
"CodyVSCodeExtension:recipe:explain-code-high-level:executed"}
1320-
users := []uint32{1, 2}
1320+
users := []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
13211321

13221322
days := []time.Time{
13231323
now, // Today
@@ -1332,7 +1332,7 @@ func TestEventLogs_AggregatedCodyEvents(t *testing.T) {
13321332
for _, user := range users {
13331333
for _, name := range codyEventNames {
13341334
for _, day := range days {
1335-
for i := 0; i < 25; i++ {
1335+
for i := 0; i < 250; i++ {
13361336
e := &Event{
13371337
UserID: user,
13381338
Name: name,
@@ -1361,35 +1361,46 @@ func TestEventLogs_AggregatedCodyEvents(t *testing.T) {
13611361

13621362
expectedEvents := []types.CodyAggregatedEvent{
13631363
{
1364-
Name: "CodyVSCodeExtension:recipe:explain-code-high-level:executed",
1365-
Month: time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC),
1366-
Week: now.Truncate(time.Hour * 24).Add(-time.Hour * 24 * 5),
1367-
Day: now.Truncate(time.Hour * 24),
1368-
TotalMonth: 200,
1369-
TotalWeek: 150,
1370-
TotalDay: 50,
1371-
UniquesMonth: 2,
1372-
UniquesWeek: 2,
1373-
UniquesDay: 2,
1374-
CodeGenerationWeek: 150,
1375-
CodeGenerationDay: 0,
1376-
ExplanationMonth: 200,
1377-
ExplanationWeek: 150,
1378-
ExplanationDay: 50,
1364+
Name: "CodyVSCodeExtension:recipe:explain-code-high-level:executed",
1365+
Month: time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC),
1366+
Week: now.Truncate(time.Hour * 24).Add(-time.Hour * 24 * 5),
1367+
Day: now.Truncate(time.Hour * 24),
1368+
TotalMonth: 20000,
1369+
TotalWeek: 15000,
1370+
TotalDay: 5000,
1371+
UniquesMonth: 20,
1372+
UniquesWeek: 20,
1373+
UniquesDay: 20,
1374+
CodeGenerationMonth: 0,
1375+
CodeGenerationWeek: 0,
1376+
CodeGenerationDay: 0,
1377+
ExplanationMonth: 20000,
1378+
ExplanationWeek: 15000,
1379+
ExplanationDay: 5000,
1380+
InvalidMonth: 0,
1381+
InvalidWeek: 0,
1382+
InvalidDay: 0,
13791383
},
13801384
{
13811385
Name: "CodyVSCodeExtension:recipe:rewrite-to-functional:executed",
13821386
Month: time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC),
13831387
Week: now.Truncate(time.Hour * 24).Add(-time.Hour * 24 * 5),
13841388
Day: now.Truncate(time.Hour * 24),
1385-
TotalMonth: 200,
1386-
TotalWeek: 150,
1387-
TotalDay: 50,
1388-
UniquesMonth: 2,
1389-
UniquesWeek: 2,
1390-
UniquesDay: 2,
1391-
CodeGenerationMonth: 200,
1392-
CodeGenerationDay: 50,
1389+
TotalMonth: 20000,
1390+
TotalWeek: 15000,
1391+
TotalDay: 5000,
1392+
UniquesMonth: 20,
1393+
UniquesWeek: 20,
1394+
UniquesDay: 20,
1395+
CodeGenerationMonth: 20000,
1396+
CodeGenerationWeek: 15000,
1397+
CodeGenerationDay: 5000,
1398+
ExplanationMonth: 0,
1399+
ExplanationWeek: 0,
1400+
ExplanationDay: 0,
1401+
InvalidMonth: 0,
1402+
InvalidWeek: 0,
1403+
InvalidDay: 0,
13931404
},
13941405
}
13951406

internal/database/schema.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@
138138
"Name": "invalidate_session_for_userid_on_password_change",
139139
"Definition": "CREATE OR REPLACE FUNCTION public.invalidate_session_for_userid_on_password_change()\n RETURNS trigger\n LANGUAGE plpgsql\nAS $function$\n BEGIN\n IF OLD.passwd != NEW.passwd THEN\n NEW.invalidated_sessions_at = now() + (1 * interval '1 second');\n RETURN NEW;\n END IF;\n RETURN NEW;\n END;\n$function$\n"
140140
},
141+
{
142+
"Name": "iscodyactiveevent",
143+
"Definition": "CREATE OR REPLACE FUNCTION public.iscodyactiveevent(name text)\n RETURNS boolean\n LANGUAGE plpgsql\n IMMUTABLE\nAS $function$\nBEGIN\n RETURN\n (name LIKE '%%cody%%' OR name LIKE '%%Cody%%')\n AND name NOT IN (\n '%completion:started%',\n '%completion:suggested%',\n '%cta%',\n '%Cta%',\n 'CodyVSCodeExtension:CodySavedLogin:executed',\n 'web:codyChat:tryOnPublicCode',\n 'web:codyEditorWidget:viewed',\n 'web:codyChat:pageViewed',\n 'CodyConfigurationPageViewed',\n 'ClickedOnTryCodySearchCTA',\n 'TryCodyWebOnboardingDisplayed',\n 'AboutGetCodyPopover',\n 'TryCodyWeb',\n 'CodySurveyToastViewed',\n 'SiteAdminCodyPageViewed',\n 'CodyUninstalled',\n 'SpeakToACodyEngineerCTA'\n );\nEND;\n$function$\n"
144+
},
145+
{
146+
"Name": "iscodyexplanationevent",
147+
"Definition": "CREATE OR REPLACE FUNCTION public.iscodyexplanationevent(name text)\n RETURNS boolean\n LANGUAGE plpgsql\n IMMUTABLE\nAS $function$\nBEGIN\n RETURN name = ANY(ARRAY[\n 'CodyVSCodeExtension:recipe:explain-code-high-level:executed',\n 'CodyVSCodeExtension:recipe:explain-code-detailed:executed',\n 'CodyVSCodeExtension:recipe:find-code-smells:executed',\n 'CodyVSCodeExtension:recipe:git-history:executed',\n 'CodyVSCodeExtension:recipe:rate-code:executed'\n ]);\nEND;\n$function$\n"
148+
},
149+
{
150+
"Name": "iscodygenerationevent",
151+
"Definition": "CREATE OR REPLACE FUNCTION public.iscodygenerationevent(name text)\n RETURNS boolean\n LANGUAGE plpgsql\n IMMUTABLE\nAS $function$\nBEGIN\n RETURN name = ANY(ARRAY[\n 'CodyVSCodeExtension:recipe:rewrite-to-functional:executed',\n 'CodyVSCodeExtension:recipe:improve-variable-names:executed',\n 'CodyVSCodeExtension:recipe:replace:executed',\n 'CodyVSCodeExtension:recipe:generate-docstring:executed',\n 'CodyVSCodeExtension:recipe:generate-unit-test:executed',\n 'CodyVSCodeExtension:recipe:rewrite-functional:executed',\n 'CodyVSCodeExtension:recipe:code-refactor:executed',\n 'CodyVSCodeExtension:recipe:fixup:executed',\n\t'CodyVSCodeExtension:recipe:translate-to-language:executed'\n ]);\nEND;\n$function$\n"
152+
},
141153
{
142154
"Name": "merge_audit_log_transitions",
143155
"Definition": "CREATE OR REPLACE FUNCTION public.merge_audit_log_transitions(internal hstore, arrayhstore hstore[])\n RETURNS hstore\n LANGUAGE plpgsql\n IMMUTABLE\nAS $function$\n DECLARE\n trans hstore;\n BEGIN\n FOREACH trans IN ARRAY arrayhstore\n LOOP\n internal := internal || hstore(trans-\u003e'column', trans-\u003e'new');\n END LOOP;\n\n RETURN internal;\n END;\n$function$\n"
@@ -10400,6 +10412,36 @@
1040010412
"ConstraintType": "",
1040110413
"ConstraintDefinition": ""
1040210414
},
10415+
{
10416+
"Name": "event_logs_name_is_cody_active_event",
10417+
"IsPrimaryKey": false,
10418+
"IsUnique": false,
10419+
"IsExclusion": false,
10420+
"IsDeferrable": false,
10421+
"IndexDefinition": "CREATE INDEX event_logs_name_is_cody_active_event ON event_logs USING btree (iscodyactiveevent(name))",
10422+
"ConstraintType": "",
10423+
"ConstraintDefinition": ""
10424+
},
10425+
{
10426+
"Name": "event_logs_name_is_cody_explanation_event",
10427+
"IsPrimaryKey": false,
10428+
"IsUnique": false,
10429+
"IsExclusion": false,
10430+
"IsDeferrable": false,
10431+
"IndexDefinition": "CREATE INDEX event_logs_name_is_cody_explanation_event ON event_logs USING btree (iscodyexplanationevent(name))",
10432+
"ConstraintType": "",
10433+
"ConstraintDefinition": ""
10434+
},
10435+
{
10436+
"Name": "event_logs_name_is_cody_generation_event",
10437+
"IsPrimaryKey": false,
10438+
"IsUnique": false,
10439+
"IsExclusion": false,
10440+
"IsDeferrable": false,
10441+
"IndexDefinition": "CREATE INDEX event_logs_name_is_cody_generation_event ON event_logs USING btree (iscodygenerationevent(name))",
10442+
"ConstraintType": "",
10443+
"ConstraintDefinition": ""
10444+
},
1040310445
{
1040410446
"Name": "event_logs_name_timestamp",
1040510447
"IsPrimaryKey": false,

internal/database/schema.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,9 @@ Referenced by:
13551355
Indexes:
13561356
"event_logs_pkey" PRIMARY KEY, btree (id)
13571357
"event_logs_anonymous_user_id" btree (anonymous_user_id)
1358+
"event_logs_name_is_cody_active_event" btree (iscodyactiveevent(name))
1359+
"event_logs_name_is_cody_explanation_event" btree (iscodyexplanationevent(name))
1360+
"event_logs_name_is_cody_generation_event" btree (iscodygenerationevent(name))
13581361
"event_logs_name_timestamp" btree (name, "timestamp" DESC)
13591362
"event_logs_source" btree (source)
13601363
"event_logs_timestamp" btree ("timestamp")

migrations/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
DROP INDEX IF EXISTS event_logs_name_is_cody_explanation_event;
2+
3+
DROP INDEX IF EXISTS event_logs_name_is_cody_generation_event;
4+
5+
DROP INDEX IF EXISTS event_logs_name_is_cody_active_event;
6+
7+
DROP FUNCTION IF EXISTS isCodyGenerationEvent(name text);
8+
9+
DROP FUNCTION IF EXISTS isCodyExplanationEvent(name text);
10+
11+
DROP FUNCTION IF EXISTS isCodyActiveEvent(name text);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: event_logs_indexing
2+
parents: [1690323910]
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
CREATE OR REPLACE FUNCTION iscodyactiveevent(name text) RETURNS boolean
2+
LANGUAGE plpgsql IMMUTABLE
3+
AS $$
4+
BEGIN
5+
RETURN
6+
(name LIKE '%%cody%%' OR name LIKE '%%Cody%%')
7+
AND name NOT IN (
8+
'%completion:started%',
9+
'%completion:suggested%',
10+
'%cta%',
11+
'%Cta%',
12+
'CodyVSCodeExtension:CodySavedLogin:executed',
13+
'web:codyChat:tryOnPublicCode',
14+
'web:codyEditorWidget:viewed',
15+
'web:codyChat:pageViewed',
16+
'CodyConfigurationPageViewed',
17+
'ClickedOnTryCodySearchCTA',
18+
'TryCodyWebOnboardingDisplayed',
19+
'AboutGetCodyPopover',
20+
'TryCodyWeb',
21+
'CodySurveyToastViewed',
22+
'SiteAdminCodyPageViewed',
23+
'CodyUninstalled',
24+
'SpeakToACodyEngineerCTA'
25+
);
26+
END;
27+
$$;
28+
29+
CREATE OR REPLACE FUNCTION iscodyexplanationevent(name text) RETURNS boolean
30+
LANGUAGE plpgsql IMMUTABLE
31+
AS $$
32+
BEGIN
33+
RETURN name = ANY(ARRAY[
34+
'CodyVSCodeExtension:recipe:explain-code-high-level:executed',
35+
'CodyVSCodeExtension:recipe:explain-code-detailed:executed',
36+
'CodyVSCodeExtension:recipe:find-code-smells:executed',
37+
'CodyVSCodeExtension:recipe:git-history:executed',
38+
'CodyVSCodeExtension:recipe:rate-code:executed'
39+
]);
40+
END;
41+
$$;
42+
43+
CREATE OR REPLACE FUNCTION iscodygenerationevent(name text) RETURNS boolean
44+
LANGUAGE plpgsql IMMUTABLE
45+
AS $$
46+
BEGIN
47+
RETURN name = ANY(ARRAY[
48+
'CodyVSCodeExtension:recipe:rewrite-to-functional:executed',
49+
'CodyVSCodeExtension:recipe:improve-variable-names:executed',
50+
'CodyVSCodeExtension:recipe:replace:executed',
51+
'CodyVSCodeExtension:recipe:generate-docstring:executed',
52+
'CodyVSCodeExtension:recipe:generate-unit-test:executed',
53+
'CodyVSCodeExtension:recipe:rewrite-functional:executed',
54+
'CodyVSCodeExtension:recipe:code-refactor:executed',
55+
'CodyVSCodeExtension:recipe:fixup:executed',
56+
'CodyVSCodeExtension:recipe:translate-to-language:executed'
57+
]);
58+
END;
59+
$$;
60+
61+
CREATE INDEX IF NOT EXISTS event_logs_name_is_cody_explanation_event ON event_logs USING btree (iscodyexplanationevent(name));
62+
63+
CREATE INDEX IF NOT EXISTS event_logs_name_is_cody_generation_event ON event_logs USING btree (iscodygenerationevent(name));
64+
65+
CREATE INDEX IF NOT EXISTS event_logs_name_is_cody_active_event ON event_logs USING btree (iscodyactiveevent(name));

0 commit comments

Comments
 (0)