Commit 0a31efb5 authored by Adam Niedzielski's avatar Adam Niedzielski

Remove query parameters from notes polling endpoint to make caching easier

parent 57c068e1
...@@ -198,7 +198,7 @@ require('./task_list'); ...@@ -198,7 +198,7 @@ require('./task_list');
this.refreshing = true; this.refreshing = true;
return $.ajax({ return $.ajax({
url: this.notes_url, url: this.notes_url,
data: "last_fetched_at=" + this.last_fetched_at, headers: { "X-Last-Fetched-At": this.last_fetched_at },
dataType: "json", dataType: "json",
success: (function(_this) { success: (function(_this) {
return function(data) { return function(data) {
......
...@@ -211,6 +211,11 @@ class Projects::NotesController < Projects::ApplicationController ...@@ -211,6 +211,11 @@ class Projects::NotesController < Projects::ApplicationController
end end
def find_current_user_notes def find_current_user_notes
@notes = NotesFinder.new(project, current_user, params).execute.inc_author @notes = NotesFinder.new(project, current_user, params.merge(last_fetched_at: last_fetched_at))
.execute.inc_author
end
def last_fetched_at
request.headers['X-Last-Fetched-At']
end end
end end
...@@ -23,4 +23,4 @@ ...@@ -23,4 +23,4 @@
to post a comment to post a comment
:javascript :javascript
var notes = new Notes("#{namespace_project_notes_path(namespace_id: @project.namespace, project_id: @project, target_id: @noteable.id, target_type: @noteable.class.name.underscore)}", #{@notes.map(&:id).to_json}, #{Time.now.to_i}, "#{diff_view}") var notes = new Notes("#{namespace_project_noteable_notes_path(namespace_id: @project.namespace, project_id: @project, target_id: @noteable.id, target_type: @noteable.class.name.underscore)}", #{@notes.map(&:id).to_json}, #{Time.now.to_i}, "#{diff_view}")
...@@ -265,7 +265,7 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -265,7 +265,7 @@ constraints(ProjectUrlConstrainer.new) do
resources :group_links, only: [:index, :create, :update, :destroy], constraints: { id: /\d+/ } resources :group_links, only: [:index, :create, :update, :destroy], constraints: { id: /\d+/ }
resources :notes, only: [:index, :create, :destroy, :update], concerns: :awardable, constraints: { id: /\d+/ } do resources :notes, only: [:create, :destroy, :update], concerns: :awardable, constraints: { id: /\d+/ } do
member do member do
delete :delete_attachment delete :delete_attachment
post :resolve post :resolve
...@@ -273,6 +273,8 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -273,6 +273,8 @@ constraints(ProjectUrlConstrainer.new) do
end end
end end
get 'noteable/:target_type/:target_id/notes' => 'notes#index', as: 'noteable_notes'
resources :boards, only: [:index, :show] do resources :boards, only: [:index, :show] do
scope module: :boards do scope module: :boards do
resources :issues, only: [:index, :update] resources :issues, only: [:index, :update]
......
...@@ -200,4 +200,31 @@ describe Projects::NotesController do ...@@ -200,4 +200,31 @@ describe Projects::NotesController do
end end
end end
end end
describe 'GET index' do
let(:last_fetched_at) { '1487756246' }
let(:request_params) do
{
namespace_id: project.namespace,
project_id: project,
target_type: 'issue',
target_id: issue.id
}
end
before do
sign_in(user)
project.team << [user, :developer]
end
it 'passes last_fetched_at from headers to NotesFinder' do
request.headers['X-Last-Fetched-At'] = last_fetched_at
expect(NotesFinder).to receive(:new)
.with(anything, anything, hash_including(last_fetched_at: last_fetched_at))
.and_call_original
get :index, request_params
end
end
end end
...@@ -431,12 +431,22 @@ describe 'project routing' do ...@@ -431,12 +431,22 @@ describe 'project routing' do
end end
end end
# project_notes GET /:project_id/notes(.:format) notes#index # project_noteable_notes GET /:project_id/noteable/:target_type/:target_id/notes notes#index
# POST /:project_id/notes(.:format) notes#create # POST /:project_id/notes(.:format) notes#create
# project_note DELETE /:project_id/notes/:id(.:format) notes#destroy # project_note DELETE /:project_id/notes/:id(.:format) notes#destroy
describe Projects::NotesController, 'routing' do describe Projects::NotesController, 'routing' do
it 'to #index' do
expect(get('/gitlab/gitlabhq/noteable/issue/1/notes')).to route_to(
'projects/notes#index',
namespace_id: 'gitlab',
project_id: 'gitlabhq',
target_type: 'issue',
target_id: '1'
)
end
it_behaves_like 'RESTful project resources' do it_behaves_like 'RESTful project resources' do
let(:actions) { [:index, :create, :destroy] } let(:actions) { [:create, :destroy] }
let(:controller) { 'notes' } let(:controller) { 'notes' }
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment