Created
December 14, 2017 17:27
-
-
Save jhugman/b482617c4383d2c7b23dc695e4e68780 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH tmpHistory AS ( | |
SELECT | |
historyID, | |
url, | |
title, | |
guid, | |
domain_id, | |
domain, | |
localVisitDate, | |
remoteVisitDate, | |
localVisitCount, | |
remoteVisitCount, | |
iconID, | |
iconURL, | |
iconDate, | |
iconType, | |
iconWidth, | |
frecencies, | |
is_bookmarked | |
FROM | |
( | |
SELECT | |
historyID, | |
url, | |
title, | |
guid, | |
domain_id, | |
domain, | |
MAX(localVisitDate) AS localVisitDate, | |
MAX(remoteVisitDate) AS remoteVisitDate, | |
SUM(localVisitCount) AS localVisitCount, | |
SUM(remoteVisitCount) AS remoteVisitCount, | |
MAX(frecency), | |
SUM(frecency) AS frecencies, | |
0 AS is_bookmarked | |
FROM | |
( | |
SELECT | |
*, | |
( | |
((2 + localVisitCount) * (2 + localVisitCount)) * MAX(2, 100 * 225 / (((1513179920524045 - localVisitDate) / 86400000000.0) * ((1513179920524045 - localVisitDate) / 86400000000.0) + 225)) + remoteVisitCount * MAX(1, 100 * 110 / (((1513179920524074 - remoteVisitDate) / 86400000000.0) * ((1513179920524074 - remoteVisitDate) / 86400000000.0) + 110)) | |
) | |
AS frecency | |
FROM | |
( | |
SELECT | |
history.id AS historyID, | |
history.url AS url, | |
history.title AS title, | |
history.guid AS guid, | |
domain_id, | |
domain, | |
COALESCE(MAX( | |
CASE | |
visits.is_local | |
WHEN | |
1 | |
THEN | |
visits.DATE | |
ELSE | |
0 | |
END | |
), 0) AS localVisitDate, COALESCE(MAX( | |
CASE | |
visits.is_local | |
WHEN | |
0 | |
THEN | |
visits.DATE | |
ELSE | |
0 | |
END | |
), 0) AS remoteVisitDate, COALESCE(SUM(visits.is_local), 0) AS localVisitCount, COALESCE(SUM( | |
CASE | |
visits.is_local | |
WHEN | |
1 | |
THEN | |
0 | |
ELSE | |
1 | |
END | |
), 0) AS remoteVisitCount | |
FROM | |
history | |
INNER JOIN | |
domains | |
ON domains.id = history.domain_id | |
INNER JOIN | |
visits | |
ON visits.siteID = history.id | |
LEFT JOIN | |
view_all_bookmarks | |
ON view_all_bookmarks.url = history.url | |
WHERE | |
( | |
((history.url LIKE '%git%') | |
OR | |
( | |
history.title LIKE '%git%' | |
) | |
) | |
) | |
AND view_all_bookmarks.url IS NULL | |
GROUP BY | |
historyID | |
) | |
WHERE | |
( | |
((localVisitCount > 0) | |
OR | |
( | |
remoteVisitCount > 0 | |
) | |
) | |
AND | |
( | |
(localVisitDate > 1497455120524082) | |
OR | |
( | |
remoteVisitDate > 1497455120524082 | |
) | |
) | |
) | |
ORDER BY | |
frecency DESC LIMIT 1000 | |
) | |
GROUP BY | |
historyID | |
ORDER BY | |
frecencies DESC LIMIT 100 | |
) | |
LEFT OUTER JOIN | |
view_history_id_favicon | |
ON historyID = view_history_id_favicon.id | |
ORDER BY | |
frecencies DESC | |
), | |
tmpBookmarks AS ( | |
SELECT | |
NULL AS historyID, | |
url, | |
title, | |
guid, | |
NULL AS domain_id, | |
NULL AS domain, | |
visitDate AS localVisitDate, | |
0 AS remoteVisitDate, | |
0 AS localVisitCount, | |
0 AS remoteVisitCount, | |
iconID, | |
iconURL, | |
iconDate, | |
iconType, | |
iconWidth, | |
visitDate AS frecencies, | |
1 AS is_bookmarked | |
FROM | |
view_awesomebar_bookmarks_with_favicons | |
WHERE | |
( | |
((url LIKE '%git%') | |
OR | |
( | |
title LIKE '%git%' | |
) | |
) | |
) | |
GROUP BY | |
url | |
ORDER BY | |
visitDate DESC LIMIT 5 | |
) | |
SELECT * FROM tmpHistory | |
UNION | |
SELECT * FROM tmpBookmarks | |
ORDER BY | |
is_bookmarked DESC, | |
frecencies DESC | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment