Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
docker
osticket
Commits
e287c7fa
Unverified
Commit
e287c7fa
authored
6 years ago
by
Peter Rotich
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #4561 from aydreeihn/issue/remove-enums
Event Migration Optimization
parents
7d3a2ba2
c548d007
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/class.thread.php
+7
-7
7 additions, 7 deletions
include/class.thread.php
include/upgrader/streams/core/26fd79dc-00c949a6.task.php
+25
-34
25 additions, 34 deletions
include/upgrader/streams/core/26fd79dc-00c949a6.task.php
with
32 additions
and
41 deletions
include/class.thread.php
+
7
−
7
View file @
e287c7fa
...
...
@@ -2077,25 +2077,25 @@ class Event extends VerySimpleModel {
return
$this
->
name
;
}
function
getNameById
(
$id
)
{
function
getDescription
()
{
return
$this
->
description
;
}
static
function
getNameById
(
$id
)
{
return
array_search
(
$id
,
self
::
getIds
());
}
function
getIdByName
(
$name
)
{
static
function
getIdByName
(
$name
)
{
$ids
=
self
::
getIds
();
return
$ids
[
$name
]
?:
0
;
}
function
getDescription
()
{
return
$this
->
description
;
}
static
function
getIds
()
{
static
$ids
;
if
(
!
isset
(
$ids
))
{
$ids
=
array
();
$events
=
s
tatic
::
objects
()
->
values_flat
(
'id'
,
'name'
);
$events
=
s
elf
::
objects
()
->
values_flat
(
'id'
,
'name'
);
foreach
(
$events
as
$row
)
{
list
(
$id
,
$name
)
=
$row
;
$ids
[
$name
]
=
$id
;
...
...
This diff is collapsed.
Click to expand it.
include/upgrader/streams/core/26fd79dc-00c949a6.task.php
+
25
−
34
View file @
e287c7fa
...
...
@@ -5,6 +5,7 @@ class EventEnumRemoval extends MigrationTask {
var
$queue
;
var
$skipList
;
var
$errorList
=
array
();
var
$limit
=
20000
;
function
sleep
()
{
return
array
(
'queue'
=>
$this
->
queue
,
'skipList'
=>
$this
->
skipList
);
...
...
@@ -13,11 +14,11 @@ class EventEnumRemoval extends MigrationTask {
$this
->
queue
=
$stuff
[
'queue'
];
$this
->
skipList
=
$stuff
[
'skipList'
];
while
(
!
$this
->
isFinished
())
$this
->
do_batch
(
30
,
5000
);
$this
->
do_batch
(
30
,
$this
->
limit
);
}
function
run
(
$max_time
)
{
$this
->
do_batch
(
$max_time
*
0.9
,
5000
);
$this
->
do_batch
(
$max_time
*
0.9
,
$this
->
limit
);
}
function
isFinished
()
{
...
...
@@ -49,40 +50,34 @@ class EventEnumRemoval extends MigrationTask {
if
((
$qc
=
$this
->
getQueueLength
()))
return
$qc
;
$sql
=
"SELECT this.id, this.state, that.id, that.name FROM "
.
THREAD_EVENT_TABLE
.
" this
INNER JOIN (
SELECT id, name
FROM "
.
EVENT_TABLE
.
") that
WHERE this.state = that.name
AND event_id IS NULL"
;
if
((
$skipList
=
$this
->
getSkipList
()))
$sql
.
=
' AND this.id NOT IN('
.
implode
(
','
,
db_input
(
$skipList
))
.
')'
;
if
(
$limit
&&
is_numeric
(
$limit
))
$sql
.
=
' LIMIT '
.
$limit
;
$sql
=
"SELECT COUNT(t.id) FROM "
.
THREAD_EVENT_TABLE
.
" t
INNER JOIN "
.
EVENT_TABLE
.
" e ON (e.name=t.state)
WHERE t.event_id IS NULL"
;
//XXX: Do a hard fail or error querying the database?
if
(
!
(
$res
=
db_query
(
$sql
)))
return
$this
->
error
(
'Unable to query DB for Thread Event migration!'
);
$count
=
db_result
(
$res
);
// Force the log message to the database
$ost
->
logDebug
(
"Thread Event Migration"
,
'Found '
.
db_num_rows
(
$res
)
$ost
->
logDebug
(
"Thread Event Migration"
,
'Found '
.
$count
.
' events to migrate'
,
true
);
if
(
!
db_num_rows
(
$res
)
)
if
(
$count
==
0
)
return
0
;
//Nothing else to do!!
$start
=
db_result
(
db_query
(
"SELECT id FROM "
.
THREAD_EVENT_TABLE
.
"
WHERE event_id IS NULL
ORDER BY id ASC LIMIT 1"
));
$this
->
queue
=
array
();
while
(
list
(
$id
,
$state
,
$eventId
,
$eventName
)
=
db_fetch_row
(
$res
))
{
$info
=
array
(
'id'
=>
$id
,
'state'
=>
$state
,
'eventId'
=>
$eventId
,
'eventName'
=>
$eventName
,
);
$this
->
enqueue
(
$info
);
}
$info
=
array
(
'count'
=>
$count
,
'start'
=>
$start
,
'end'
=>
$start
+
$limit
);
$this
->
enqueue
(
$info
);
return
$this
->
getQueueLength
();
}
...
...
@@ -125,16 +120,12 @@ class EventEnumRemoval extends MigrationTask {
# need to be recalculated for every shift() operation.
$info
=
array_pop
(
$this
->
queue
);
if
(
!
$info
[
'state'
])
{
# Continue with next thread event
return
$this
->
skip
(
$info
[
'eventId'
],
sprintf
(
'Thread Event ID %s: State is blank'
,
$info
[
'eventId'
]));
}
$sql
=
"UPDATE "
.
THREAD_EVENT_TABLE
.
" t
INNER JOIN "
.
EVENT_TABLE
.
" e ON (e.name=t.state)
SET t.event_id = e.id
WHERE t.event_id IS NULL AND t.id <= "
.
$info
[
'end'
];
db_query
(
'update '
.
THREAD_EVENT_TABLE
.
' set event_id='
.
db_input
(
$info
[
'eventId'
])
.
' where state='
.
db_input
(
$info
[
'eventName'
])
.
' and id='
.
db_input
(
$info
[
'id'
]));
db_query
(
$sql
);
return
true
;
}
...
...
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