BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
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
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
9325a51c
Commit
9325a51c
authored
Aug 11, 2017
by
Jose Ivan Vargas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Merge branch 'broadcast-messages-cache' into 'master'"
This reverts commit
c19ea197
, reversing changes made to
0887a2bd
.
parent
e93779ae
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
8 additions
and
80 deletions
+8
-80
broadcast_message.rb
app/models/broadcast_message.rb
+2
-12
broadcast-messages-cache.yml
changelogs/unreleased/broadcast-messages-cache.yml
+0
-4
20170809133343_add_broadcast_messages_index.rb
db/migrate/20170809133343_add_broadcast_messages_index.rb
+0
-21
20170809134534_add_broadcast_message_not_null_constraints.rb
...70809134534_add_broadcast_message_not_null_constraints.rb
+0
-17
schema.rb
db/schema.rb
+5
-7
broadcast_message_spec.rb
spec/models/broadcast_message_spec.rb
+1
-19
No files found.
app/models/broadcast_message.rb
View file @
9325a51c
...
...
@@ -14,15 +14,9 @@ class BroadcastMessage < ActiveRecord::Base
default_value_for
:color
,
'#E75E40'
default_value_for
:font
,
'#FFFFFF'
CACHE_KEY
=
'broadcast_message_current'
.
freeze
after_commit
:flush_redis_cache
def
self
.
current
Rails
.
cache
.
fetch
(
CACHE_KEY
)
do
where
(
'ends_at > :now AND starts_at <= :now'
,
now:
Time
.
zone
.
now
)
.
reorder
(
id: :asc
)
.
to_a
Rails
.
cache
.
fetch
(
"broadcast_message_current"
,
expires_in:
1
.
minute
)
do
where
(
'ends_at > :now AND starts_at <= :now'
,
now:
Time
.
zone
.
now
).
order
([
:created_at
,
:id
]).
to_a
end
end
...
...
@@ -37,8 +31,4 @@ class BroadcastMessage < ActiveRecord::Base
def
ended?
ends_at
<
Time
.
zone
.
now
end
def
flush_redis_cache
Rails
.
cache
.
delete
(
CACHE_KEY
)
end
end
changelogs/unreleased/broadcast-messages-cache.yml
deleted
100644 → 0
View file @
e93779ae
---
title
:
Better caching and indexing of broadcast messages
merge_request
:
author
:
db/migrate/20170809133343_add_broadcast_messages_index.rb
deleted
100644 → 0
View file @
e93779ae
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
AddBroadcastMessagesIndex
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
disable_ddl_transaction!
COLUMNS
=
%i[starts_at ends_at id]
.
freeze
def
up
add_concurrent_index
:broadcast_messages
,
COLUMNS
end
def
down
remove_concurrent_index
:broadcast_messages
,
COLUMNS
end
end
db/migrate/20170809134534_add_broadcast_message_not_null_constraints.rb
deleted
100644 → 0
View file @
e93779ae
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
AddBroadcastMessageNotNullConstraints
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
COLUMNS
=
%i[starts_at ends_at created_at updated_at message_html]
def
change
COLUMNS
.
each
do
|
column
|
change_column_null
:broadcast_messages
,
column
,
false
end
end
end
db/schema.rb
View file @
9325a51c
...
...
@@ -163,18 +163,16 @@ ActiveRecord::Schema.define(version: 20170807160457) do
create_table
"broadcast_messages"
,
force: :cascade
do
|
t
|
t
.
text
"message"
,
null:
false
t
.
datetime
"starts_at"
,
null:
false
t
.
datetime
"ends_at"
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"starts_at"
t
.
datetime
"ends_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
string
"color"
t
.
string
"font"
t
.
text
"message_html"
,
null:
false
t
.
text
"message_html"
t
.
integer
"cached_markdown_version"
end
add_index
"broadcast_messages"
,
[
"starts_at"
,
"ends_at"
,
"id"
],
name:
"index_broadcast_messages_on_starts_at_and_ends_at_and_id"
,
using: :btree
create_table
"chat_names"
,
force: :cascade
do
|
t
|
t
.
integer
"user_id"
,
null:
false
t
.
integer
"service_id"
,
null:
false
...
...
spec/models/broadcast_message_spec.rb
View file @
9325a51c
...
...
@@ -20,7 +20,7 @@ describe BroadcastMessage do
it
{
is_expected
.
not_to
allow_value
(
'000'
).
for
(
:font
)
}
end
describe
'.current'
,
:use_clean_rails_memory_store_caching
do
describe
'.current'
do
it
'returns message if time match'
do
message
=
create
(
:broadcast_message
)
...
...
@@ -45,14 +45,6 @@ describe BroadcastMessage do
expect
(
described_class
.
current
).
to
be_empty
end
it
'caches the output of the query'
do
create
(
:broadcast_message
)
expect
(
described_class
).
to
receive
(
:where
).
and_call_original
.
once
2
.
times
{
described_class
.
current
}
end
end
describe
'#active?'
do
...
...
@@ -110,14 +102,4 @@ describe BroadcastMessage do
end
end
end
describe
'#flush_redis_cache'
do
it
'flushes the Redis cache'
do
message
=
create
(
:broadcast_message
)
expect
(
Rails
.
cache
).
to
receive
(
:delete
).
with
(
described_class
::
CACHE_KEY
)
message
.
flush_redis_cache
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