PostgreSQL - made all 'weight' calculating SQL expressions compatible with both databases, and made some GROUP BY queries more explicit about the fields they are selecting, for the same reason.
This commit is contained in:
parent
c02a2f1891
commit
115519a5e7
@ -169,8 +169,14 @@ class FavoritedAction extends Action
|
|||||||
|
|
||||||
function showContent()
|
function showContent()
|
||||||
{
|
{
|
||||||
|
if (common_config('db', 'type') == 'pgsql') {
|
||||||
|
$weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
|
||||||
|
} else {
|
||||||
|
$weightexpr='sum(exp(-(now() - fave.modified) / %s))';
|
||||||
|
}
|
||||||
|
|
||||||
$qry = 'SELECT notice.*, '.
|
$qry = 'SELECT notice.*, '.
|
||||||
'sum(exp(-(now() - fave.modified) / %s)) as weight ' .
|
$weightexpr . ' as weight ' .
|
||||||
'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
|
'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
|
||||||
'GROUP BY fave.notice_id ' .
|
'GROUP BY fave.notice_id ' .
|
||||||
'ORDER BY weight DESC';
|
'ORDER BY weight DESC';
|
||||||
|
@ -45,7 +45,7 @@ class GroupsByMembersSection extends GroupSection
|
|||||||
{
|
{
|
||||||
function getGroups()
|
function getGroups()
|
||||||
{
|
{
|
||||||
$qry = 'SELECT user_group.*, count(*) as value ' .
|
$qry = 'SELECT user_group.id, count(*) as value ' .
|
||||||
'FROM user_group JOIN group_member '.
|
'FROM user_group JOIN group_member '.
|
||||||
'ON user_group.id = group_member.group_id ' .
|
'ON user_group.id = group_member.group_id ' .
|
||||||
'GROUP BY user_group.id ' .
|
'GROUP BY user_group.id ' .
|
||||||
|
@ -45,7 +45,7 @@ class GroupsByPostsSection extends GroupSection
|
|||||||
{
|
{
|
||||||
function getGroups()
|
function getGroups()
|
||||||
{
|
{
|
||||||
$qry = 'SELECT user_group.*, count(*) as value ' .
|
$qry = 'SELECT user_group.id, count(*) as value ' .
|
||||||
'FROM user_group JOIN group_inbox '.
|
'FROM user_group JOIN group_inbox '.
|
||||||
'ON user_group.id = group_inbox.group_id ' .
|
'ON user_group.id = group_inbox.group_id ' .
|
||||||
'GROUP BY user_group.id ' .
|
'GROUP BY user_group.id ' .
|
||||||
|
@ -58,8 +58,14 @@ class GroupTagCloudSection extends TagCloudSection
|
|||||||
|
|
||||||
function getTags()
|
function getTags()
|
||||||
{
|
{
|
||||||
|
if (common_config('db', 'type') == 'pgsql') {
|
||||||
|
$weightexpr='sum(exp(-extract(epoch from (now() - notice_tag.created)) / %s))';
|
||||||
|
} else {
|
||||||
|
$weightexpr='sum(exp(-(now() - notice_tag.created) / %s))';
|
||||||
|
}
|
||||||
|
|
||||||
$qry = 'SELECT notice_tag.tag, '.
|
$qry = 'SELECT notice_tag.tag, '.
|
||||||
'sum(exp(-(now() - notice_tag.created)/%s)) as weight ' .
|
$weightexpr . ' as weight ' .
|
||||||
'FROM notice_tag JOIN notice ' .
|
'FROM notice_tag JOIN notice ' .
|
||||||
'ON notice_tag.notice_id = notice.id ' .
|
'ON notice_tag.notice_id = notice.id ' .
|
||||||
'JOIN group_inbox on group_inbox.notice_id = notice.id ' .
|
'JOIN group_inbox on group_inbox.notice_id = notice.id ' .
|
||||||
|
@ -58,8 +58,14 @@ class PersonalTagCloudSection extends TagCloudSection
|
|||||||
|
|
||||||
function getTags()
|
function getTags()
|
||||||
{
|
{
|
||||||
$qry = 'SELECT notice_tag.tag, '.
|
if (common_config('db', 'type') == 'pgsql') {
|
||||||
'sum(exp(-(now() - notice_tag.created)/%s)) as weight ' .
|
$weightexpr='sum(exp(-extract(epoch from (now() - notice_tag.created)) / %s))';
|
||||||
|
} else {
|
||||||
|
$weightexpr='sum(exp(-(now() - notice_tag.created) / %s))';
|
||||||
|
}
|
||||||
|
|
||||||
|
$qry = 'SELECT notice_tag.tag, '.
|
||||||
|
$weightexpr . ' as weight ' .
|
||||||
'FROM notice_tag JOIN notice ' .
|
'FROM notice_tag JOIN notice ' .
|
||||||
'ON notice_tag.notice_id = notice.id ' .
|
'ON notice_tag.notice_id = notice.id ' .
|
||||||
'WHERE notice.profile_id = %d ' .
|
'WHERE notice.profile_id = %d ' .
|
||||||
|
@ -48,10 +48,16 @@ class PopularNoticeSection extends NoticeSection
|
|||||||
{
|
{
|
||||||
function getNotices()
|
function getNotices()
|
||||||
{
|
{
|
||||||
$qry = 'SELECT notice.*, '.
|
if (common_config('db', 'type') == 'pgsql') {
|
||||||
'sum(exp(-(now() - fave.modified) / %s)) as weight ' .
|
$weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
|
||||||
|
} else {
|
||||||
|
$weightexpr='sum(exp(-(now() - fave.modified) / %s))';
|
||||||
|
}
|
||||||
|
|
||||||
|
$qry = 'SELECT notice.id, '.
|
||||||
|
$weightexpr . ' as weight ' .
|
||||||
'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
|
'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
|
||||||
'GROUP BY fave.notice_id ' .
|
'GROUP BY notice.id ' .
|
||||||
'ORDER BY weight DESC';
|
'ORDER BY weight DESC';
|
||||||
|
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user