Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mentat-test
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
713
Mentat
mentat-test
Commits
f7aacb8c
Verified
Commit
f7aacb8c
authored
3 weeks ago
by
Rajmund Hruška
Browse files
Options
Downloads
Patches
Plain Diff
Fix: Fetch last_seen beforehand and use it as the first fallback (
#7812
)
parent
2ab94d84
Branches
hruska-bugfix-#7812-enum-values
No related tags found
1 merge request
!106
Fix slow mentat-precache
Pipeline
#15533
passed
3 weeks ago
Stage: test
Stage: check-warnings
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/mentat/services/eventstorage.py
+12
-3
12 additions, 3 deletions
lib/mentat/services/eventstorage.py
with
12 additions
and
3 deletions
lib/mentat/services/eventstorage.py
+
12
−
3
View file @
f7aacb8c
...
...
@@ -1569,6 +1569,12 @@ class EventStorageService:
:rtype: list
"""
enum_table
=
"
enum_{}
"
.
format
(
column
)
# Get last_seen first.
self
.
cursor
.
execute
(
psycopg2
.
sql
.
SQL
(
"
SELECT max(last_seen) FROM {}
"
).
format
(
psycopg2
.
sql
.
Identifier
(
enum_table
)))
last_seen
=
self
.
cursor
.
fetchone
()[
0
]
self
.
commit
()
# Build and execute query for updating enumeration table.
enum_query
=
psycopg2
.
sql
.
SQL
(
"
INSERT INTO {} (SELECT * FROM (
"
).
format
(
psycopg2
.
sql
.
Identifier
(
enum_table
))
if
column
not
in
(
'
eventclass
'
,
'
targetclass
'
,
'
eventseverity
'
,
'
targetseverity
'
):
...
...
@@ -1577,10 +1583,13 @@ class EventStorageService:
enum_query
+=
psycopg2
.
sql
.
SQL
(
"
SELECT {}
"
).
format
(
psycopg2
.
sql
.
Identifier
(
column
))
enum_query
+=
psycopg2
.
sql
.
SQL
(
"
AS data, max(storagetime) AS last_seen FROM events
"
"
WHERE storagetime >= COALESCE(
(SELECT max(last_seen) FROM {})
, %s, (SELECT min(storagetime) FROM events))
"
"
WHERE storagetime >= COALESCE(
%s
, %s, (SELECT min(storagetime) FROM events))
"
"
GROUP BY data) AS enum WHERE data IS NOT NULL) ON CONFLICT (data) DO UPDATE SET last_seen = excluded.last_seen
"
).
format
(
psycopg2
.
sql
.
Identifier
(
enum_table
))
self
.
cursor
.
execute
(
enum_query
,
(
last_run_ts
,))
)
# Use the time of the last run before the value of last_seen from the database.
# Some values may be quite rare and it doesn't make sense to always search all events
# since the time when this rare value appeared the last time.
self
.
cursor
.
execute
(
enum_query
,
(
last_run_ts
,
last_seen
,))
self
.
commit
()
# Return all entries from recently updated enumeration table.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment