Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Register
Sign in
Toggle navigation
Menu
Open sidebar
Tiger Ton
mastodon
Commits
6d4438a6
Commit
6d4438a6
authored
6 years ago
by
Eugen Rochko
Browse files
Options
Download
Email Patches
Plain Diff
Remove intermediary arrays when creating hash maps from results (#9291)
parent
01a8ab92
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
app/controllers/application_controller.rb
+1
-1
app/controllers/application_controller.rb
app/lib/entity_cache.rb
+1
-1
app/lib/entity_cache.rb
app/lib/formatter.rb
+2
-2
app/lib/formatter.rb
app/lib/settings/scoped_settings.rb
+2
-2
app/lib/settings/scoped_settings.rb
app/models/concerns/account_interactions.rb
+2
-2
app/models/concerns/account_interactions.rb
app/models/notification.rb
+1
-1
app/models/notification.rb
app/models/setting.rb
+1
-1
app/models/setting.rb
app/models/status.rb
+5
-5
app/models/status.rb
app/models/trending_tags.rb
+1
-1
app/models/trending_tags.rb
app/services/batched_remove_status_service.rb
+3
-3
app/services/batched_remove_status_service.rb
spec/models/notification_spec.rb
+1
-1
spec/models/notification_spec.rb
with
20 additions
and
20 deletions
+20
-20
app/controllers/application_controller.rb
+
1
-
1
View file @
6d4438a6
...
...
@@ -113,7 +113,7 @@ class ApplicationController < ActionController::Base
klass
.
reload_stale_associations!
(
cached_keys_with_value
.
values
)
if
klass
.
respond_to?
(
:reload_stale_associations!
)
unless
uncached_ids
.
empty?
uncached
=
klass
.
where
(
id:
uncached_ids
).
with_includes
.
map
{
|
item
|
[
item
.
id
,
item
]
}
.
to_h
uncached
=
klass
.
where
(
id:
uncached_ids
).
with_includes
.
each_with_object
({})
{
|
item
,
h
|
h
[
item
.
id
]
=
item
}
uncached
.
each_value
do
|
item
|
Rails
.
cache
.
write
(
item
,
item
)
...
...
This diff is collapsed.
Click to expand it.
app/lib/entity_cache.rb
+
1
-
1
View file @
6d4438a6
...
...
@@ -21,7 +21,7 @@ class EntityCache
end
unless
uncached_ids
.
empty?
uncached
=
CustomEmoji
.
where
(
shortcode:
shortcodes
,
domain:
domain
,
disabled:
false
).
map
{
|
item
|
[
item
.
shortcode
,
item
]
}
.
to_h
uncached
=
CustomEmoji
.
where
(
shortcode:
shortcodes
,
domain:
domain
,
disabled:
false
).
each_with_object
({})
{
|
item
,
h
|
h
[
item
.
shortcode
]
=
item
}
uncached
.
each_value
{
|
item
|
Rails
.
cache
.
write
(
to_key
(
:emoji
,
item
.
shortcode
,
domain
),
item
,
expires_in:
MAX_EXPIRATION
)
}
end
...
...
This diff is collapsed.
Click to expand it.
app/lib/formatter.rb
+
2
-
2
View file @
6d4438a6
...
...
@@ -128,9 +128,9 @@ class Formatter
return
html
if
emojis
.
empty?
emoji_map
=
if
animate
emojis
.
map
{
|
e
|
[
e
.
shortcode
,
full_asset_url
(
e
.
image
.
url
)
]
}
.
to_h
emojis
.
each_with_object
({})
{
|
e
,
h
|
h
[
e
.
shortcode
]
=
full_asset_url
(
e
.
image
.
url
)
}
else
emojis
.
map
{
|
e
|
[
e
.
shortcode
,
full_asset_url
(
e
.
image
.
url
(
:static
))
]
}
.
to_h
emojis
.
each_with_object
({})
{
|
e
,
h
|
h
[
e
.
shortcode
]
=
full_asset_url
(
e
.
image
.
url
(
:static
))
}
end
i
=
-
1
...
...
This diff is collapsed.
Click to expand it.
app/lib/settings/scoped_settings.rb
+
2
-
2
View file @
6d4438a6
...
...
@@ -31,7 +31,7 @@ module Settings
def
all_as_records
vars
=
thing_scoped
records
=
vars
.
map
{
|
r
|
[
r
.
var
,
r
]
}
.
to_h
records
=
vars
.
each_with_object
({})
{
|
r
,
h
|
h
[
r
.
var
]
=
r
}
Setting
.
default_settings
.
each
do
|
key
,
default_value
|
next
if
records
.
key?
(
key
)
||
default_value
.
is_a?
(
Hash
)
...
...
@@ -65,7 +65,7 @@ module Settings
class
<<
self
def
default_settings
defaulting
=
DEFAULTING_TO_UNSCOPED
.
map
{
|
k
|
[
k
,
Setting
[
k
]
]
}
.
to_h
defaulting
=
DEFAULTING_TO_UNSCOPED
.
each_with_object
({})
{
|
k
,
h
|
h
[
k
]
=
Setting
[
k
]
}
Setting
.
default_settings
.
merge!
(
defaulting
)
end
end
...
...
This diff is collapsed.
Click to expand it.
app/models/concerns/account_interactions.rb
+
2
-
2
View file @
6d4438a6
...
...
@@ -45,9 +45,9 @@ module AccountInteractions
end
def
domain_blocking_map
(
target_account_ids
,
account_id
)
accounts_map
=
Account
.
where
(
id:
target_account_ids
).
select
(
'id, domain'
).
map
{
|
a
|
[
a
.
id
,
a
.
domain
]
}
.
to_h
accounts_map
=
Account
.
where
(
id:
target_account_ids
).
select
(
'id, domain'
).
each_with_object
({})
{
|
a
,
h
|
h
[
a
.
id
]
=
a
.
domain
}
blocked_domains
=
domain_blocking_map_by_domain
(
accounts_map
.
values
.
compact
,
account_id
)
accounts_map
.
map
{
|
id
,
domain
|
[
id
,
blocked_domains
[
domain
]
]
}
.
to_h
accounts_map
.
reduce
({})
{
|
h
,
(
id
,
domain
)
|
h
.
merge
(
id
=>
blocked_domains
[
domain
]
)
}
end
def
domain_blocking_map_by_domain
(
target_domains
,
account_id
)
...
...
This diff is collapsed.
Click to expand it.
app/models/notification.rb
+
1
-
1
View file @
6d4438a6
...
...
@@ -75,7 +75,7 @@ class Notification < ApplicationRecord
return
if
account_ids
.
empty?
accounts
=
Account
.
where
(
id:
account_ids
).
map
{
|
a
|
[
a
.
id
,
a
]
}
.
to_h
accounts
=
Account
.
where
(
id:
account_ids
).
each_with_object
({})
{
|
a
,
h
|
h
[
a
.
id
]
=
a
}
cached_items
.
each
do
|
item
|
item
.
from_account
=
accounts
[
item
.
from_account_id
]
...
...
This diff is collapsed.
Click to expand it.
app/models/setting.rb
+
1
-
1
View file @
6d4438a6
...
...
@@ -40,7 +40,7 @@ class Setting < RailsSettings::Base
def
all_as_records
vars
=
thing_scoped
records
=
vars
.
map
{
|
r
|
[
r
.
var
,
r
]
}
.
to_h
records
=
vars
.
each_with_object
({})
{
|
r
,
h
|
h
[
r
.
var
]
=
r
}
default_settings
.
each
do
|
key
,
default_value
|
next
if
records
.
key?
(
key
)
||
default_value
.
is_a?
(
Hash
)
...
...
This diff is collapsed.
Click to expand it.
app/models/status.rb
+
5
-
5
View file @
6d4438a6
...
...
@@ -310,19 +310,19 @@ class Status < ApplicationRecord
end
def
favourites_map
(
status_ids
,
account_id
)
Favourite
.
select
(
'status_id'
).
where
(
status_id:
status_ids
).
where
(
account_id:
account_id
).
map
{
|
f
|
[
f
.
status_id
,
true
]
}
.
to_h
Favourite
.
select
(
'status_id'
).
where
(
status_id:
status_ids
).
where
(
account_id:
account_id
).
each_with_object
({})
{
|
f
,
h
|
h
[
f
.
status_id
]
=
true
}
end
def
reblogs_map
(
status_ids
,
account_id
)
select
(
'reblog_of_id'
).
where
(
reblog_of_id:
status_ids
).
where
(
account_id:
account_id
).
reorder
(
nil
).
map
{
|
s
|
[
s
.
reblog_of_id
,
true
]
}
.
to_h
select
(
'reblog_of_id'
).
where
(
reblog_of_id:
status_ids
).
where
(
account_id:
account_id
).
reorder
(
nil
).
each_with_object
({})
{
|
s
,
h
|
h
[
s
.
reblog_of_id
]
=
true
}
end
def
mutes_map
(
conversation_ids
,
account_id
)
ConversationMute
.
select
(
'conversation_id'
).
where
(
conversation_id:
conversation_ids
).
where
(
account_id:
account_id
).
map
{
|
m
|
[
m
.
conversation_id
,
true
]
}
.
to_h
ConversationMute
.
select
(
'conversation_id'
).
where
(
conversation_id:
conversation_ids
).
where
(
account_id:
account_id
).
each_with_object
({})
{
|
m
,
h
|
h
[
m
.
conversation_id
]
=
true
}
end
def
pins_map
(
status_ids
,
account_id
)
StatusPin
.
select
(
'status_id'
).
where
(
status_id:
status_ids
).
where
(
account_id:
account_id
).
map
{
|
p
|
[
p
.
status_id
,
true
]
}
.
to_h
StatusPin
.
select
(
'status_id'
).
where
(
status_id:
status_ids
).
where
(
account_id:
account_id
).
each_with_object
({})
{
|
p
,
h
|
h
[
p
.
status_id
]
=
true
}
end
def
reload_stale_associations!
(
cached_items
)
...
...
@@ -337,7 +337,7 @@ class Status < ApplicationRecord
return
if
account_ids
.
empty?
accounts
=
Account
.
where
(
id:
account_ids
).
map
{
|
a
|
[
a
.
id
,
a
]
}
.
to_h
accounts
=
Account
.
where
(
id:
account_ids
).
each_with_object
({})
{
|
a
,
h
|
h
[
a
.
id
]
=
a
}
cached_items
.
each
do
|
item
|
item
.
account
=
accounts
[
item
.
account_id
]
...
...
This diff is collapsed.
Click to expand it.
app/models/trending_tags.rb
+
1
-
1
View file @
6d4438a6
...
...
@@ -18,7 +18,7 @@ class TrendingTags
def
get
(
limit
)
key
=
"
#{
KEY
}
:
#{
Time
.
now
.
utc
.
beginning_of_day
.
to_i
}
"
tag_ids
=
redis
.
zrevrange
(
key
,
0
,
limit
-
1
).
map
(
&
:to_i
)
tags
=
Tag
.
where
(
id:
tag_ids
).
to_a
.
map
{
|
tag
|
[
tag
.
id
,
tag
]
}
.
to_h
tags
=
Tag
.
where
(
id:
tag_ids
).
to_a
.
each_with_object
({})
{
|
tag
,
h
|
h
[
tag
.
id
]
=
tag
}
tag_ids
.
map
{
|
tag_id
|
tags
[
tag_id
]
}.
compact
end
...
...
This diff is collapsed.
Click to expand it.
app/services/batched_remove_status_service.rb
+
3
-
3
View file @
6d4438a6
...
...
@@ -12,12 +12,12 @@ class BatchedRemoveStatusService < BaseService
def
call
(
statuses
)
statuses
=
Status
.
where
(
id:
statuses
.
map
(
&
:id
)).
includes
(
:account
,
:stream_entry
).
flat_map
{
|
status
|
[
status
]
+
status
.
reblogs
.
includes
(
:account
,
:stream_entry
).
to_a
}
@mentions
=
statuses
.
map
{
|
s
|
[
s
.
id
,
s
.
active_mentions
.
includes
(
:account
).
to_a
]
}
.
to_h
@tags
=
statuses
.
map
{
|
s
|
[
s
.
id
,
s
.
tags
.
pluck
(
:name
)
]
}
.
to_h
@mentions
=
statuses
.
each_with_object
({})
{
|
s
,
h
|
h
[
s
.
id
]
=
s
.
active_mentions
.
includes
(
:account
).
to_a
}
@tags
=
statuses
.
each_with_object
({})
{
|
s
,
h
|
h
[
s
.
id
]
=
s
.
tags
.
pluck
(
:name
)
}
@stream_entry_batches
=
[]
@salmon_batches
=
[]
@json_payloads
=
statuses
.
map
{
|
s
|
[
s
.
id
,
Oj
.
dump
(
event: :delete
,
payload:
s
.
id
.
to_s
)
]
}
.
to_h
@json_payloads
=
statuses
.
each_with_object
({})
{
|
s
,
h
|
h
[
s
.
id
]
=
Oj
.
dump
(
event: :delete
,
payload:
s
.
id
.
to_s
)
}
@activity_xml
=
{}
# Ensure that rendered XML reflects destroyed state
...
...
This diff is collapsed.
Click to expand it.
spec/models/notification_spec.rb
+
1
-
1
View file @
6d4438a6
...
...
@@ -101,7 +101,7 @@ RSpec.describe Notification, type: :model do
before
do
allow
(
accounts_with_ids
).
to
receive
(
:[]
).
with
(
stale_account1
.
id
).
and_return
(
account1
)
allow
(
accounts_with_ids
).
to
receive
(
:[]
).
with
(
stale_account2
.
id
).
and_return
(
account2
)
allow
(
Account
).
to
receive_message_chain
(
:where
,
:
map
,
:to_h
).
and_return
(
accounts_with_ids
)
allow
(
Account
).
to
receive_message_chain
(
:where
,
:
each_with_object
).
and_return
(
accounts_with_ids
)
end
let
(
:cached_items
)
do
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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