mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1752818 - SnapshotGroups should return the last accessed date. r=mossop
Depends on D136527 Differential Revision: https://phabricator.services.mozilla.com/D137451
This commit is contained in:
parent
c50783cfa7
commit
3866a4ff0f
@ -215,10 +215,10 @@ const SnapshotGroups = new (class SnapshotGroups {
|
||||
|
||||
let rows = await db.executeCached(
|
||||
`
|
||||
SELECT g.id, g.title, g.builder, g.builder_data, COUNT(h.url) AS snapshot_count, MAX(h.last_visit_date) AS last_access
|
||||
SELECT g.id, g.title, g.builder, g.builder_data, COUNT(s.group_id) AS snapshot_count, MAX(sn.last_interaction_at) AS last_access
|
||||
FROM moz_places_metadata_snapshots_groups g
|
||||
LEFT JOIN moz_places_metadata_groups_to_snapshots s ON s.group_id = g.id
|
||||
LEFT JOIN moz_places h ON h.id = s.place_id
|
||||
LEFT JOIN moz_places_metadata_snapshots sn ON sn.place_id = s.place_id
|
||||
WHERE builder = :builder OR :builder = ""
|
||||
GROUP BY g.id ${sizeFragment}
|
||||
ORDER BY last_access DESC
|
||||
@ -320,6 +320,7 @@ const SnapshotGroups = new (class SnapshotGroups {
|
||||
builder: row.getResultByName("builder"),
|
||||
builderMetadata: JSON.parse(row.getResultByName("builder_data")),
|
||||
snapshotCount: row.getResultByName("snapshot_count"),
|
||||
lastAccessed: row.getResultByName("last_access"),
|
||||
};
|
||||
|
||||
return snapshotGroup;
|
||||
|
@ -321,6 +321,13 @@ function assertSnapshotGroup(group, expected) {
|
||||
"Should have the expected snapshotCount"
|
||||
);
|
||||
}
|
||||
if (expected.lastAccessed != null) {
|
||||
Assert.equal(
|
||||
group.lastAccessed,
|
||||
expected.lastAccessed,
|
||||
"Should have the expected lastAccessed value"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,14 +17,22 @@ async function delete_all_groups() {
|
||||
}
|
||||
}
|
||||
|
||||
async function addInteractionsAndSnapshots(urls) {
|
||||
for (let url of urls) {
|
||||
await addInteractions([
|
||||
{
|
||||
url,
|
||||
},
|
||||
]);
|
||||
await Snapshots.add({ url });
|
||||
/**
|
||||
* Adds interactions and snapshots for the supplied data.
|
||||
*
|
||||
* @param {string[]|InteractionInfo[]} data
|
||||
* Either an array of urls, or an array of InteractionInfo objects suitable
|
||||
* for passing to `addInteractions`.
|
||||
*/
|
||||
async function addInteractionsAndSnapshots(data) {
|
||||
for (let item of data) {
|
||||
if (typeof item == "string") {
|
||||
await addInteractions([{ url: item }]);
|
||||
await Snapshots.add({ url: item });
|
||||
} else {
|
||||
await addInteractions([item]);
|
||||
await Snapshots.add({ url: item.url });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,19 +60,28 @@ add_task(async function test_add_and_query_no_snapshots() {
|
||||
|
||||
add_task(async function test_add_and_query() {
|
||||
await delete_all_groups();
|
||||
let urls = [TEST_URL1, TEST_URL2, TEST_URL3];
|
||||
await addInteractionsAndSnapshots(urls);
|
||||
|
||||
let now = Date.now();
|
||||
let data = [
|
||||
{ url: TEST_URL1, created_at: now - 30000, updated_at: now - 30000 },
|
||||
{ url: TEST_URL2, created_at: now - 20000, updated_at: now - 20000 },
|
||||
{ url: TEST_URL3, created_at: now - 10000, updated_at: now - 10000 },
|
||||
];
|
||||
await addInteractionsAndSnapshots(data);
|
||||
|
||||
let newGroup = { title: "Test Group", builder: "domain" };
|
||||
|
||||
await SnapshotGroups.add(newGroup, urls);
|
||||
await SnapshotGroups.add(
|
||||
newGroup,
|
||||
data.map(d => d.url)
|
||||
);
|
||||
|
||||
let groups = await SnapshotGroups.query({ skipMinimum: true });
|
||||
Assert.equal(groups.length, 1, "Should return 1 SnapshotGroup");
|
||||
assertSnapshotGroup(groups[0], {
|
||||
title: "Test Group",
|
||||
builder: "domain",
|
||||
snapshotCount: urls.length,
|
||||
snapshotCount: data.length,
|
||||
lastAccessed: now - 10000,
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user