Bug 520165 - Part2: Stop using history prefs to build date containers, r=mano

This commit is contained in:
Marco Bonardo 2009-12-22 13:05:04 +01:00
Родитель 007d749660
Коммит 4f52e11055
2 изменённых файлов: 41 добавлений и 15 удалений

Просмотреть файл

@ -183,11 +183,14 @@ using namespace mozilla::places;
// These macros are used when splitting history by date. // These macros are used when splitting history by date.
// These are the day containers and catch-all final container. // These are the day containers and catch-all final container.
#define ADDITIONAL_DATE_CONT_NUM 3 #define HISTORY_ADDITIONAL_DATE_CONT_NUM 3
// We use a guess of the number of months considering all of them 30 days // We use a guess of the number of months considering all of them 30 days
// long, but we split only the last 6 months. // long, but we split only the last 6 months.
#define DATE_CONT_NUM(_expireDays) \ #define HISTORY_DATE_CONT_NUM(_daysFromOldestVisit) \
(ADDITIONAL_DATE_CONT_NUM + NS_MIN(6, (_expireDays/30))) (HISTORY_ADDITIONAL_DATE_CONT_NUM + \
NS_MIN(6, (PRInt32)NS_ceilf((float)_daysFromOldestVisit/30)))
// Max number of containers, used to initialize the params hash.
#define HISTORY_DATE_CONT_MAX 10
// fraction of free pages in the database to force a vacuum between // fraction of free pages in the database to force a vacuum between
// MAX_TIME_BEFORE_VACUUM and MIN_TIME_BEFORE_VACUUM. // MAX_TIME_BEFORE_VACUUM and MIN_TIME_BEFORE_VACUUM.
@ -368,9 +371,6 @@ static const char* gXpcomShutdown = "xpcom-shutdown";
static const char* gAutoCompleteFeedback = "autocomplete-will-enter-text"; static const char* gAutoCompleteFeedback = "autocomplete-will-enter-text";
static const char* gIdleDaily = "idle-daily"; static const char* gIdleDaily = "idle-daily";
// annotation names
const char nsNavHistory::kAnnotationPreviousEncoding[] = "history/encoding";
// code borrowed from mozilla/xpfe/components/history/src/nsGlobalHistory.cpp // code borrowed from mozilla/xpfe/components/history/src/nsGlobalHistory.cpp
// pass in a pre-normalized now and a date, and we'll find // pass in a pre-normalized now and a date, and we'll find
// the difference since midnight on each of the days. // the difference since midnight on each of the days.
@ -2115,6 +2115,29 @@ nsNavHistory::LoadPrefs(PRBool aInitializing)
return NS_OK; return NS_OK;
} }
PRInt32
nsNavHistory::GetDaysOfHistory() {
PRInt32 daysOfHistory = 0;
nsCOMPtr<mozIStorageStatement> statement;
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT ROUND(( "
"strftime('%s','now','localtime','utc') - "
"( "
"SELECT visit_date FROM moz_historyvisits "
"UNION ALL "
"SELECT visit_date FROM moz_historyvisits_temp "
"ORDER BY visit_date ASC LIMIT 1 "
")/1000000 "
")/86400) AS daysOfHistory "),
getter_AddRefs(statement));
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Unable to create statement.");
NS_ENSURE_SUCCESS(rv, 0);
PRBool hasResult;
if (NS_SUCCEEDED(statement->ExecuteStep(&hasResult)) && hasResult)
statement->GetInt32(0, &daysOfHistory);
return daysOfHistory;
}
// nsNavHistory::GetNow // nsNavHistory::GetNow
// //
@ -3382,7 +3405,8 @@ PlacesSQLQueryBuilder::SelectAsDay()
nsNavHistory *history = nsNavHistory::GetHistoryService(); nsNavHistory *history = nsNavHistory::GetHistoryService();
NS_ENSURE_STATE(history); NS_ENSURE_STATE(history);
for (PRInt32 i = 0; i <= DATE_CONT_NUM(history->mExpireDaysMax); i++) { PRInt32 daysOfHistory = history->GetDaysOfHistory();
for (PRInt32 i = 0; i <= HISTORY_DATE_CONT_NUM(daysOfHistory); i++) {
nsCAutoString dateName; nsCAutoString dateName;
// Timeframes are calculated as BeginTime <= container < EndTime. // Timeframes are calculated as BeginTime <= container < EndTime.
// Notice times can't be relative to now, since to recognize a query we // Notice times can't be relative to now, since to recognize a query we
@ -3455,7 +3479,7 @@ PlacesSQLQueryBuilder::SelectAsDay()
"(strftime('%s','now','localtime','start of day','-7 days','utc')*1000000)"); "(strftime('%s','now','localtime','start of day','-7 days','utc')*1000000)");
break; break;
default: default:
if (i == ADDITIONAL_DATE_CONT_NUM + 6) { if (i == HISTORY_ADDITIONAL_DATE_CONT_NUM + 6) {
// Older than 6 months // Older than 6 months
history->GetAgeInDaysString(6, history->GetAgeInDaysString(6,
NS_LITERAL_STRING("finduri-AgeInMonths-isgreater").get(), dateName); NS_LITERAL_STRING("finduri-AgeInMonths-isgreater").get(), dateName);
@ -3470,7 +3494,7 @@ PlacesSQLQueryBuilder::SelectAsDay()
sqlFragmentSearchEndTime = sqlFragmentContainerEndTime; sqlFragmentSearchEndTime = sqlFragmentContainerEndTime;
break; break;
} }
PRInt32 MonthIndex = i - ADDITIONAL_DATE_CONT_NUM; PRInt32 MonthIndex = i - HISTORY_ADDITIONAL_DATE_CONT_NUM;
// Previous months' titles are month's name if inside this year, // Previous months' titles are month's name if inside this year,
// month's name and year for previous years. // month's name and year for previous years.
PRExplodedTime tm; PRExplodedTime tm;
@ -3540,8 +3564,8 @@ PlacesSQLQueryBuilder::SelectAsDay()
mQueryString.Append(dayRange); mQueryString.Append(dayRange);
if (i < DATE_CONT_NUM(history->mExpireDaysMax)) if (i < HISTORY_DATE_CONT_NUM(daysOfHistory))
mQueryString.Append(NS_LITERAL_CSTRING(" UNION ALL ")); mQueryString.Append(NS_LITERAL_CSTRING(" UNION ALL "));
} }
mQueryString.Append(NS_LITERAL_CSTRING(") ")); // TOUTER END mQueryString.Append(NS_LITERAL_CSTRING(") ")); // TOUTER END
@ -4122,7 +4146,7 @@ nsNavHistory::GetQueryResults(nsNavHistoryQueryResultNode *aResultNode,
nsCString queryString; nsCString queryString;
PRBool paramsPresent = PR_FALSE; PRBool paramsPresent = PR_FALSE;
nsNavHistory::StringHash addParams; nsNavHistory::StringHash addParams;
addParams.Init(DATE_CONT_NUM(mExpireDaysMax)); addParams.Init(HISTORY_DATE_CONT_MAX);
nsresult rv = ConstructQueryString(aQueries, aOptions, queryString, nsresult rv = ConstructQueryString(aQueries, aOptions, queryString,
paramsPresent, addParams); paramsPresent, addParams);
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);

Просмотреть файл

@ -272,12 +272,14 @@ public:
void SendPageChangedNotification(nsIURI* aURI, PRUint32 aWhat, void SendPageChangedNotification(nsIURI* aURI, PRUint32 aWhat,
const nsAString& aValue); const nsAString& aValue);
/**
* Returns current number of days stored in history.
*/
PRInt32 GetDaysOfHistory();
// current time optimization // current time optimization
PRTime GetNow(); PRTime GetNow();
// well-known annotations used by the history and bookmarks systems
static const char kAnnotationPreviousEncoding[];
// used by query result nodes to update: see comment on body of CanLiveUpdateQuery // used by query result nodes to update: see comment on body of CanLiveUpdateQuery
static PRUint32 GetUpdateRequirements(const nsCOMArray<nsNavHistoryQuery>& aQueries, static PRUint32 GetUpdateRequirements(const nsCOMArray<nsNavHistoryQuery>& aQueries,
nsNavHistoryQueryOptions* aOptions, nsNavHistoryQueryOptions* aOptions,