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
788f260c
Commit
788f260c
authored
Sep 04, 2017
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split views increment out of hotness function
parent
d46809f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
10 deletions
+22
-10
page.php
qa-include/app/page.php
+6
-1
hotness.php
qa-include/db/hotness.php
+16
-9
No files found.
qa-include/app/page.php
View file @
788f260c
...
@@ -370,7 +370,12 @@ function qa_do_content_stats($qa_content)
...
@@ -370,7 +370,12 @@ function qa_do_content_stats($qa_content)
{
{
if
(
isset
(
$qa_content
[
'inc_views_postid'
]))
{
if
(
isset
(
$qa_content
[
'inc_views_postid'
]))
{
require_once
QA_INCLUDE_DIR
.
'db/hotness.php'
;
require_once
QA_INCLUDE_DIR
.
'db/hotness.php'
;
qa_db_hotness_update
(
$qa_content
[
'inc_views_postid'
],
null
,
true
);
qa_db_increment_views
(
$qa_content
[
'inc_views_postid'
]);
if
(
qa_opt
(
'recalc_hotness_q_view'
))
{
qa_db_hotness_update
(
$qa_content
[
'inc_views_postid'
]);
}
return
true
;
return
true
;
}
}
...
...
qa-include/db/hotness.php
View file @
788f260c
...
@@ -26,6 +26,20 @@ if (!defined('QA_VERSION')) { // don't allow this page to be requested directly
...
@@ -26,6 +26,20 @@ if (!defined('QA_VERSION')) { // don't allow this page to be requested directly
/**
/**
* Increment the views counter for the post (if different IP from last view).
* @param int $postid The ID of the post
* @return void
*/
function
qa_db_increment_views
(
$postid
)
{
$query
=
'UPDATE ^posts SET views=views+1, lastviewip=UNHEX($) WHERE postid=# AND (lastviewip IS NULL OR lastviewip!=UNHEX($))'
;
$ipHex
=
bin2hex
(
@
inet_pton
(
qa_remote_ip_address
()));
qa_db_query_sub
(
$query
,
$ipHex
,
$postid
,
$ipHex
);
}
/**
* Recalculate the hotness in the database for posts $firstpostid to $lastpostid (if specified)
* Recalculate the hotness in the database for posts $firstpostid to $lastpostid (if specified)
* If $viewincrement is true, also increment the views counter for the post (if different IP from last view),
* If $viewincrement is true, also increment the views counter for the post (if different IP from last view),
* and include that in the hotness calculation
* and include that in the hotness calculation
...
@@ -47,9 +61,8 @@ function qa_db_hotness_update($firstpostid, $lastpostid = null, $viewincrement =
...
@@ -47,9 +61,8 @@ function qa_db_hotness_update($firstpostid, $lastpostid = null, $viewincrement =
'((TO_DAYS(a.acreated)-734138)*86400.0+TIME_TO_SEC(a.acreated))*# + '
.
'((TO_DAYS(a.acreated)-734138)*86400.0+TIME_TO_SEC(a.acreated))*# + '
.
'(a.acount+0.0)*# + '
.
'(a.acount+0.0)*# + '
.
'(a.netvotes+0.0)*# + '
.
'(a.netvotes+0.0)*# + '
.
'(a.views+0.0+#)*#'
.
'(a.views+0.0)*#'
.
')'
.
(
$viewincrement
?
', x.views=x.views+1, x.lastviewip=UNHEX($)'
:
''
)
.
') WHERE x.postid=a.postid'
;
' WHERE x.postid=a.postid'
.
(
$viewincrement
?
' AND (x.lastviewip IS NULL OR x.lastviewip!=UNHEX($))'
:
''
);
// Additional multiples based on empirical analysis of activity on Q2A meta site to give approx equal influence for all factors
// Additional multiples based on empirical analysis of activity on Q2A meta site to give approx equal influence for all factors
...
@@ -60,15 +73,9 @@ function qa_db_hotness_update($firstpostid, $lastpostid = null, $viewincrement =
...
@@ -60,15 +73,9 @@ function qa_db_hotness_update($firstpostid, $lastpostid = null, $viewincrement =
qa_opt
(
'hot_weight_a_age'
),
qa_opt
(
'hot_weight_a_age'
),
qa_opt
(
'hot_weight_answers'
)
*
160000
,
qa_opt
(
'hot_weight_answers'
)
*
160000
,
qa_opt
(
'hot_weight_votes'
)
*
160000
,
qa_opt
(
'hot_weight_votes'
)
*
160000
,
$viewincrement
?
1
:
0
,
qa_opt
(
'hot_weight_views'
)
*
4000
,
qa_opt
(
'hot_weight_views'
)
*
4000
,
);
);
if
(
$viewincrement
)
{
$ipHex
=
bin2hex
(
@
inet_pton
(
qa_remote_ip_address
()));
array_push
(
$arguments
,
$ipHex
,
$ipHex
);
}
qa_db_query_raw
(
qa_db_apply_sub
(
$query
,
$arguments
));
qa_db_query_raw
(
qa_db_apply_sub
(
$query
,
$arguments
));
}
}
}
}
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