Skip to content

Commit

Permalink
Fix language filtering for feeds (#5026)
Browse files Browse the repository at this point in the history
* Fix language filtering for feeds

* Simplify logic
  • Loading branch information
gaearon authored Aug 29, 2024
1 parent e51eb39 commit 0a75969
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/lib/api/feed-manip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,27 +392,20 @@ export class FeedTuner {
slices: FeedViewPostsSlice[],
_dryRun: boolean,
): FeedViewPostsSlice[] => {
const candidateSlices = slices.slice()

// early return if no languages have been specified
if (!preferredLangsCode2.length || preferredLangsCode2.length === 0) {
return slices
}

for (let i = 0; i < slices.length; i++) {
let hasPreferredLang = false
for (const item of slices[i].items) {
const candidateSlices = slices.filter(slice => {
for (const item of slice.items) {
if (isPostInLanguage(item.post, preferredLangsCode2)) {
hasPreferredLang = true
break
return true
}
}

// if item does not fit preferred language, remove it
if (!hasPreferredLang) {
candidateSlices.splice(i, 1)
}
}
return false
})

// if the language filter cleared out the entire page, return the original set
// so that something always shows
Expand Down

0 comments on commit 0a75969

Please sign in to comment.