-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add fixed status to suggestions #634
base: main
Are you sure you want to change the base?
Changes from 4 commits
5fe9099
a34e964
9a90ab4
70a8bf9
2f2dc6f
4c51ef2
dbafed8
c6e3110
8e6b9b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,10 +22,11 @@ import URI from 'urijs'; | |||||||||||||||||||||||||||||||||||||
import { JSDOM } from 'jsdom'; | ||||||||||||||||||||||||||||||||||||||
import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager'; | ||||||||||||||||||||||||||||||||||||||
import { ListObjectsV2Command } from '@aws-sdk/client-s3'; | ||||||||||||||||||||||||||||||||||||||
import { AbortController, AbortError } from '@adobe/fetch'; | ||||||||||||||||||||||||||||||||||||||
import { getObjectFromKey } from '../utils/s3-utils.js'; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
URI.preventInvalidHostname = true; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
export const TIMEOUT = 3000; | ||||||||||||||||||||||||||||||||||||||
// weekly pageview threshold to eliminate urls with lack of samples | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
export async function getRUMUrl(url) { | ||||||||||||||||||||||||||||||||||||||
|
@@ -298,6 +299,36 @@ export const getScrapedDataForSiteId = async (site, context) => { | |||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
export const fetchWithTimeout = async (url, timeout, log = console) => { | ||||||||||||||||||||||||||||||||||||||
const controller = new AbortController(); | ||||||||||||||||||||||||||||||||||||||
const { signal } = controller; | ||||||||||||||||||||||||||||||||||||||
const id = setTimeout(() => controller.abort(), timeout); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||
const response = await fetch(url, { signal }); | ||||||||||||||||||||||||||||||||||||||
clearTimeout(id); | ||||||||||||||||||||||||||||||||||||||
return response; | ||||||||||||||||||||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||||||||||||||||||||
if (error instanceof AbortError) { | ||||||||||||||||||||||||||||||||||||||
log.warn(`Request to ${url} timed out after ${timeout}ms`); | ||||||||||||||||||||||||||||||||||||||
return { ok: false, status: 408 }; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
} finally { | ||||||||||||||||||||||||||||||||||||||
clearTimeout(id); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
export const isFixedURL = async (backlink) => { | ||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||
const response = await fetchWithTimeout(backlink.url_to, TIMEOUT); | ||||||||||||||||||||||||||||||||||||||
return response.ok; | ||||||||||||||||||||||||||||||||||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||||||||||||||||||||||||||||||||||||||
} catch (e) { | ||||||||||||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might not work for other audits than backlinks right now. Also we could introduce an
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
export async function sleep(ms) { | ||||||||||||||||||||||||||||||||||||||
return new Promise((resolve) => { | ||||||||||||||||||||||||||||||||||||||
setTimeout(resolve, ms); | ||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
* governing permissions and limitations under the License. | ||
*/ | ||
import { isObject } from '@adobe/spacecat-shared-utils'; | ||
import { Suggestion } from '@adobe/spacecat-shared-data-access'; | ||
|
||
/** | ||
* Fetches site data based on the given base URL. If no site is found for the given | ||
|
@@ -53,16 +54,23 @@ export async function syncSuggestions({ | |
opportunity, | ||
newData, | ||
buildKey, | ||
isFixed, | ||
mapNewSuggestion, | ||
log, | ||
}) { | ||
const newDataKeys = new Set(newData.map(buildKey)); | ||
const existingSuggestions = await opportunity.getSuggestions(); | ||
// Remove outdated suggestions | ||
await Promise.all( | ||
existingSuggestions | ||
.filter((existing) => !newDataKeys.has(buildKey(existing.getData()))) | ||
.map((suggestion) => suggestion.remove()), | ||
.map(async (suggestion) => { | ||
const isSuggestionFixed = await isFixed(suggestion); | ||
if (isSuggestionFixed) { | ||
suggestion.setStatus(Suggestion.STATUSES.FiXED); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be better to use |
||
return suggestion.save(); | ||
} | ||
return suggestion.remove(); | ||
}), | ||
); | ||
|
||
// Update existing suggestions | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of returning
null
we could return{ ok: false }
to avoid exceptions