Closed
Bug 1235642
Opened 9 years ago
Closed 9 years ago
Don't query-then-update to bump history visit counts
Categories
(Firefox for Android Graveyard :: Data Providers, defect)
Tracking
(firefox44 fixed, firefox45 fixed, firefox46 fixed, b2g-v2.5 fixed)
RESOLVED
FIXED
Firefox 46
People
(Reporter: rnewman, Assigned: mfinkle, Mentored)
References
Details
(Keywords: perf)
Attachments
(1 file, 1 obsolete file)
5.15 KB,
patch
|
rnewman
:
review+
ritu
:
approval-mozilla-aurora+
ritu
:
approval-mozilla-beta+
|
Details | Diff | Splinter Review |
BrowserProvider.updateHistory uses a cursor to extract the VISIT count. It doesn't need to if we use raw SQL instead of the hamstrung Android sqlite API: just UPDATE SET visitCount = visitCount + 1 … This'll save a cursor and a query, which is 10-100msec.
Assignee | ||
Comment 1•9 years ago
|
||
This patch uses the DBUtils.updateArrays method to pass the VISITS in as an EXPRESSION. Seemed to work locally. Try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=052140617c6e
Assignee: nobody → mark.finkle
Attachment #8702998 -
Flags: review?(rnewman)
Assignee | ||
Comment 2•9 years ago
|
||
By "work locally" I mean that I see: Update SQL: UPDATE history SET date= ?,deleted= ?,modified= ?,url= ?,visits = visits+1 WHERE url = ? in logcat. I'll remove that debugging before any landing.
Reporter | ||
Comment 3•9 years ago
|
||
Comment on attachment 8702998 [details] [diff] [review] nocursor-inc-visits v0.1 Review of attachment 8702998 [details] [diff] [review]: ----------------------------------------------------------------- r+ with logging removed. Lovely! ::: mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java @@ +17,5 @@ > import org.mozilla.gecko.db.BrowserContract.History; > import org.mozilla.gecko.db.BrowserContract.Schema; > import org.mozilla.gecko.db.BrowserContract.Tabs; > import org.mozilla.gecko.db.BrowserContract.Thumbnails; > +import org.mozilla.gecko.db.DBUtils.UpdateOperation; I'm increasingly glad that I added this!
Attachment #8702998 -
Flags: review?(rnewman) → review+
Reporter | ||
Updated•9 years ago
|
Status: NEW → ASSIGNED
Whiteboard: [good first bug][lang=java]
Assignee | ||
Comment 4•9 years ago
|
||
Tests failed because I am | values.removeKey(History.VISITS); | and that breaks insertOrUpdateHistory which will also attempt to use the | values | if the updateHistory call does not update anything. I updated the patch to make a copy of the ContentValues when we know we are in the "increment visits" code path. This passes testBrowserProvider locally. diff --git a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java --- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java +++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java @@ -1021,34 +1021,37 @@ public class BrowserProvider extends Sha // Use the simple code path for easy updates. if (!shouldIncrementVisits(uri)) { trace("Updating history meta data only"); return db.update(TABLE_HISTORY, values, selection, selectionArgs); } trace("Updating history meta data and incrementing visits"); + // We might be altering the ContentValues, so let's use a copy. + final ContentValues valuesForUpdate = new ContentValues(values); + // Update data and increment visits by 1. long incVisits = 1; - if (values.containsKey(History.VISITS)) { + if (valuesForUpdate.containsKey(History.VISITS)) { // Use a given visit count, if found. - Long additional = values.getAsLong(History.VISITS); + Long additional = valuesForUpdate.getAsLong(History.VISITS); if (additional != null) { incVisits = additional; } // Remove the visits from this set of values so we can pass the visits // as an expression. - values.remove(History.VISITS); + valuesForUpdate.remove(History.VISITS); } // Create a separate set of values that will be updated as an expression. final ContentValues visits = new ContentValues(); - visits.put(History.VISITS, History.VISITS + "+" + incVisits); + visits.put(History.VISITS, History.VISITS + " + " + incVisits); - final ContentValues[] valuesAndVisits = { values, visits }; + final ContentValues[] valuesAndVisits = { valuesForUpdate, visits }; final UpdateOperation[] ops = { UpdateOperation.ASSIGN, UpdateOperation.EXPRESSION }; return DBUtils.updateArrays(db, TABLE_HISTORY, valuesAndVisits, ops, selection, selectionArgs); }
Assignee | ||
Comment 5•9 years ago
|
||
Copying the ContentValues seems like a safe and cheap thing to do. Alternate: I could cache the VISITS value and put it back if the update fails.
Attachment #8702998 -
Attachment is obsolete: true
Attachment #8703065 -
Flags: review?(rnewman)
Assignee | ||
Comment 6•9 years ago
|
||
Full Try run: https://treeherder.mozilla.org/#/jobs?repo=try&revision=8145d0bbb26f
Reporter | ||
Comment 7•9 years ago
|
||
Comment on attachment 8703065 [details] [diff] [review] nocursor-inc-visits v0.2 (In reply to Mark Finkle (:mfinkle) from comment #4) > Tests failed because I am | values.removeKey(History.VISITS); | and that > breaks insertOrUpdateHistory which will also attempt to use the | values | > if the updateHistory call does not update anything. Heh, I was going to call that out, but I figured we were already mutating the provided CV, so it was likely fine. > I updated the patch to make a copy of the ContentValues when we know we are > in the "increment visits" code path. This passes testBrowserProvider locally. SGTM. Interdiff looks fine. Don't forget to remove the Log.i.
Attachment #8703065 -
Flags: review?(rnewman) → review+
Comment 9•9 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/9126f599f632
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 46
Assignee | ||
Comment 10•8 years ago
|
||
Comment on attachment 8703065 [details] [diff] [review] nocursor-inc-visits v0.2 Approval Request Comment [Feature/regressing bug #]: [User impact if declined]: Might reduce cursor crashes. Should improve performance [Describe test coverage new/current, TreeHerder]: Working on Nightly for a few days [Risks and why]: Low risk. Very localized change. [String/UUID change made/needed]: None Should be taken with bug 1235637
Attachment #8703065 -
Flags: approval-mozilla-beta?
Attachment #8703065 -
Flags: approval-mozilla-aurora?
Comment on attachment 8703065 [details] [diff] [review] nocursor-inc-visits v0.2 Let's hope this improves Fennec performance, beta44+, aurora45+
Attachment #8703065 -
Flags: approval-mozilla-beta?
Attachment #8703065 -
Flags: approval-mozilla-beta+
Attachment #8703065 -
Flags: approval-mozilla-aurora?
Attachment #8703065 -
Flags: approval-mozilla-aurora+
status-firefox44:
--- → affected
status-firefox45:
--- → affected
This doesn't apply cleanly to beta due to the lack of bug 1107811. Can we get a rebased patch?
Flags: needinfo?(mark.finkle)
Comment 13•8 years ago
|
||
bugherder uplift |
https://hg.mozilla.org/releases/mozilla-aurora/rev/8f4bd2002ea6
Assignee | ||
Comment 14•8 years ago
|
||
https://hg.mozilla.org/releases/mozilla-beta/rev/afffbf932c7d
Flags: needinfo?(mark.finkle)
Comment 15•8 years ago
|
||
bugherder uplift |
https://hg.mozilla.org/releases/mozilla-b2g44_v2_5/rev/afffbf932c7d
status-b2g-v2.5:
--- → fixed
Updated•3 years ago
|
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•