de-lodashify

This commit is contained in:
Henry Jameson 2026-08-04 16:36:27 +03:00
commit 2db420ac54
7 changed files with 44 additions and 56 deletions

View file

@ -1,4 +1,4 @@
import { cloneDeep, differenceWith, flatten, get, isEqual, set } from 'lodash'
import { cloneDeep, differenceWith, get, isEqual, set } from 'lodash'
import { defineStore } from 'pinia'
import { useOAuthStore } from 'src/stores/oauth.js'
@ -209,11 +209,11 @@ export const useAdminSettingsStore = defineStore('adminSettings', {
}
// Getting all group-keys used in config
const allGroupKeys = flatten(
Object.entries(this.config).map(([group, lv1data]) =>
const allGroupKeys = Object.entries(this.config)
.map(([group, lv1data]) =>
Object.keys(lv1data).map((key) => ({ group, key })),
),
)
)
.flat()
// Only using group-keys where there are changes detected
const changedGroupKeys = allGroupKeys.filter(({ group, key }) => {

View file

@ -4,13 +4,12 @@ import {
clamp,
cloneDeep,
findLastIndex,
flatten,
get,
groupBy,
isEqual,
set,
take,
takeRight,
last,
uniqWith,
unset,
} from 'lodash'
@ -222,15 +221,16 @@ export const _mergeFlags = (recent, stale, allFlagKeys) => {
export const _mergeJournal = (...journals) => {
// Ignore invalid journal entries
const allJournals = flatten(
journals.map((j) => (Array.isArray(j) ? j : [])),
).filter(
(entry) =>
Object.hasOwn(entry, 'path') &&
Object.hasOwn(entry, 'operation') &&
Object.hasOwn(entry, 'args') &&
Object.hasOwn(entry, 'timestamp'),
)
const allJournals = journals
.map((j) => (Array.isArray(j) ? j : []))
.flat()
.filter(
(entry) =>
Object.hasOwn(entry, 'path') &&
Object.hasOwn(entry, 'operation') &&
Object.hasOwn(entry, 'args') &&
Object.hasOwn(entry, 'timestamp'),
)
const grouped = groupBy(allJournals, 'path')
const trimmedGrouped = Object.entries(grouped).map(([path, rawJournal]) => {
const journal = rawJournal
@ -271,13 +271,14 @@ export const _mergeJournal = (...journals) => {
})
} else if (path.startsWith('simple')) {
// Only the last record is important
return takeRight(journal)
return [last(journal)]
} else {
return journal
}
})
const flat = flatten(trimmedGrouped)
const flat = trimmedGrouped
.flat()
.map((data, index) => ({ data, index }))
.toSorted(({ data: a, index: ai }, { data: b, index: bi }) => {
if (a.timestamp === b.timestamp) {

View file

@ -2,10 +2,9 @@ import {
merge as _merge,
clone,
cloneDeep,
flatten,
groupBy,
isEqual,
takeRight,
last,
} from 'lodash'
import { defineStore } from 'pinia'
import { toRaw } from 'vue'
@ -117,25 +116,26 @@ export const _getRecentData = (cache, live, isTest) => {
const _mergeJournal = (...journals) => {
// Ignore invalid journal entries
const allJournals = flatten(
journals.map((j) => (Array.isArray(j) ? j : [])),
).filter(
(entry) =>
Object.hasOwn(entry, 'user') &&
Object.hasOwn(entry, 'operation') &&
Object.hasOwn(entry, 'args') &&
Object.hasOwn(entry, 'timestamp'),
)
const allJournals = journals
.map((j) => (Array.isArray(j) ? j : []))
.flat()
.filter(
(entry) =>
Object.hasOwn(entry, 'user') &&
Object.hasOwn(entry, 'operation') &&
Object.hasOwn(entry, 'args') &&
Object.hasOwn(entry, 'timestamp'),
)
const grouped = groupBy(allJournals, 'user')
const trimmedGrouped = Object.entries(grouped).map(([user, journal]) => {
// side effect
journal.sort((a, b) => (a.timestamp > b.timestamp ? 1 : -1))
return takeRight(journal)
return [last(journal)]
})
return flatten(trimmedGrouped).sort((a, b) =>
a.timestamp > b.timestamp ? 1 : -1,
)
return trimmedGrouped
.flat()
.sort((a, b) => (a.timestamp > b.timestamp ? 1 : -1))
}
export const _mergeHighlights = (recent, stale) => {