Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
1c21830c
Commit
1c21830c
authored
Jan 24, 2018
by
Simon Champion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor the recalc functions into a class.
parent
f9f9d3bb
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
876 additions
and
15 deletions
+876
-15
recalc.php
qa-include/ajax/recalc.php
+6
-4
recalc.php
qa-include/app/recalc.php
+4
-0
RecalcMain.php
qa-include/app/recalc/RecalcMain.php
+853
-0
install.php
qa-include/db/install.php
+7
-6
admin-recalc.php
qa-include/pages/admin/admin-recalc.php
+5
-4
qa-app-recalc.php
qa-include/qa-app-recalc.php
+1
-1
No files found.
qa-include/ajax/recalc.php
View file @
1c21830c
...
...
@@ -20,7 +20,7 @@
*/
require_onc
e
QA_INCLUDE_DI
R
.
'app/users.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'app/recalc.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'app/recalc
/RecalcMain
.php'
;
i
f
(
qa_get_logged_in_leve
l
()
>=
QA_USER_LEVEL_ADMI
N
)
{
...
...
@@ -29,14 +29,16 @@ if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
$message
=
qa_lan
g
(
'misc/form_security_reload'
);
}
els
e
{
$
state
=
qa_post_tex
t
(
'state'
);
$
recalc
=
ne
w
Q
2
A_App_Recalc_Mai
n
(
qa_post_tex
t
(
'state'
)
);
$stoptime
=
tim
e
()
+
3
;
whil
e
(
qa_recalc_perform_ste
p
(
$state
)
&&
tim
e
()
<
$stoptime
)
{
whil
e
(
$recalc
->
performStep
(
)
&&
tim
e
()
<
$stoptime
)
{
// wait
}
$message
=
qa_recalc_get_messag
e
(
$state
);
$message
=
$recalc
->
getMessage
();
$state
=
$recalc
->
getState
();
}
}
els
e
{
...
...
qa-include/app/recalc.php
View file @
1c21830c
...
...
@@ -60,6 +60,10 @@ if (!defined('QA_VERSION')) { // don't allow this page to be requested directly
exi
t
;
}
i
f
(
define
d
(
'QA_DEBUG_PERFORMANCE'
)
&&
QA_DEBUG_PERFORMANC
E
)
{
trigger_erro
r
(
'Included file '
.
basenam
e
(
__FILE_
_
)
.
' is deprecated'
);
}
require_onc
e
QA_INCLUDE_DI
R
.
'db/recalc.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'db/post-create.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'db/points.php'
;
...
...
qa-include/app/recalc/RecalcMain.php
0 → 100644
View file @
1c21830c
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Util/Usage.php
Description: Debugging stuff, currently used for tracking resource usage
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
/*
A full list of redundant (non-normal) information in the database that can be recalculated:
Recalculated in doreindexcontent:
================================
^titlewords (all): index of words in titles of posts
^contentwords (all): index of words in content of posts
^tagwords (all): index of words in tags of posts (a tag can contain multiple words)
^posttags (all): index tags of posts
^words (all): list of words used for indexes
^options (title=cache_*): cached values for various things (e.g. counting questions)
Recalculated in dorecountposts:
==============================
^posts (upvotes, downvotes, netvotes, hotness, acount, amaxvotes, flagcount): number of votes, hotness, answers, answer votes, flags
Recalculated in dorecalcpoints:
===============================
^userpoints (all except bonus): points calculation for all users
^options (title=cache_userpointscount):
Recalculated in dorecalccategories:
===================================
^posts (categoryid): assign to answers and comments based on their antecedent question
^posts (catidpath1, catidpath2, catidpath3): hierarchical path to category ids (requires QA_CATEGORY_DEPTH=4)
^categories (qcount): number of (visible) questions in each category
^categories (backpath): full (backwards) path of slugs to that category
Recalculated in dorebuildupdates:
=================================
^sharedevents (all): per-entity event streams (see big comment in /qa-include/db/favorites.php)
^userevents (all): per-subscriber event streams
[but these are not entirely redundant since they can contain historical information no longer in ^posts]
*/
i
f
(
!
define
d
(
'QA_VERSION'
))
{
// don't allow this page to be requested directly from browser
heade
r
(
'Location: ../../'
);
exi
t
;
}
require_onc
e
QA_INCLUDE_DI
R
.
'db/recalc.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'db/post-create.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'db/points.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'db/selects.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'db/admin.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'db/users.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'app/options.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'app/post-create.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'app/post-update.php'
;
class
Q2A_App_Recalc_Main
{
protecte
d
$state
;
protecte
d
$operation
;
protecte
d
$length
;
protecte
d
$next
;
protecte
d
$done
;
/**
* Initialize the counts of resource usage.
*/
publi
c
function
__construct
(
$state
)
{
$this
->
state
=
$state
;
lis
t
(
$this
->
operation
,
$this
->
length
,
$this
->
next
,
$this
->
done
)
=
explod
e
(
"
\t
"
,
$state
.
"
\t\t\t\t
"
);
}
publi
c
function
getState
()
{
retur
n
$this
->
state
;
}
publi
c
function
performStep
()
{
i
f
(
!
method_exist
s
(
$this
,
$this
->
operation
))
{
$this
->
state
=
''
;
retur
n
false
;
}
$continue
=
$this
->
{
$this
->
operation
}();
i
f
(
$continue
)
{
$this
->
state
=
$this
->
operation
.
"
\t
"
.
$this
->
length
.
"
\t
"
.
$this
->
next
.
"
\t
"
.
$this
->
done
;
}
retur
n
$continue
&&
$this
->
done
<
$this
->
length
;
}
privat
e
function
DoReindexContent
()
{
$this
->
transition
(
'doreindexcontent_pagereindex'
);
}
privat
e
function
DoReindexContent_PageReindex
()
{
$pages
=
qa_db_pages_get_for_reindexin
g
(
$this
->
next
,
10
);
i
f
(
!
coun
t
(
$pages
))
{
$this
->
transition
(
'doreindexcontent_postcount'
);
retur
n
false
;
}
require_onc
e
QA_INCLUDE_DI
R
.
'app/format.php'
;
$lastpageid
=
ma
x
(
array_key
s
(
$pages
));
foreac
h
(
$pages
a
s
$pageid
=>
$page
)
{
i
f
(
!
(
$page
[
'flags'
]
&
QA_PAGE_FLAGS_EXTERNA
L
))
{
$searchmodules_u
=
qa_load_modules_wit
h
(
'search'
,
'unindex_page'
);
foreac
h
(
$searchmodules_u
a
s
$searchmodule
)
{
$searchmodule
->
unindex_page
(
$pageid
);
}
$searchmodules_i
=
qa_load_modules_wit
h
(
'search'
,
'index_page'
);
i
f
(
coun
t
(
$searchmodules_i
))
{
$indextext
=
qa_viewer_tex
t
(
$page
[
'content'
],
'html'
);
foreac
h
(
$searchmodules_i
a
s
$searchmodule
)
{
$searchmodule
->
index_page
(
$pageid
,
$page
[
'tags'
],
$page
[
'heading'
],
$page
[
'content'
],
'html'
,
$indextext
);
}
}
}
}
$this
->
next
=
1
+
$lastpageid
;
$this
->
done
+=
coun
t
(
$pages
);
retur
n
true
;
}
privat
e
function
DoReindexContent_PostCount
()
{
qa_db_qcount_updat
e
();
qa_db_acount_updat
e
();
qa_db_ccount_updat
e
();
$this
->
transition
(
'doreindexcontent_postreindex'
);
retur
n
false
;
}
privat
e
function
DoReindexContent_PostReindex
()
{
$posts
=
qa_db_posts_get_for_reindexin
g
(
$this
->
next
,
10
);
i
f
(
!
coun
t
(
$posts
))
{
qa_db_truncate_indexe
s
(
$this
->
next
);
$this
->
transition
(
'doreindexposts_wordcount'
);
retur
n
false
;
}
require_onc
e
QA_INCLUDE_DI
R
.
'app/format.php'
;
$lastpostid
=
ma
x
(
array_key
s
(
$posts
));
qa_db_prepare_for_reindexin
g
(
$this
->
next
,
$lastpostid
);
qa_suspend_update_count
s
();
foreac
h
(
$posts
a
s
$postid
=>
$post
)
{
qa_post_uninde
x
(
$postid
);
qa_post_inde
x
(
$postid
,
$post
[
'type'
],
$post
[
'questionid'
],
$post
[
'parentid'
],
$post
[
'title'
],
$post
[
'content'
],
$post
[
'format'
],
qa_viewer_tex
t
(
$post
[
'content'
],
$post
[
'format'
]),
$post
[
'tags'
],
$post
[
'categoryid'
]);
}
$this
->
next
=
1
+
$lastpostid
;
$this
->
done
+=
coun
t
(
$posts
);
retur
n
true
;
}
privat
e
function
DoReindexPosts_WordCount
()
{
$wordids
=
qa_db_words_prepare_for_recountin
g
(
$this
->
next
,
1000
);
i
f
(
!
coun
t
(
$wordids
))
{
qa_db_tagcount_updat
e
();
// this is quick so just do it here
$this
->
transition
(
'doreindexposts_complete'
);
retur
n
false
;
}
$lastwordid
=
ma
x
(
$wordids
);
qa_db_words_recoun
t
(
$this
->
next
,
$lastwordid
);
$this
->
next
=
1
+
$lastwordid
;
$this
->
done
+=
coun
t
(
$wordids
);
retur
n
true
;
}
privat
e
function
DoRecountPosts
()
{
$this
->
transition
(
'dorecountposts_postcount'
);
retur
n
false
;
}
privat
e
function
DoRecountPosts_PostCount
()
{
qa_db_qcount_updat
e
();
qa_db_acount_updat
e
();
qa_db_ccount_updat
e
();
qa_db_unaqcount_updat
e
();
qa_db_unselqcount_updat
e
();
$this
->
transition
(
'dorecountposts_votecount'
);
retur
n
false
;
}
privat
e
function
DoRecountPosts_VoteCount
()
{
$postids
=
qa_db_posts_get_for_recountin
g
(
$this
->
next
,
1000
);
i
f
(
!
coun
t
(
$postids
))
{
$this
->
transition
(
'dorecountposts_acount'
);
retur
n
false
;
}
$lastpostid
=
ma
x
(
$postids
);
qa_db_posts_votes_recoun
t
(
$this
->
next
,
$lastpostid
);
$this
->
next
=
1
+
$lastpostid
;
$this
->
done
+=
coun
t
(
$postids
);
retur
n
true
;
}
privat
e
function
DoRecountPosts_Acount
()
{
$postids
=
qa_db_posts_get_for_recountin
g
(
$this
->
next
,
1000
);
i
f
(
coun
t
(
$postids
))
{
qa_db_unupaqcount_updat
e
();
$this
->
transition
(
'dorecountposts_complete'
);
retur
n
false
;
}
$lastpostid
=
ma
x
(
$postids
);
qa_db_posts_answers_recoun
t
(
$this
->
next
,
$lastpostid
);
$this
->
next
=
1
+
$lastpostid
;
$this
->
done
+=
coun
t
(
$postids
);
retur
n
true
;
}
privat
e
function
DoRecalcPoints
()
{
$this
->
transition
(
'dorecalcpoints_usercount'
);
retur
n
false
;
}
privat
e
function
DoRecalcPoints_UserCount
()
{
qa_db_userpointscount_updat
e
();
// for progress update - not necessarily accurate
qa_db_uapprovecount_updat
e
();
// needs to be somewhere and this is the most appropriate place
$this
->
transition
(
'dorecalcpoints_recalc'
);
retur
n
false
;
}
privat
e
function
DoRecalcPoints_Recalc
()
{
$default_recalccount
=
10
;
$userids
=
qa_db_users_get_for_recalc_point
s
(
$this
->
next
,
$default_recalccount
+
1
);
// get one extra so we know where to start from next
$gotcount
=
coun
t
(
$userids
);
$recalccount
=
mi
n
(
$default_recalccount
,
$gotcount
);
// can't recalc more than we got
i
f
(
$recalccount
>
0
)
{
$lastuserid
=
$userids
[
$recalccount
-
1
];
qa_db_users_recalc_point
s
(
$this
->
next
,
$lastuserid
);
$this
->
done
+=
$recalccount
;
}
els
e
{
$lastuserid
=
$this
->
next
;
// for truncation
}
i
f
(
$gotcount
>
$recalccount
)
{
// more left to do
$this
->
next
=
$userids
[
$recalccount
];
// start next round at first one not recalculated
retur
n
true
;
}
els
e
{
qa_db_truncate_userpoint
s
(
$lastuserid
);
qa_db_userpointscount_updat
e
();
// quick so just do it here
$this
->
transition
(
'dorecalcpoints_complete'
);
retur
n
false
;
}
}
privat
e
function
DoRefillEvents
()
{
$this
->
transition
(
'dorefillevents_qcount'
);
retur
n
false
;
}
privat
e
function
DoRefillEvents_Qcount
()
{
qa_db_qcount_updat
e
();
$this
->
transition
(
'dorefillevents_refill'
);
retur
n
false
;
}
privat
e
function
DoRefillEvents_Refill
()
{
$questionids
=
qa_db_qs_get_for_event_refillin
g
(
$this
->
next
,
1
);
i
f
(
!
coun
t
(
$questionids
))
{
$this
->
transition
(
'dorefillevents_complete'
);
retur
n
false
;
}
require_onc
e
QA_INCLUDE_DI
R
.
'app/events.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'app/updates.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'util/sort.php'
;
$lastquestionid
=
ma
x
(
$questionids
);
foreac
h
(
$questionids
a
s
$questionid
)
{
// Retrieve all posts relating to this question
lis
t
(
$question
,
$childposts
,
$achildposts
)
=
qa_db_select_with_pendin
g
(
qa_db_full_post_selectspe
c
(
null
,
$questionid
),
qa_db_full_child_posts_selectspe
c
(
null
,
$questionid
),
qa_db_full_a_child_posts_selectspe
c
(
null
,
$questionid
)
);
// Merge all posts while preserving keys as postids
$posts
=
arra
y
(
$questionid
=>
$question
);
foreac
h
(
$childposts
a
s
$postid
=>
$post
)
{
$posts
[
$postid
]
=
$post
;
}
foreac
h
(
$achildposts
a
s
$postid
=>
$post
)
{
$posts
[
$postid
]
=
$post
;
}
// Creation and editing of each post
foreac
h
(
$posts
a
s
$postid
=>
$post
)
{
$followonq
=
(
$post
[
'basetype'
]
==
'Q'
)
&&
(
$postid
!=
$questionid
);
i
f
(
$followonq
)
{
$updatetype
=
QA_UPDATE_FOLLOW
S
;
}
elsei
f
(
$post
[
'basetype'
]
==
'C'
&&
@
$posts
[
$post
[
'parentid'
]][
'basetype'
]
==
'Q'
)
{
$updatetype
=
QA_UPDATE_C_FOR_
Q
;
}
elsei
f
(
$post
[
'basetype'
]
==
'C'
&&
@
$posts
[
$post
[
'parentid'
]][
'basetype'
]
==
'A'
)
{
$updatetype
=
QA_UPDATE_C_FOR_
A
;
}
els
e
{
$updatetype
=
null
;
}
qa_create_event_for_q_use
r
(
$questionid
,
$postid
,
$updatetype
,
$post
[
'userid'
],
@
$posts
[
$post
[
'parentid'
]][
'userid'
],
$post
[
'created'
]);
i
f
(
isse
t
(
$post
[
'updated'
])
&&
!
$followonq
)
{
qa_create_event_for_q_use
r
(
$questionid
,
$postid
,
$post
[
'updatetype'
],
$post
[
'lastuserid'
],
$post
[
'userid'
],
$post
[
'updated'
]);
}
}
// Tags and categories of question
qa_create_event_for_tag
s
(
$question
[
'tags'
],
$questionid
,
null
,
$question
[
'userid'
],
$question
[
'created'
]);
qa_create_event_for_categor
y
(
$question
[
'categoryid'
],
$questionid
,
null
,
$question
[
'userid'
],
$question
[
'created'
]);
// Collect comment threads
$parentidcomments
=
arra
y
();
foreac
h
(
$posts
a
s
$postid
=>
$post
)
{
i
f
(
$post
[
'basetype'
]
==
'C'
)
{
$parentidcomments
[
$post
[
'parentid'
]][
$postid
]
=
$post
;
}
}
// For each comment thread, notify all previous comment authors of each comment in the thread (could get slow)
foreac
h
(
$parentidcomments
a
s
$parentid
=>
$comments
)
{
$keyuserids
=
arra
y
();
qa_sort_b
y
(
$comments
,
'created'
);
foreac
h
(
$comments
a
s
$comment
)
{
foreac
h
(
$keyuserids
a
s
$keyuserid
=>
$dummy
)
{
i
f
(
$keyuserid
!=
$comment
[
'userid'
]
&&
$keyuserid
!=
@
$posts
[
$parentid
][
'userid'
])
{
qa_db_event_create_not_entit
y
(
$keyuserid
,
$questionid
,
$comment
[
'postid'
],
QA_UPDATE_FOLLOW
S
,
$comment
[
'userid'
],
$comment
[
'created'
]);
}
}
i
f
(
isse
t
(
$comment
[
'userid'
]))
{
$keyuserids
[
$comment
[
'userid'
]]
=
true
;
}
}
}
}
$this
->
next
=
1
+
$lastquestionid
;
$this
->
done
+=
coun
t
(
$questionids
);
retur
n
true
;
}
privat
e
function
DoRecalcCategories
()
{
$this
->
transition
(
'dorecalccategories_postcount'
);
retur
n
false
;
}
privat
e
function
DoRecalcCategories_PostCount
()
{
qa_db_acount_updat
e
();
qa_db_ccount_updat
e
();
$this
->
transition
(
'dorecalccategories_postupdate'
);
retur
n
false
;
}
privat
e
function
DoRecalcCategories_PostUpdate
()
{
$postids
=
qa_db_posts_get_for_recategorizin
g
(
$this
->
next
,
100
);
i
f
(
!
coun
t
(
$postids
))
{
$this
->
transition
(
'dorecalccategories_recount'
);
retur
n
false
;
}
$lastpostid
=
ma
x
(
$postids
);
qa_db_posts_recalc_categoryi
d
(
$this
->
next
,
$lastpostid
);
qa_db_posts_calc_category_pat
h
(
$this
->
next
,
$lastpostid
);
$this
->
next
=
1
+
$lastpostid
;
$this
->
done
+=
coun
t
(
$postids
);
retur
n
true
;
}
privat
e
function
DoRecalcCategories_Recount
()
{
$categoryids
=
qa_db_categories_get_for_recalc
s
(
$this
->
next
,
10
);
i
f
(
!
coun
t
(
$categoryids
))
{
$this
->
transition
(
'dorecalccategories_backpaths'
);
retur
n
false
;
}
$lastcategoryid
=
ma
x
(
$categoryids
);
foreac
h
(
$categoryids
a
s
$categoryid
)
{
qa_db_ifcategory_qcount_updat
e
(
$categoryid
);
}
$this
->
next
=
1
+
$lastcategoryid
;
$this
->
done
+=
coun
t
(
$categoryids
);
retur
n
true
;
}
privat
e
function
DoRecalcCategories_BackPaths
()
{
$categoryids
=
qa_db_categories_get_for_recalc
s
(
$this
->
next
,
10
);
i
f
(
!
coun
t
(
$categoryids
))
{
$this
->
transition
(
'dorecalccategories_complete'
);
retur
n
false
;
}
$lastcategoryid
=
ma
x
(
$categoryids
);
qa_db_categories_recalc_backpath
s
(
$this
->
next
,
$lastcategoryid
);
$this
->
next
=
1
+
$lastcategoryid
;
$this
->
done
+=
coun
t
(
$categoryids
);
retur
n
true
;
}
privat
e
function
DoDeleteHidden
()
{
$this
->
transition
(
'dodeletehidden_comments'
);
retur
n
false
;
}
privat
e
function
DoDeleteHidden_Comments
()
{
$posts
=
qa_db_posts_get_for_deletin
g
(
'C'
,
$this
->
next
,
1
);
i
f
(
!
coun
t
(
$posts
))
{
$this
->
transition
(
'dodeletehidden_answers'
);
retur
n
false
;
}
require_onc
e
QA_INCLUDE_DI
R
.
'app/posts.php'
;
$postid
=
$posts
[
0
];
qa_post_delet
e
(
$postid
);
$this
->
next
=
1
+
$postid
;
$this
->
done
++
;
retur
n
true
;
}
privat
e
function
DoDeleteHidden_Answers
()
{
$posts
=
qa_db_posts_get_for_deletin
g
(
'A'
,
$this
->
next
,
1
);
i
f
(
!
coun
t
(
$posts
))
{
$this
->
transition
(
'dodeletehidden_questions'
);
retur
n
false
;
}
require_onc
e
QA_INCLUDE_DI
R
.
'app/posts.php'
;
$postid
=
$posts
[
0
];
qa_post_delet
e
(
$postid
);
$this
->
next
=
1
+
$postid
;
$this
->
done
++
;
retur
n
true
;
}
privat
e
function
dodeletehidden_questions
()
{
$posts
=
qa_db_posts_get_for_deletin
g
(
'Q'
,
$this
->
next
,
1
);
i
f
(
!
coun
t
(
$posts
))
{
$this
->
transition
(
'dodeletehidden_complete'
);
retur
n
false
;
}
require_onc
e
QA_INCLUDE_DI
R
.
'app/posts.php'
;
$postid
=
$posts
[
0
];
qa_post_delet
e
(
$postid
);
$this
->
next
=
1
+
$postid
;
$this
->
done
++
;
retur
n
true
;
}
privat
e
function
DoBlobsToDisk
()
{
$this
->
transition
(
'doblobstodisk_move'
);
retur
n
false
;
}
privat
e
function
DoBlobsToDisk_Move
()
{
$blob
=
qa_db_get_next_blob_in_d
b
(
$this
->
next
);
i
f
(
!
isse
t
(
$blob
))
{
$this
->
transition
(
'doblobstodisk_complete'
);
retur
n
false
;
}
require_onc
e
QA_INCLUDE_DI
R
.
'app/blobs.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'db/blobs.php'
;
i
f
(
qa_write_blob_fil
e
(
$blob
[
'blobid'
],
$blob
[
'content'
],
$blob
[
'format'
]))
{
qa_db_blob_set_conten
t
(
$blob
[
'blobid'
],
null
);
}
$this
->
next
=
1
+
$blob
[
'blobid'
];
$this
->
done
++
;
retur
n
true
;
}
privat
e
function
DoBlobsToDB
()
{
$this
->
transition
(
'doblobstodb_move'
);
retur
n
false
;
}
privat
e
function
DoBlobsToDB_Move
()
{
$blob
=
qa_db_get_next_blob_on_dis
k
(
$this
->
next
);
i
f
(
!
isse
t
(
$blob
))
{
$this
->
transition
(
'doblobstodb_complete'
);
retur
n
false
;
}
require_onc
e
QA_INCLUDE_DI
R
.
'app/blobs.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'db/blobs.php'
;
$content
=
qa_read_blob_fil
e
(
$blob
[
'blobid'
],
$blob
[
'format'
]);
qa_db_blob_set_conten
t
(
$blob
[
'blobid'
],
$content
);
qa_delete_blob_fil
e
(
$blob
[
'blobid'
],
$blob
[
'format'
]);
$this
->
next
=
1
+
$blob
[
'blobid'
];
$this
->
done
++
;
retur
n
true
;
}
privat
e
function
DoCacheTrim
()
{
$this
->
transition
(
'docachetrim_process'
);
retur
n
false
;
}
privat
e
function
DoCacheClear
()
{
$this
->
transition
(
'docacheclear_process'
);
retur
n
false
;
}
privat
e
function
DoCacheTrim_Process
()
{
retur
n
$this
->
docacheclear_process
();
}
privat
e
function
DoCacheClear_Process
()
{
$cacheDriver
=
Q
2
A_Storage_CacheFactor
y
::
getCacheDriver
();
$cacheStats
=
$cacheDriver
->
getStats
();
$limit
=
mi
n
(
$cacheStats
[
'files'
],
20
);
i
f
(
!
(
$cacheStats
[
'files'
]
>
0
&&
$this
->
next
<=
$this
->
length
))
{
$this
->
transition
(
'docacheclear_complete'
);
retur
n
false
;
}
$deleted
=
$cacheDriver
->
clear
(
$limit
,
$this
->
next
,
(
$this
->
operation
===
'docachetrim_process'
));
$this
->
done
+=
$deleted
;
$this
->
next
+=
$limit
-
$deleted
;
// skip files that weren't deleted on next iteration
retur
n
true
;
}
/**
* Change the $state to represent the beginning of a new $operation
* @param $newOoperation
*/
publi
c
function
transition
(
$newOperation
)
{
$this
->
operation
=
$newOperation
;
$this
->
length
=
$this
->
stageLength
();
$this
->
next
=
(
QA_FINAL_EXTERNAL_USER
S
&&
(
$newOperation
==
'dorecalcpoints_recalc'
))
?
''
:
0
;
$this
->
done
=
0
;
$this
->
state
=
$newOperation
.
"
\t
"
.
$this
->
length
.
"
\t
"
.
$this
->
next
.
"
\t
"
.
$this
->
done
;
}
/**
* Return how many steps there will be in recalculation $operation
* @return int
*/
privat
e
function
stageLength
()
{
switc
h
(
$this
->
operation
)
{
cas
e
'doreindexcontent_pagereindex'
:
retur
n
qa_db_count_page
s
();
cas
e
'doreindexcontent_postreindex'
:
retur
n
qa_op
t
(
'cache_qcount'
)
+
qa_op
t
(
'cache_acount'
)
+
qa_op
t
(
'cache_ccount'
);
cas
e
'doreindexposts_wordcount'
:
retur
n
qa_db_count_word
s
();
cas
e
'dorecalcpoints_recalc'
:
retur
n
qa_op
t
(
'cache_userpointscount'
);
cas
e
'dorecountposts_votecount'
:
cas
e
'dorecountposts_acount'
:
cas
e
'dorecalccategories_postupdate'
:
retur
n
qa_db_count_post
s
();
cas
e
'dorefillevents_refill'
:
retur
n
qa_op
t
(
'cache_qcount'
)
+
qa_db_count_post
s
(
'Q_HIDDEN'
);
cas
e
'dorecalccategories_recount'
:
cas
e
'dorecalccategories_backpaths'
:
retur
n
qa_db_count_categorie
s
();
cas
e
'dodeletehidden_comments'
:
retur
n
coun
t
(
qa_db_posts_get_for_deletin
g
(
'C'
));
cas
e
'dodeletehidden_answers'
:
retur
n
coun
t
(
qa_db_posts_get_for_deletin
g
(
'A'
));
cas
e
'dodeletehidden_questions'
:
retur
n
coun
t
(
qa_db_posts_get_for_deletin
g
(
'Q'
));
cas
e
'doblobstodisk_move'
:
retur
n
qa_db_count_blobs_in_d
b
();
cas
e
'doblobstodb_move'
:
retur
n
qa_db_count_blobs_on_dis
k
();
cas
e
'docachetrim_process'
:
cas
e
'docacheclear_process'
:
$cacheDriver
=
Q
2
A_Storage_CacheFactor
y
::
getCacheDriver
();
$cacheStats
=
$cacheDriver
->
getStats
();
retur
n
$cacheStats
[
'files'
];
}
retur
n
0
;
}
/**
* Return the translated language ID string replacing the progress and total in it.
* @access private
* @param string $langId Language string ID that contains 2 placeholders (^1 and ^2)
* @param int $progress Amount of processed elements
* @param int $total Total amount of elements
*
* @return string Returns the language string ID with their placeholders replaced with
* the formatted progress and total numbers
*/
privat
e
function
progressLang
(
$langId
,
$progress
,
$total
)
{
retur
n
strt
r
(
qa_lan
g
(
$langId
),
arra
y
(
'^1'
=>
qa_format_numbe
r
(
$progress
),
'^2'
=>
qa_format_numbe
r
(
$total
),
));
}
/**
* Return a string which gives a user-viewable version of $state
* @return string
*/
publi
c
function
getMessage
()
{
require_onc
e
QA_INCLUDE_DI
R
.
'app/format.php'
;
$this
->
done
=
(
in
t
)
$this
->
done
;
$this
->
length
=
(
in
t
)
$this
->
length
;
switc
h
(
$this
->
operation
)
{
cas
e
'doreindexcontent_postcount'
:
cas
e
'dorecountposts_postcount'
:
cas
e
'dorecalccategories_postcount'
:
cas
e
'dorefillevents_qcount'
:
$message
=
qa_lan
g
(
'admin/recalc_posts_count'
);
brea
k
;
cas
e
'doreindexcontent_pagereindex'
:
$message
=
$this
->
progressLang
(
'admin/reindex_pages_reindexed'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'doreindexcontent_postreindex'
:
$message
=
$this
->
progressLang
(
'admin/reindex_posts_reindexed'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'doreindexposts_complete'
:
$message
=
qa_lan
g
(
'admin/reindex_posts_complete'
);
brea
k
;
cas
e
'doreindexposts_wordcount'
:
$message
=
$this
->
progressLang
(
'admin/reindex_posts_wordcounted'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'dorecountposts_votecount'
:
$message
=
$this
->
progressLang
(
'admin/recount_posts_votes_recounted'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'dorecountposts_acount'
:
$message
=
$this
->
progressLang
(
'admin/recount_posts_as_recounted'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'dorecountposts_complete'
:
$message
=
qa_lan
g
(
'admin/recount_posts_complete'
);
brea
k
;
cas
e
'dorecalcpoints_usercount'
:
$message
=
qa_lan
g
(
'admin/recalc_points_usercount'
);
brea
k
;
cas
e
'dorecalcpoints_recalc'
:
$message
=
$this
->
progressLang
(
'admin/recalc_points_recalced'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'dorecalcpoints_complete'
:
$message
=
qa_lan
g
(
'admin/recalc_points_complete'
);
brea
k
;
cas
e
'dorefillevents_refill'
:
$message
=
$this
->
progressLang
(
'admin/refill_events_refilled'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'dorefillevents_complete'
:
$message
=
qa_lan
g
(
'admin/refill_events_complete'
);
brea
k
;
cas
e
'dorecalccategories_postupdate'
:
$message
=
$this
->
progressLang
(
'admin/recalc_categories_updated'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'dorecalccategories_recount'
:
$message
=
$this
->
progressLang
(
'admin/recalc_categories_recounting'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'dorecalccategories_backpaths'
:
$message
=
$this
->
progressLang
(
'admin/recalc_categories_backpaths'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'dorecalccategories_complete'
:
$message
=
qa_lan
g
(
'admin/recalc_categories_complete'
);
brea
k
;
cas
e
'dodeletehidden_comments'
:
$message
=
$this
->
progressLang
(
'admin/hidden_comments_deleted'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'dodeletehidden_answers'
:
$message
=
$this
->
progressLang
(
'admin/hidden_answers_deleted'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'dodeletehidden_questions'
:
$message
=
$this
->
progressLang
(
'admin/hidden_questions_deleted'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'dodeletehidden_complete'
:
$message
=
qa_lan
g
(
'admin/delete_hidden_complete'
);
brea
k
;
cas
e
'doblobstodisk_move'
:
cas
e
'doblobstodb_move'
:
$message
=
$this
->
progressLang
(
'admin/blobs_move_moved'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'doblobstodisk_complete'
:
cas
e
'doblobstodb_complete'
:
$message
=
qa_lan
g
(
'admin/blobs_move_complete'
);
brea
k
;
cas
e
'docachetrim_process'
:
cas
e
'docacheclear_process'
:
$message
=
$this
->
progressLang
(
'admin/caching_delete_progress'
,
$this
->
done
,
$this
->
length
);
brea
k
;
cas
e
'docacheclear_complete'
:
$message
=
qa_lan
g
(
'admin/caching_delete_complete'
);
brea
k
;
defaul
t
:
$message
=
''
;
brea
k
;
}
retur
n
$message
;
}
}
qa-include/db/install.php
View file @
1c21830c
...
...
@@ -78,7 +78,7 @@ function qa_db_table_definitions()
* In MySQL versions prior to 5.0.3, VARCHAR(x) columns will be silently converted to TEXT where x>255
* See box at top of /qa-include/app/recalc.php for a list of redundant (non-normal) information in the database
* See box at top of /qa-include/app/recalc
/RecalcMain
.php for a list of redundant (non-normal) information in the database
* Starting in version 1.2, we explicitly name keys and foreign key constraints, instead of allowing MySQL
to name these by default. Our chosen names match the default names that MySQL would have assigned, and
...
...
@@ -769,7 +769,7 @@ function qa_db_default_userfields_sql()
*/
function
qa_db_upgrade_tables
()
{
require_onc
e
QA_INCLUDE_DI
R
.
'app/recalc.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'app/recalc
/RecalcMain
.php'
;
$definitions
=
qa_db_table_definition
s
();
$keyrecalc
=
arra
y
();
...
...
@@ -1611,16 +1611,17 @@ function qa_db_upgrade_tables()
// Perform any necessary recalculations, as determined by upgrade steps
foreac
h
(
$keyrecalc
a
s
$state
=>
$dummy
)
{
whil
e
(
$state
)
{
foreac
h
(
array_key
s
(
$keyrecalc
)
a
s
$state
)
{
$recalc
=
ne
w
Q
2
A_App_Recalc_Mai
n
(
$state
);
whil
e
(
$recalc
->
getState
())
{
set_time_limi
t
(
60
);
$stoptime
=
tim
e
()
+
2
;
whil
e
(
qa_recalc_perform_ste
p
(
$state
)
&&
(
tim
e
()
<
$stoptime
))
whil
e
(
$recalc
->
performStep
(
)
&&
(
tim
e
()
<
$stoptime
))
;
qa_db_upgrade_progres
s
(
qa_recalc_get_messag
e
(
$state
));
qa_db_upgrade_progres
s
(
$recalc
->
getMmessage
(
));
}
}
}
...
...
qa-include/pages/admin/admin-recalc.php
View file @
1c21830c
...
...
@@ -25,7 +25,7 @@ if (!defined('QA_VERSION')) { // don't allow this page to be requested directly
}
require_onc
e
QA_INCLUDE_DI
R
.
'app/admin.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'app/recalc.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'app/recalc
/RecalcMain
.php'
;
// Check we have administrative privileges
...
...
@@ -71,15 +71,16 @@ if ($recalcnow) {
<?php
whil
e
(
$state
)
{
$recalc
=
ne
w
Q
2
A_App_Recalc_Mai
n
(
$state
);
whil
e
(
$recalc
->
getState
())
{
set_time_limi
t
(
60
);
$stoptime
=
tim
e
()
+
2
;
// run in lumps of two seconds...
whil
e
(
qa_recalc_perform_ste
p
(
$state
)
&&
tim
e
()
<
$stoptime
)
whil
e
(
$recalc
->
performStep
(
)
&&
tim
e
()
<
$stoptime
)
;
ech
o
qa_htm
l
(
qa_recalc_get_messag
e
(
$state
)
)
.
str_repea
t
(
' '
,
1024
)
.
"<br>
\n
"
;
ech
o
qa_htm
l
(
$recalc
->
getMessage
)
.
str_repea
t
(
' '
,
1024
)
.
"<br>
\n
"
;
flus
h
();
slee
p
(
1
);
// ... then rest for one
...
...
qa-include/qa-app-recalc.php
View file @
1c21830c
...
...
@@ -12,4 +12,4 @@ if (defined('QA_DEBUG_PERFORMANCE') && QA_DEBUG_PERFORMANCE) {
trigger_erro
r
(
'Included file '
.
basenam
e
(
__FILE_
_
)
.
' is deprecated'
);
}
require_onc
e
QA_INCLUDE_DI
R
.
'app/recalc.php'
;
require_onc
e
QA_INCLUDE_DI
R
.
'app/recalc
/RecalcMain
.php'
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment