Performance.
This commit is contained in:
		
							parent
							
								
									a5aac9a337
								
							
						
					
					
						commit
						e06776d81d
					
				| @ -183,7 +183,7 @@ class Application(BaseApplication): | ||||
|         self.router.add_view("/settings/repositories/index.html", RepositoriesIndexView) | ||||
|         self.router.add_view("/settings/repositories/create.html", RepositoriesCreateView) | ||||
|         self.router.add_view("/settings/repositories/repository/{name}/update.html", RepositoriesUpdateView) | ||||
|         self.router.add_view("/settings/repositories/respository/{name}/delete.html", RepositoriesDeleteView) | ||||
|         self.router.add_view("/settings/repositories/repository/{name}/delete.html", RepositoriesDeleteView) | ||||
|         self.webdav = WebdavApplication(self) | ||||
|         self.git = GitApplication(self) | ||||
|         self.add_subapp("/webdav", self.webdav) | ||||
|  | ||||
| @ -1,9 +1,21 @@ | ||||
| from snek.system.service import BaseService | ||||
| import asyncio  | ||||
| import shutil | ||||
| 
 | ||||
| class RepositoryService(BaseService): | ||||
|     mapper_name = "repository" | ||||
| 
 | ||||
|     async def delete(self, user_uid, name): | ||||
|         loop = asyncio.get_event_loop() | ||||
|         repository_path = (await self.services.user.get_repository_path(user_uid)).joinpath(name) | ||||
|         try: | ||||
|             await loop.run_in_executor(None, shutil.rmtree, repository_path) | ||||
|         except Exception as ex: | ||||
|             print(ex) | ||||
| 
 | ||||
|         await super().delete(user_uid=user_uid, name=name) | ||||
| 
 | ||||
| 
 | ||||
|     async def exists(self, user_uid, name, **kwargs): | ||||
|         kwargs["user_uid"] = user_uid | ||||
|         kwargs["name"] = name | ||||
| @ -14,6 +26,9 @@ class RepositoryService(BaseService): | ||||
|         if not repository_path.exists(): | ||||
|             repository_path.mkdir(parents=True) | ||||
|         repository_path = repository_path.joinpath(name) | ||||
|         repository_path = str(repository_path) | ||||
|         if not repository_path.endswith(".git"): | ||||
|             repository_path += ".git" | ||||
|         command = ['git', 'init', '--bare', repository_path] | ||||
|         process = await asyncio.subprocess.create_subprocess_exec( | ||||
|             *command, | ||||
|  | ||||
| @ -64,7 +64,7 @@ class BaseMapper: | ||||
|         for record in self.db.query(sql, *args): | ||||
|             yield dict(record) | ||||
| 
 | ||||
|     async def delete(self, kwargs=None) -> int: | ||||
|     async def delete(self, **kwargs) -> int: | ||||
|         if not kwargs or not isinstance(kwargs, dict): | ||||
|             raise Exception("Can't execute delete with no filter.") | ||||
|         return self.table.delete(**kwargs) | ||||
|  | ||||
| @ -1,20 +1,10 @@ | ||||
| <!DOCTYPE html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
|   <meta charset="UTF-8"> | ||||
|   <title>Delete Repository</title> | ||||
| {% extends 'settings/index.html' %} | ||||
| 
 | ||||
| {% block header_text %}<h1><i class="fa-solid fa-trash-can"></i> Delete Repository</h1>{% endblock %} | ||||
| 
 | ||||
| {% block main %} | ||||
|   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css"> | ||||
|   <style> | ||||
|     body { font-family: sans-serif; margin: 2rem; } | ||||
|     .container { max-width: 400px; margin: 0 auto; } | ||||
|     .confirm-box { | ||||
|       background: #ffe5e8; | ||||
|       border: 1.5px solid #dc3545; | ||||
|       padding: 2rem; | ||||
|       border-radius: 10px; | ||||
|       text-align: center; | ||||
|       margin-top: 2rem; | ||||
|     } | ||||
|     .repo-name { | ||||
|       font-weight: bold; | ||||
|       font-size: 1.2rem; | ||||
| @ -22,9 +12,9 @@ | ||||
|       color: #dc3545; | ||||
|     } | ||||
|     .actions { | ||||
|       display: flex; gap: 1rem; justify-content: center; margin-top: 1.5rem; | ||||
|       display: flex; gap: 1rem; justify-content: left; margin-top: 1.5rem; | ||||
|     } | ||||
|     button, a { | ||||
|     button { | ||||
|       background: #dc3545; color: #fff; | ||||
|       border: none; border-radius: 5px; padding: 0.6rem 1.2rem; | ||||
|       font-size: 1rem; cursor: pointer; | ||||
| @ -39,25 +29,15 @@ | ||||
|       .confirm-box { padding: 1rem; } | ||||
|     } | ||||
|   </style> | ||||
| </head> | ||||
| <body> | ||||
|   <div class="container"> | ||||
|     <h1><i class="fa-solid fa-trash-can"></i> Delete Repository</h1> | ||||
|     <div class="confirm-box"> | ||||
|       <div> | ||||
|         <i class="fa-solid fa-triangle-exclamation" style="font-size:2rem; color:#dc3545;"></i> | ||||
|       </div> | ||||
|       <p>Are you sure you want to <strong>delete</strong> the following repository?</p> | ||||
|       <div class="repo-name"><i class="fa-solid fa-book"></i> my-first-repo</div> | ||||
|       <form action="/repositories/delete" method="post" style="margin-top:1.5rem;"> | ||||
|         <input type="hidden" name="id" value="1"> | ||||
|       <div class="repo-name"><i class="fa-solid fa-book"></i> {{ repository.name }}</div> | ||||
|       <form method="post" style="margin-top:1.5rem;"> | ||||
|         <input type="hidden" name="name" value="{{ repository.name }}"> | ||||
|         <div class="actions"> | ||||
|           <button type="submit"><i class="fa-solid fa-trash"></i> Yes, delete</button> | ||||
|           <a href="repositories.html" class="cancel"><i class="fa-solid fa-ban"></i> Cancel</a> | ||||
|           <button type="button" onclick="history.back()" class="cancel"><i class="fa-solid fa-arrow-left"></i> Cancel</button> | ||||
|         </div> | ||||
|       </form> | ||||
|     </div> | ||||
|   </div> | ||||
| </body> | ||||
| </html> | ||||
| 
 | ||||
| {% endblock %} | ||||
|  | ||||
| @ -92,7 +92,7 @@ | ||||
|           <a class="button edit" href="/settings/repositories/repository/{{ repo.name }}/update.html"> | ||||
|             <i class="fa-solid fa-pen"></i> Edit | ||||
|           </a> | ||||
|           <a class="button delete" href="/settings/repositories/{{ repo.name }}/delete.html"> | ||||
|           <a class="button delete" href="/settings/repositories/repository/{{ repo.name }}/delete.html"> | ||||
|             <i class="fa-solid fa-trash"></i> Delete | ||||
|           </a> | ||||
|         </div> | ||||
|  | ||||
| @ -62,7 +62,23 @@ class RepositoriesDeleteView(BaseFormView): | ||||
| 
 | ||||
|     async def get(self): | ||||
|              | ||||
|         return await self.render_template("settings/repositories/delete.html") | ||||
| 
 | ||||
|         repository = await self.services.repository.get( | ||||
|             user_uid=self.session.get("uid"), name=self.request.match_info["name"] | ||||
|         ) | ||||
|         if not repository: | ||||
|             return web.HTTPNotFound() | ||||
| 
 | ||||
|         return await self.render_template("settings/repositories/delete.html", {"repository": repository.record}) | ||||
| 
 | ||||
|     async def post(self): | ||||
|         user_uid = self.session.get("uid") | ||||
|         name = self.request.match_info["name"] | ||||
|         repository = await self.services.repository.get( | ||||
|                 user_uid=user_uid, name=name | ||||
|         ) | ||||
|         if not repository: | ||||
|             return web.HTTPNotFound() | ||||
|         await self.services.repository.delete(user_uid=user_uid, name=name) | ||||
|         return web.HTTPFound("/settings/repositories/index.html") | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user