Bug 476299 - Decay frecency values to estimate recalculating frecencies. r=dietrich

Bug 482069 - Awesome bar adaptiveness totally sucks
This commit is contained in:
Edward Lee 2009-03-14 01:08:51 -05:00
parent 9c46baf11f
commit 9fed57c6b0
3 changed files with 78 additions and 12 deletions

View File

@ -84,11 +84,12 @@
#include "nsIClassInfoImpl.h"
#include "nsThreadUtils.h"
#include "mozIStorageService.h"
#include "mozIStorageConnection.h"
#include "mozIStorageValueArray.h"
#include "mozIStorageStatement.h"
#include "mozIStorageFunction.h"
#include "mozIStoragePendingStatement.h"
#include "mozIStorageService.h"
#include "mozIStorageStatement.h"
#include "mozIStorageValueArray.h"
#include "mozStorageCID.h"
#include "mozStorageHelper.h"
#include "nsPlacesTriggers.h"
@ -5431,6 +5432,49 @@ nsNavHistory::Observe(nsISupports *aSubject, const char *aTopic,
// Recalculate some frecency values (zero time means don't recalculate)
if (mFrecencyUpdateIdleTime)
(void)RecalculateFrecencies(mNumCalculateFrecencyOnIdle, PR_TRUE);
if (mDBConn) {
// Globally decay places frecency rankings to estimate reduced frecency
// values of pages that haven't been visited for a while, i.e., they do
// not get an updated frecency. We directly modify moz_places to avoid
// bringing the whole database into places_temp through places_view. A
// scaling factor of .975 results in .5 the original value after 28 days.
nsCOMPtr<mozIStorageStatement> decayFrecency;
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"UPDATE moz_places SET frecency = ROUND(frecency * .975) "
"WHERE frecency > 0"),
getter_AddRefs(decayFrecency));
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to create decayFrecency");
// Decay potentially unused adaptive entries (e.g. those that are at 1)
// to allow better chances for new entries that will start at 1
nsCOMPtr<mozIStorageStatement> decayAdaptive;
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"UPDATE moz_inputhistory SET use_count = use_count * .975"),
getter_AddRefs(decayAdaptive));
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to create decayAdaptive");
// Delete any adaptive entries that won't help in ordering anymore
nsCOMPtr<mozIStorageStatement> deleteAdaptive;
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"DELETE FROM moz_inputhistory WHERE use_count < .01"),
getter_AddRefs(deleteAdaptive));
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to create deleteAdaptive");
// Run these statements asynchronously if they were created successfully
if (decayFrecency && decayAdaptive && deleteAdaptive) {
nsCOMPtr<mozIStoragePendingStatement> ps;
mozIStorageStatement *stmts[] = {
decayFrecency,
decayAdaptive,
deleteAdaptive
};
rv = mDBConn->ExecuteAsync(stmts, NS_ARRAY_LENGTH(stmts), nsnull,
getter_AddRefs(ps));
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to exec async idle stmts");
}
}
}
else if (strcmp(aTopic, NS_PRIVATE_BROWSING_SWITCH_TOPIC) == 0) {
if (NS_LITERAL_STRING(NS_PRIVATE_BROWSING_ENTER).Equals(aData)) {

View File

@ -1022,7 +1022,7 @@ nsNavHistoryExpire::ExpireAnnotationsParanoid(mozIStorageConnection* aConnection
// nsNavHistoryExpire::ExpireInputHistoryParanoid
//
// Deletes dangling input history, decay potentially unused entries
// Deletes dangling input history
nsresult
nsNavHistoryExpire::ExpireInputHistoryParanoid(mozIStorageConnection* aConnection)
@ -1038,13 +1038,6 @@ nsNavHistoryExpire::ExpireInputHistoryParanoid(mozIStorageConnection* aConnectio
")"));
NS_ENSURE_SUCCESS(rv, rv);
// Decay potentially unused entries (e.g. those that are at 1) to allow
// better chances for new entries that will start at 1
rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"UPDATE moz_inputhistory "
"SET use_count = use_count * .9"));
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}

View File

@ -177,6 +177,15 @@ function setCountRank(aURI, aCount, aRank, aSearch)
}
}
/**
* Decay the adaptive entries by sending the daily idle topic
*/
function doAdaptiveDecay()
{
for (let i = 0; i < 10; i++)
obs.notifyObservers(null, "idle-daily", null);
}
let uri1 = uri("http://site.tld/1");
let uri2 = uri("http://site.tld/2");
@ -311,7 +320,27 @@ let tests = [
observer.runCount = c1 + c2;
setCountRank(uri1, c1, c2, s2);
setCountRank(uri2, c1, c1, s2);
}
},
function() {
prepTest("10 same count, same rank, same term, decay first; exact match");
observer.uriA = uri2;
observer.uriB = uri1;
observer.search = s1;
observer.runCount = c1 + c1;
setCountRank(uri1, c1, c1, s1);
doAdaptiveDecay();
setCountRank(uri2, c1, c1, s1);
},
function() {
prepTest("11 same count, same rank, same term, decay second; exact match");
observer.uriA = uri1;
observer.uriB = uri2;
observer.search = s1;
observer.runCount = c1 + c1;
setCountRank(uri2, c1, c1, s1);
doAdaptiveDecay();
setCountRank(uri1, c1, c1, s1);
},
];
/**