Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
VeNJob
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tô Ngọc Ánh
VeNJob
Commits
eb291848
Commit
eb291848
authored
Aug 24, 2020
by
Tô Ngọc Ánh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rake task delete history if size > limit
parent
37cb0f75
Pipeline
#1006
failed with stages
in 0 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
4 deletions
+7
-4
lib/tasks/delete_record.rake
+7
-4
No files found.
lib/tasks/delete_record.rake
View file @
eb291848
namespace
:delete_record
do
namespace
:delete_record
do
desc
'Delete history when total greater than default limit'
desc
'Delete history when total greater than default limit'
task
history: :environment
do
task
histories: :environment
do
users
=
User
.
includes
(
:histories
).
all
users
=
User
.
joins
(
:histories
)
.
group
(
:user_id
)
.
select
(
'users.id'
)
.
having
(
"count(histories.id) >
#{
History
::
NUMBER_STORED_HISTORIES
}
"
)
users
.
each
do
|
user
|
users
.
each
do
|
user
|
break
if
user
.
histories
.
size
<=
History
::
NUMBER_STORED_HISTORIES
break
if
user
.
histories
.
size
<=
History
::
NUMBER_STORED_HISTORIES
laste
d
=
user
.
histories
.
last
(
History
::
NUMBER_STORED_HISTORIES
).
pluck
(
:id
)
laste
st
=
user
.
histories
.
order
(
updated_at: :desc
).
take
(
History
::
NUMBER_STORED_HISTORIES
).
pluck
(
:id
)
user
.
histories
.
where
.
not
(
id:
laste
d
).
delete_all
user
.
histories
.
where
.
not
(
id:
laste
st
).
delete_all
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment