Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
diaspora
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Milan
diaspora
Commits
d69953b0
Commit
d69953b0
authored
13 years ago
by
Dennis Collinson
Browse files
Options
Downloads
Patches
Plain Diff
enter the idea of the evilquery
parent
939383ef
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/diaspora/user/querying.rb
+64
-20
64 additions, 20 deletions
lib/diaspora/user/querying.rb
with
64 additions
and
20 deletions
lib/diaspora/user/querying.rb
+
64
−
20
View file @
d69953b0
...
...
@@ -5,14 +5,65 @@
require
File
.
join
(
Rails
.
root
,
'lib'
,
'diaspora'
,
'redis_cache'
)
module
Diaspora
module
EvilQuery
def
self
.
prep_opts
(
klass
,
opts
)
defaults
=
{
:order
=>
'created_at DESC'
,
:limit
=>
15
,
:hidden
=>
false
}
defaults
[
:type
]
=
Stream
::
Base
::
TYPES_OF_POST_IN_STREAM
if
klass
==
Post
opts
=
defaults
.
merge
(
opts
)
opts
[
:order_field
]
=
opts
[
:order
].
split
.
first
.
to_sym
opts
[
:order_with_table
]
=
klass
.
table_name
+
'.'
+
opts
[
:order
]
opts
[
:max_time
]
=
Time
.
at
(
opts
[
:max_time
])
if
opts
[
:max_time
].
is_a?
(
Integer
)
opts
[
:max_time
]
||=
Time
.
now
+
1
opts
end
class
Base
def
initialize
(
user
,
klass
)
@user
=
user
@class
=
klass
end
end
class
VisibleShareableById
<
Base
def
initialize
(
user
,
klass
,
key
,
id
,
conditions
=
{})
super
(
user
,
klass
)
@key
=
key
@id
=
id
@conditions
=
conditions
end
def
post!
#is this optimal order, also, queries don't get executed until first
user_is_contact
.
first
||
user_is_author
.
first
||
public_post
.
first
end
def
user_is_contact
@class
.
where
(
@key
=>
@id
).
joins
(
:contacts
).
where
(
:contacts
=>
{
:user_id
=>
@user
.
id
}).
where
(
@conditions
).
select
(
@class
.
table_name
+
".*"
)
end
def
user_is_author
@class
.
where
(
@key
=>
@id
,
:author_id
=>
@user
.
person
.
id
).
where
(
@conditions
)
end
def
public_post
@class
.
where
(
@key
=>
@id
,
:public
=>
true
).
where
(
@conditions
)
end
end
end
module
UserModules
module
Querying
def
find_visible_shareable_by_id
(
klass
,
id
,
opts
=
{}
)
key
=
opts
.
delete
(
:key
)
||
:id
post
=
klass
.
where
(
key
=>
id
).
joins
(
:contacts
).
where
(
:contacts
=>
{
:user_id
=>
self
.
id
}).
where
(
opts
).
select
(
klass
.
table_name
+
".*"
).
first
post
||=
klass
.
where
(
key
=>
id
,
:author_id
=>
self
.
person
.
id
).
where
(
opts
).
first
post
||=
klass
.
where
(
key
=>
id
,
:public
=>
true
).
where
(
opts
).
first
key
=
(
opts
.
delete
(
:key
)
||
:id
)
EvilQuery
::
VisibleShareableById
.
new
(
self
,
klass
,
key
,
id
,
opts
).
post!
end
def
visible_shareables
(
klass
,
opts
=
{})
...
...
@@ -72,8 +123,14 @@ module Diaspora
end
def
construct_shareable_from_others_query
(
opts
)
conditions
=
{
:pending
=>
false
,
:share_visibilities
=>
{
:hidden
=>
opts
[
:hidden
]},
:contacts
=>
{
:user_id
=>
self
.
id
,
:receiving
=>
true
}
}
conditions
=
{
:pending
=>
false
,
:share_visibilities
=>
{
:hidden
=>
opts
[
:hidden
]},
:contacts
=>
{
:user_id
=>
self
.
id
,
:receiving
=>
true
}
}
conditions
[
:type
]
=
opts
[
:type
]
if
opts
.
has_key?
(
:type
)
query
=
opts
[
:klass
].
joins
(
:contacts
).
where
(
conditions
)
if
opts
[
:by_members_of
]
...
...
@@ -194,20 +251,7 @@ module Diaspora
# @return [Hash]
def
prep_opts
(
klass
,
opts
)
defaults
=
{
:order
=>
'created_at DESC'
,
:limit
=>
15
,
:hidden
=>
false
}
defaults
[
:type
]
=
Stream
::
Base
::
TYPES_OF_POST_IN_STREAM
if
klass
==
Post
opts
=
defaults
.
merge
(
opts
)
opts
[
:order_field
]
=
opts
[
:order
].
split
.
first
.
to_sym
opts
[
:order_with_table
]
=
klass
.
table_name
+
'.'
+
opts
[
:order
]
opts
[
:max_time
]
=
Time
.
at
(
opts
[
:max_time
])
if
opts
[
:max_time
].
is_a?
(
Integer
)
opts
[
:max_time
]
||=
Time
.
now
+
1
opts
EvilQuery
.
prep_opts
(
klass
,
opts
)
end
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment