mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-19 22:16:49 +00:00
Merge pull request #1274 from nextcloud/enh/1272/session-deduplication
rework session deduplication
This commit is contained in:
commit
41507c05fa
7 changed files with 40 additions and 29 deletions
|
|
@ -1,26 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
while true; do
|
||||
while [ "$(find "/mnt/docker-aio-config/session/" -mindepth 1 -exec grep "aio_authenticated|[a-z]:1" {} \; | wc -l)" -gt 1 ]; do
|
||||
# First delete all session files that are not authenticated
|
||||
unset SESSION_FILES
|
||||
SESSION_FILES="$(find "/mnt/docker-aio-config/session/" -mindepth 1)"
|
||||
unset SESSION_FILES_ARRAY
|
||||
mapfile -t SESSION_FILES_ARRAY <<< "$SESSION_FILES"
|
||||
for SESSION_FILE in "${SESSION_FILES_ARRAY[@]}"; do
|
||||
if [ -f "$SESSION_FILE" ] && ! grep -q "aio_authenticated|[a-z]:1" "$SESSION_FILE"; then
|
||||
rm "$SESSION_FILE"
|
||||
fi
|
||||
done
|
||||
deduplicate_sessions() {
|
||||
echo "Deleting duplicate sessions"
|
||||
find "/mnt/docker-aio-config/session/" -mindepth 1 -exec grep -qv "$NEW_SESSION_TIME" {} \; -delete
|
||||
}
|
||||
|
||||
# Second clean up all sessions that are authenticated
|
||||
echo "Deleting duplicate sessions"
|
||||
unset OLDEST_FILE
|
||||
set -x
|
||||
# shellcheck disable=SC2012
|
||||
OLDEST_FILE="$(ls -t "/mnt/docker-aio-config/session/" | tail -1)"
|
||||
rm "/mnt/docker-aio-config/session/$OLDEST_FILE"
|
||||
set +x
|
||||
done
|
||||
sleep 5
|
||||
compare_times() {
|
||||
if [ -f "/mnt/docker-aio-config/data/session_date_file" ]; then
|
||||
unset NEW_SESSION_TIME
|
||||
NEW_SESSION_TIME="$(cat "/mnt/docker-aio-config/data/session_date_file")"
|
||||
if [ -n "$NEW_SESSION_TIME" ] && [ -n "$OLD_SESSION_TIME" ] && [ "$NEW_SESSION_TIME" != "$OLD_SESSION_TIME" ]; then
|
||||
deduplicate_sessions
|
||||
fi
|
||||
OLD_SESSION_TIME="$NEW_SESSION_TIME"
|
||||
fi
|
||||
}
|
||||
|
||||
while true; do
|
||||
compare_times
|
||||
sleep 2
|
||||
done
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue