Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance #84

Merged
merged 5 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/base_chats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class BaseChatsController < ApplicationController
# GET /chats or /chats.json
def index
@chats = if params[:all].present?
Chat.includes(:assistant, :user).page(params[:page])
Chat.includes(:assistant, :user).order(created_at: :desc).page(params[:page])
else
Chat.includes(:assistant, :user).where(user_id: current_user.id).page(params[:page])
Chat.includes(:assistant, :user).where(user_id: current_user.id).order(created_at: :desc).page(params[:page])
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/base_documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BaseDocumentsController < ApplicationController

# GET /documents or /documents.json
def index
@documents = Document.all
@documents = Document.includes(:library, :user)

@documents = if params[:sort] == 'questions'
@documents.order(questions_count: :desc)
Expand Down
1 change: 0 additions & 1 deletion app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
import "controllers"
import "channels"
2 changes: 1 addition & 1 deletion app/javascript/channels/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Import all the channels to be used by Action Cable
import "channels/messages_channel"
// import "channels/messages_channel"
36 changes: 17 additions & 19 deletions app/views/chats/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,25 @@
<% end %>
</div>
<div id="chats" class="min-w-full mt-5 space-y-4">
<% @chats.order(created_at: :desc).each do |chat| %>
<% @chats.order(created_at: :desc).each do |chat| %>
<% cache(chat) do %> <!-- Cache each chat entry -->
<%= link_to chat_path(chat), class: "block bg-white rounded-lg shadow-lg p-4 hover:bg-gray-100" do %>
<div class="flex justify-between items-center">
<div class="w-5/6">
<div class="flex items-center text-stone-600 mb-1">
<!-- Icon here -->
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 mr-1">
<path stroke-linecap="round" stroke-linejoin="round" d="M9.813 15.904 9 18.75l-.813-2.846a4.5 4.5 0 0 0-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 0 0 3.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 0 0 3.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 0 0-3.09 3.09ZM18.259 8.715 18 9.75l-.259-1.035a3.375 3.375 0 0 0-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 0 0 2.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 0 0 2.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 0 0-2.456 2.456ZM16.894 20.567 16.5 21.75l-.394-1.183a2.25 2.25 0 0 0-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 0 0 1.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 0 0 1.423 1.423l1.183.394-1.183.394a2.25 2.25 0 0 0-1.423 1.423Z" />
</svg>
<h2 class="font-bold text-xl "><%= chat.assistant.name %></h2>
</div>
<p class="text-gray-700 font-mono"><%= truncate(chat.first_message, length: 100) %></p>
</div>
<div class="text-gray-500 text-sm">
<%= chat.created_at.strftime("%B %d, %Y %I:%M %p") %>
<p class="text-gray-400 text-xs">By: <%= chat.user.email %></p>
<% @chats.each do |chat| %>
<% cache(chat) do %> <!-- Cache each chat entry -->
<%= link_to chat_path(chat), class: "block bg-white rounded-lg shadow-lg p-4 hover:bg-gray-100" do %>
<div class="flex justify-between items-center">
<div class="w-5/6">
<div class="flex items-center text-stone-600 mb-1">
<!-- Icon here -->
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 mr-1">
<path stroke-linecap="round" stroke-linejoin="round" d="M9.813 15.904 9 18.75l-.813-2.846a4.5 4.5 0 0 0-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 0 0 3.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 0 0 3.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 0 0-3.09 3.09ZM18.259 8.715 18 9.75l-.259-1.035a3.375 3.375 0 0 0-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 0 0 2.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 0 0 2.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 0 0-2.456 2.456ZM16.894 20.567 16.5 21.75l-.394-1.183a2.25 2.25 0 0 0-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 0 0 1.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 0 0 1.423 1.423l1.183.394-1.183.394a2.25 2.25 0 0 0-1.423 1.423Z" />
</svg>
<h2 class="font-bold text-xl "><%= chat.assistant.name %></h2>
</div>
<p class="text-gray-700 font-mono"><%= truncate(chat.first_message, length: 100) %></p>
</div>
<div class="text-gray-500 text-sm">
<%= chat.created_at.strftime("%B %d, %Y %I:%M %p") %>
<p class="text-gray-400 text-xs">By: <%= chat.user.email %></p>
</div>
<% end %>
</div>
<% end %>
<% end %>
<% end %>
Expand Down